BulletSim: make removing zero width triangles from meshes optional

and, for the moment, default to 'off'.
user_profiles
Robert Adams 2013-02-05 17:19:55 -08:00
parent dce9e323f4
commit 3646361279
4 changed files with 33 additions and 24 deletions

View File

@ -62,6 +62,7 @@ public static class BSParam
public static bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed public static bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed
public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes
public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects
public static bool ShouldRemoveZeroWidthTriangles { get; private set; }
public static float TerrainImplementation { get; private set; } public static float TerrainImplementation { get; private set; }
public static float TerrainFriction { get; private set; } public static float TerrainFriction { get; private set; }
@ -218,6 +219,11 @@ public static class BSParam
(s,cf,p,v) => { ShouldUseHullsForPhysicalObjects = cf.GetBoolean(p, BSParam.BoolNumeric(v)); }, (s,cf,p,v) => { ShouldUseHullsForPhysicalObjects = cf.GetBoolean(p, BSParam.BoolNumeric(v)); },
(s) => { return BSParam.NumericBool(ShouldUseHullsForPhysicalObjects); }, (s) => { return BSParam.NumericBool(ShouldUseHullsForPhysicalObjects); },
(s,p,l,v) => { ShouldUseHullsForPhysicalObjects = BSParam.BoolNumeric(v); } ), (s,p,l,v) => { ShouldUseHullsForPhysicalObjects = BSParam.BoolNumeric(v); } ),
new ParameterDefn("ShouldRemoveZeroWidthTriangles", "If true, remove degenerate triangles from meshes",
ConfigurationParameters.numericFalse,
(s,cf,p,v) => { ShouldRemoveZeroWidthTriangles = cf.GetBoolean(p, BSParam.BoolNumeric(v)); },
(s) => { return BSParam.NumericBool(ShouldRemoveZeroWidthTriangles); },
(s,p,l,v) => { ShouldRemoveZeroWidthTriangles = BSParam.BoolNumeric(v); } ),
new ParameterDefn("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)", new ParameterDefn("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)",
32f, 32f,

View File

@ -640,34 +640,37 @@ public sealed class BSShapeCollection : IDisposable
{ {
int[] indices = meshData.getIndexListAsInt(); int[] indices = meshData.getIndexListAsInt();
// int realIndicesIndex = indices.Length; int realIndicesIndex = indices.Length;
float[] verticesAsFloats = meshData.getVertexListAsFloat(); float[] verticesAsFloats = meshData.getVertexListAsFloat();
// Remove degenerate triangles. These are triangles with two of the vertices if (BSParam.ShouldRemoveZeroWidthTriangles)
// are the same. This is complicated by the problem that vertices are not
// made unique in sculpties so we have to compare the values in the vertex.
int realIndicesIndex = 0;
for (int tri = 0; tri < indices.Length; tri += 3)
{ {
int v1 = indices[tri + 0] * 3; // Remove degenerate triangles. These are triangles with two of the vertices
int v2 = indices[tri + 1] * 3; // are the same. This is complicated by the problem that vertices are not
int v3 = indices[tri + 2] * 3; // made unique in sculpties so we have to compare the values in the vertex.
if (!( ( verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] realIndicesIndex = 0;
&& verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1] for (int tri = 0; tri < indices.Length; tri += 3)
&& verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2] )
|| ( verticesAsFloats[v2 + 0] == verticesAsFloats[v3 + 0]
&& verticesAsFloats[v2 + 1] == verticesAsFloats[v3 + 1]
&& verticesAsFloats[v2 + 2] == verticesAsFloats[v3 + 2] )
|| ( verticesAsFloats[v1 + 0] == verticesAsFloats[v3 + 0]
&& verticesAsFloats[v1 + 1] == verticesAsFloats[v3 + 1]
&& verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2] ) )
)
{ {
// None of the vertices of the triangles are the same. This is a good triangle; int v1 = indices[tri + 0] * 3;
indices[realIndicesIndex + 0] = indices[tri + 0]; int v2 = indices[tri + 1] * 3;
indices[realIndicesIndex + 1] = indices[tri + 1]; int v3 = indices[tri + 2] * 3;
indices[realIndicesIndex + 2] = indices[tri + 2]; if (!((verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0]
realIndicesIndex += 3; && verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1]
&& verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2])
|| (verticesAsFloats[v2 + 0] == verticesAsFloats[v3 + 0]
&& verticesAsFloats[v2 + 1] == verticesAsFloats[v3 + 1]
&& verticesAsFloats[v2 + 2] == verticesAsFloats[v3 + 2])
|| (verticesAsFloats[v1 + 0] == verticesAsFloats[v3 + 0]
&& verticesAsFloats[v1 + 1] == verticesAsFloats[v3 + 1]
&& verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2]))
)
{
// None of the vertices of the triangles are the same. This is a good triangle;
indices[realIndicesIndex + 0] = indices[tri + 0];
indices[realIndicesIndex + 1] = indices[tri + 1];
indices[realIndicesIndex + 2] = indices[tri + 2];
realIndicesIndex += 3;
}
} }
} }
DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}", DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}",

Binary file not shown.

Binary file not shown.