From d9572bdf4e97a82ef570b1153e422b66ea5085f7 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 2 Sep 2016 11:55:59 +0100 Subject: [PATCH] ConvexDecomposition remove a copy of vertices not needed for ubOde --- .../ConvexDecompositionDotNet/HullUtils.cs | 15 +++- .../ubOdeMeshing/Meshmerizer.cs | 83 +++++++++++++++++-- 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs b/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs index 22691e69f8..72f2d6d525 100644 --- a/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs +++ b/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs @@ -1094,7 +1094,7 @@ namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet return m; } - for (int i = m; i < count; i++) + for (int i = m + 1; i < count; i++) { if (allow[i] != 0) { @@ -1540,6 +1540,19 @@ namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet } } + public static bool ComputeHull(List vertices, out List indices) + { + List tris = new List(); + + bool ret = calchull(vertices, out indices, 0, tris); + if (ret == false) + { + indices = new List(); + return false; + } + return true; + } + private static bool CleanupVertices(List svertices, out List vertices, float normalepsilon, out float3 scale) { const float EPSILON = 0.000001f; diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs index 89baf94dfa..d9544dbd9b 100644 --- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs +++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs @@ -619,7 +619,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing vs.Clear(); continue; } - +/* if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f)) { vs.Clear(); @@ -657,6 +657,45 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3); faces.Add(f); } +*/ + List indices; + if (!HullUtils.ComputeHull(vs, out indices)) + { + vs.Clear(); + continue; + } + + nverts = vs.Count; + nindexs = indices.Count; + + if (nindexs % 3 != 0) + { + vs.Clear(); + continue; + } + + for (i = 0; i < nverts; i++) + { + c.X = vs[i].x; + c.Y = vs[i].y; + c.Z = vs[i].z; + coords.Add(c); + } + + for (i = 0; i < nindexs; i += 3) + { + t1 = indices[i]; + if (t1 > nverts) + break; + t2 = indices[i + 1]; + if (t2 > nverts) + break; + t3 = indices[i + 2]; + if (t3 > nverts) + break; + f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3); + faces.Add(f); + } vertsoffset += nverts; vs.Clear(); } @@ -686,13 +725,15 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing vs.Add(f3); } - if (vs.Count < 3) + nverts = vs.Count; + + if (nverts < 3) { vs.Clear(); return false; } - if (vs.Count < 5) + if (nverts < 5) { foreach (float3 point in vs) { @@ -701,10 +742,11 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing c.Z = point.z; coords.Add(c); } + f = new Face(0, 1, 2); faces.Add(f); - if (vs.Count == 4) + if (nverts == 4) { f = new Face(0, 2, 3); faces.Add(f); @@ -716,7 +758,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing vs.Clear(); return true; } - +/* if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f)) return false; @@ -747,7 +789,38 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing f = new Face(t1, t2, t3); faces.Add(f); } +*/ + List indices; + if (!HullUtils.ComputeHull(vs, out indices)) + return false; + nindexs = indices.Count; + + if (nindexs % 3 != 0) + return false; + + for (i = 0; i < nverts; i++) + { + c.X = vs[i].x; + c.Y = vs[i].y; + c.Z = vs[i].z; + coords.Add(c); + } + for (i = 0; i < nindexs; i += 3) + { + t1 = indices[i]; + if (t1 > nverts) + break; + t2 = indices[i + 1]; + if (t2 > nverts) + break; + t3 = indices[i + 2]; + if (t3 > nverts) + break; + f = new Face(t1, t2, t3); + faces.Add(f); + } + vs.Clear(); if (coords.Count > 0 && faces.Count > 0) return true; }