From e07e31af1c8e0c56e5c2e7b91f1f707cc57180f3 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Fri, 16 Dec 2022 18:49:26 +0200
Subject: SL-18854 Prevent texture drop onto faces that have pbr

---
 indra/newview/lltooldraganddrop.cpp | 54 +++++++++++++++++++++++++++++++++----
 1 file changed, 49 insertions(+), 5 deletions(-)

diff --git a/indra/newview/lltooldraganddrop.cpp b/indra/newview/lltooldraganddrop.cpp
index 3f45d4f0da..5c4f7f75bf 100644
--- a/indra/newview/lltooldraganddrop.cpp
+++ b/indra/newview/lltooldraganddrop.cpp
@@ -1047,6 +1047,20 @@ void LLToolDragAndDrop::dropTextureAllFaces(LLViewerObject* hit_obj,
 		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)
+    {
+        return;
+    }
 	LLUUID asset_id = item->getAssetUUID();
 	BOOL success = handleDropMaterialProtections(hit_obj, item, source, src_id);
 	if (!success)
@@ -1055,13 +1069,14 @@ void LLToolDragAndDrop::dropTextureAllFaces(LLViewerObject* hit_obj,
 	}
 	LLViewerTexture* image = LLViewerTextureManager::getFetchedTexture(asset_id);
 	add(LLStatViewer::EDIT_TEXTURE, 1);
-	S32 num_faces = hit_obj->getNumTEs();
 	for( S32 face = 0; face < num_faces; face++ )
 	{
-
-		// update viewer side image in anticipation of update from simulator
-		hit_obj->setTEImage(face, image);
-		dialog_refresh_all();
+        if (hit_obj->getRenderMaterialID(face).isNull())
+        {
+            // update viewer side image in anticipation of update from simulator
+            hit_obj->setTEImage(face, image);
+            dialog_refresh_all();
+        }
 	}
 	// send the update to the simulator
 	hit_obj->sendTEUpdate();
@@ -1167,6 +1182,10 @@ void LLToolDragAndDrop::dropTextureOneFace(LLViewerObject* hit_obj,
 		LL_WARNS() << "LLToolDragAndDrop::dropTextureOneFace no texture item." << LL_ENDL;
 		return;
 	}
+    if (hit_obj->getRenderMaterialID(hit_face).notNull())
+    {
+        return;
+    }
 	LLUUID asset_id = item->getAssetUUID();
 	BOOL success = handleDropMaterialProtections(hit_obj, item, source, src_id);
 	if (!success)
@@ -2032,6 +2051,31 @@ EAcceptance LLToolDragAndDrop::dad3dApplyToObject(
 		return ACCEPT_NO;
 	}
 
+    if (cargo_type == DAD_TEXTURE)
+    {
+        if ((mask & MASK_SHIFT))
+        {
+            S32 num_faces = obj->getNumTEs();
+            bool has_non_pbr_faces = false;
+            for (S32 face = 0; face < num_faces; face++)
+            {
+                if (obj->getRenderMaterialID(face).isNull())
+                {
+                    has_non_pbr_faces = true;
+                    break;
+                }
+            }
+            if (!has_non_pbr_faces)
+            {
+                return ACCEPT_NO;
+            }
+        }
+        else if (obj->getRenderMaterialID(face).notNull())
+        {
+            return ACCEPT_NO;
+        }
+    }
+
 	if(drop && (ACCEPT_YES_SINGLE <= rv))
 	{
 		if (cargo_type == DAD_TEXTURE)
-- 
cgit v1.2.3