From 481d7156d16adc59da0ab82f0ae5d7b3c584e104 Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Sun, 24 Mar 2019 01:51:29 +0000
Subject: mantis 8505 ( and not 8506 by mistake on previus commit) remove the
 meshes numbre of sides warning. build prims with the number of sides of the
 high LOD submesh

---
 .../Linden/Caps/BunchOfCaps/BunchOfCaps.cs         | 33 +++++++++++++---------
 .../Linden/Caps/BunchOfCaps/MeshCost.cs            | 13 +++------
 2 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
index 16178e6..deeacf5 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
@@ -61,7 +61,7 @@ namespace OpenSim.Region.ClientStack.Linden
         string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder,
         byte[] data, string inventoryType, string assetType,
         int cost, UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances,
-        bool IsAtestUpload, ref string error, ref int nextOwnerMask, ref int groupMask, ref int everyoneMask);
+        bool IsAtestUpload, ref string error, ref int nextOwnerMask, ref int groupMask, ref int everyoneMask, int[] meshesSides);
 
     public delegate UUID UpdateItem(UUID itemID, byte[] data);
 
@@ -529,6 +529,7 @@ namespace OpenSim.Region.ClientStack.Linden
             int nreqmeshs= 0;
             int nreqinstances = 0;
             bool IsAtestUpload = false;
+            int[] meshesSides = null;
 
             string assetName = llsdRequest.name;
 
@@ -578,9 +579,8 @@ namespace OpenSim.Region.ClientStack.Linden
                         string error;
                         int modelcost;
 
-
                         if (!m_ModelCost.MeshModelCost(llsdRequest.asset_resources, baseCost, out modelcost,
-                            meshcostdata, out error, ref warning))
+                            meshcostdata, out error, ref warning, out meshesSides))
                         {
                             LLSDAssetUploadError resperror = new LLSDAssetUploadError();
                             resperror.message = error;
@@ -668,7 +668,7 @@ namespace OpenSim.Region.ClientStack.Linden
                 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type,
                         llsdRequest.asset_type, uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile, cost,
                         texturesFolder, nreqtextures, nreqmeshs, nreqinstances, IsAtestUpload,
-                        llsdRequest.next_owner_mask, llsdRequest.group_mask, llsdRequest.everyone_mask);
+                        llsdRequest.next_owner_mask, llsdRequest.group_mask, llsdRequest.everyone_mask, meshesSides);
 
             m_HostCapsObj.HttpListener.AddStreamHandler(
                 new BinaryStreamHandler(
@@ -713,7 +713,7 @@ namespace OpenSim.Region.ClientStack.Linden
                                           string assetType, int cost,
                                           UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances,
                                           bool IsAtestUpload, ref string error,
-                                          ref int nextOwnerMask, ref int groupMask, ref int everyoneMask)
+                                          ref int nextOwnerMask, ref int groupMask, ref int everyoneMask, int[] meshesSides)
         {
             lock (m_ModelCost)
                 m_FileAgentInventoryState = FileAgentInventoryState.processUpload;
@@ -967,7 +967,12 @@ namespace OpenSim.Region.ClientStack.Linden
                         {
                             int meshindx = inner_instance_list["mesh"].AsInteger();
                             if (meshAssets.Count > meshindx)
-                                pbs = PrimitiveBaseShape.CreateMesh(face_list.Count, meshAssets[meshindx]);
+                            {
+                                if(meshesSides != null && meshesSides.Length > meshindx)
+                                    pbs = PrimitiveBaseShape.CreateMesh(meshesSides[i], meshAssets[meshindx]);
+                                else
+                                    pbs = PrimitiveBaseShape.CreateMesh(face_list.Count, meshAssets[meshindx]);
+                            }
                         }
                         if(pbs == null) // fallback
                             pbs = PrimitiveBaseShape.CreateBox();
@@ -1025,12 +1030,12 @@ namespace OpenSim.Region.ClientStack.Linden
                         Vector3 position = inner_instance_list["position"].AsVector3();
                         Quaternion rotation = inner_instance_list["rotation"].AsQuaternion();
 
-                        // for now viwers do send fixed defaults
-                        // but this may change
-//                        int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger();
                         byte physicsShapeType = (byte)PhysShapeType.convex; // default is simple convex
-//                        int material = inner_instance_list["material"].AsInteger();
+                        if (inner_instance_list.ContainsKey("physics_shape_type"))
+                            physicsShapeType = (byte)inner_instance_list["physics_shape_type"].AsInteger();
                         byte material = (byte)Material.Wood;
+                        if (inner_instance_list.ContainsKey("material"))
+                            material = (byte)inner_instance_list["material"].AsInteger();
 
                         SceneObjectPart prim
                             = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity, Vector3.Zero);
@@ -2014,13 +2019,13 @@ namespace OpenSim.Region.ClientStack.Linden
         private int m_nextOwnerMask;
         private int m_groupMask;
         private int m_everyoneMask;
-
+        private int[] m_meshesSides;
 
         public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem,
                                 UUID parentFolderID, string invType, string assetType, string path,
                                 IHttpServer httpServer, bool dumpAssetsToFile,
                                 int totalCost, UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances,
-                                bool IsAtestUpload, int nextOwnerMask, int groupMask, int everyoneMask)
+                                bool IsAtestUpload, int nextOwnerMask, int groupMask, int everyoneMask, int[] meshesSides)
         {
             m_assetName = assetName;
             m_assetDes = description;
@@ -2048,6 +2053,8 @@ namespace OpenSim.Region.ClientStack.Linden
             m_nextOwnerMask = nextOwnerMask;
             m_groupMask = groupMask;
             m_everyoneMask = everyoneMask;
+
+            m_meshesSides = meshesSides;
         }
 
         /// <summary>
@@ -2088,7 +2095,7 @@ namespace OpenSim.Region.ClientStack.Linden
             {
                 handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType,
                     m_cost, m_texturesFolder, m_nreqtextures, m_nreqmeshs, m_nreqinstances, m_IsAtestUpload,
-                    ref m_error, ref m_nextOwnerMask, ref m_groupMask, ref m_everyoneMask);
+                    ref m_error, ref m_nextOwnerMask, ref m_groupMask, ref m_everyoneMask, m_meshesSides);
             }
 
             uploadComplete.new_next_owner_mask = m_nextOwnerMask;
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs
index e293463..8844a0f 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs
@@ -145,11 +145,11 @@ namespace OpenSim.Region.ClientStack.Linden
         // avatarSkeleton if mesh includes a avatar skeleton
         // useAvatarCollider if we should use physics mesh for avatar
         public bool MeshModelCost(LLSDAssetResource resources, int basicCost, out int totalcost,
-            LLSDAssetUploadResponseData meshcostdata, out string error, ref string warning)
+            LLSDAssetUploadResponseData meshcostdata, out string error, ref string warning, out int[] meshesSides)
         {
             totalcost = 0;
             error = string.Empty;
-
+            meshesSides = null;
             bool avatarSkeleton = false;
 
             if (resources == null ||
@@ -204,6 +204,7 @@ namespace OpenSim.Region.ClientStack.Linden
             if (resources.mesh_list != null && resources.mesh_list.Array.Count > 0)
             {
                 numberMeshs = resources.mesh_list.Array.Count;
+                meshesSides = new int[numberMeshs];
 
                 for (int i = 0; i < numberMeshs; i++)
                 {
@@ -226,6 +227,7 @@ namespace OpenSim.Region.ClientStack.Linden
                     }
                     meshsCosts.Add(curCost);
                     meshsfee += curCost.costFee;
+                    meshesSides[i] = curCost.highLODsides;
                 }
                 haveMeshs = true;
             }
@@ -260,11 +262,6 @@ namespace OpenSim.Region.ClientStack.Linden
                     error = "Model contains parts with sides larger than " + NonPhysicalPrimScaleMax.ToString() + "m. Please ajust scale";
                     return false;
                 }
-                int nfaces = 0;
-                if(inst.Contains("face_list"))
-                {
-                     nfaces = ((ArrayList)inst["face_list"]).Count;
-                }
 
                 if (haveMeshs && inst.ContainsKey("mesh"))
                 {
@@ -281,8 +278,6 @@ namespace OpenSim.Region.ClientStack.Linden
                     float sqdiam = scale.LengthSquared();
 
                     ameshCostParam curCost = meshsCosts[mesh];
-                    if(nfaces != curCost.highLODsides)
-                        warning +="Warning: Uploaded number of faces ( "+ nfaces.ToString() +" ) does not match highlod number of faces ( "+ curCost.highLODsides.ToString() +" )\n";
 
                     float mesh_streaming = streamingCost(curCost, sqdiam);
 
-- 
cgit v1.1