ConvexDecomposition remove a copy of vertices not needed for ubOde

LSLKeyTest
UbitUmarov 2016-09-02 11:55:59 +01:00
parent ea686058c9
commit d9572bdf4e
2 changed files with 92 additions and 6 deletions

View File

@ -1094,7 +1094,7 @@ namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet
return m; return m;
} }
for (int i = m; i < count; i++) for (int i = m + 1; i < count; i++)
{ {
if (allow[i] != 0) if (allow[i] != 0)
{ {
@ -1540,6 +1540,19 @@ namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet
} }
} }
public static bool ComputeHull(List<float3> vertices, out List<int> indices)
{
List<HullTriangle> tris = new List<HullTriangle>();
bool ret = calchull(vertices, out indices, 0, tris);
if (ret == false)
{
indices = new List<int>();
return false;
}
return true;
}
private static bool CleanupVertices(List<float3> svertices, out List<float3> vertices, float normalepsilon, out float3 scale) private static bool CleanupVertices(List<float3> svertices, out List<float3> vertices, float normalepsilon, out float3 scale)
{ {
const float EPSILON = 0.000001f; const float EPSILON = 0.000001f;

View File

@ -619,7 +619,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
vs.Clear(); vs.Clear();
continue; continue;
} }
/*
if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f)) if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f))
{ {
vs.Clear(); vs.Clear();
@ -657,6 +657,45 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3); f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3);
faces.Add(f); faces.Add(f);
} }
*/
List<int> 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; vertsoffset += nverts;
vs.Clear(); vs.Clear();
} }
@ -686,13 +725,15 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
vs.Add(f3); vs.Add(f3);
} }
if (vs.Count < 3) nverts = vs.Count;
if (nverts < 3)
{ {
vs.Clear(); vs.Clear();
return false; return false;
} }
if (vs.Count < 5) if (nverts < 5)
{ {
foreach (float3 point in vs) foreach (float3 point in vs)
{ {
@ -701,10 +742,11 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
c.Z = point.z; c.Z = point.z;
coords.Add(c); coords.Add(c);
} }
f = new Face(0, 1, 2); f = new Face(0, 1, 2);
faces.Add(f); faces.Add(f);
if (vs.Count == 4) if (nverts == 4)
{ {
f = new Face(0, 2, 3); f = new Face(0, 2, 3);
faces.Add(f); faces.Add(f);
@ -716,7 +758,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
vs.Clear(); vs.Clear();
return true; return true;
} }
/*
if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f)) if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f))
return false; return false;
@ -747,7 +789,38 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
f = new Face(t1, t2, t3); f = new Face(t1, t2, t3);
faces.Add(f); faces.Add(f);
} }
*/
List<int> 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) if (coords.Count > 0 && faces.Count > 0)
return true; return true;
} }