diff options
author | Robert Adams | 2013-02-05 17:19:55 -0800 |
---|---|---|
committer | Robert Adams | 2013-02-05 17:19:55 -0800 |
commit | 36463612794f95776e8ddea14333827cbce35eff (patch) | |
tree | f90d645c0543cc473a6468bc5811ae1d3ae21a47 /OpenSim/Region | |
parent | BulletSim: remove degenerate triangles from meshes. This fixes the (diff) | |
download | opensim-SC-36463612794f95776e8ddea14333827cbce35eff.zip opensim-SC-36463612794f95776e8ddea14333827cbce35eff.tar.gz opensim-SC-36463612794f95776e8ddea14333827cbce35eff.tar.bz2 opensim-SC-36463612794f95776e8ddea14333827cbce35eff.tar.xz |
BulletSim: make removing zero width triangles from meshes optional
and, for the moment, default to 'off'.
Diffstat (limited to 'OpenSim/Region')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 6 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 51 |
2 files changed, 33 insertions, 24 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index bdd9ce4..306928a 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | |||
@@ -62,6 +62,7 @@ public static class BSParam | |||
62 | public static bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed | 62 | public static bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed |
63 | public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes | 63 | public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes |
64 | public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects | 64 | public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects |
65 | public static bool ShouldRemoveZeroWidthTriangles { get; private set; } | ||
65 | 66 | ||
66 | public static float TerrainImplementation { get; private set; } | 67 | public static float TerrainImplementation { get; private set; } |
67 | public static float TerrainFriction { get; private set; } | 68 | public static float TerrainFriction { get; private set; } |
@@ -218,6 +219,11 @@ public static class BSParam | |||
218 | (s,cf,p,v) => { ShouldUseHullsForPhysicalObjects = cf.GetBoolean(p, BSParam.BoolNumeric(v)); }, | 219 | (s,cf,p,v) => { ShouldUseHullsForPhysicalObjects = cf.GetBoolean(p, BSParam.BoolNumeric(v)); }, |
219 | (s) => { return BSParam.NumericBool(ShouldUseHullsForPhysicalObjects); }, | 220 | (s) => { return BSParam.NumericBool(ShouldUseHullsForPhysicalObjects); }, |
220 | (s,p,l,v) => { ShouldUseHullsForPhysicalObjects = BSParam.BoolNumeric(v); } ), | 221 | (s,p,l,v) => { ShouldUseHullsForPhysicalObjects = BSParam.BoolNumeric(v); } ), |
222 | new ParameterDefn("ShouldRemoveZeroWidthTriangles", "If true, remove degenerate triangles from meshes", | ||
223 | ConfigurationParameters.numericFalse, | ||
224 | (s,cf,p,v) => { ShouldRemoveZeroWidthTriangles = cf.GetBoolean(p, BSParam.BoolNumeric(v)); }, | ||
225 | (s) => { return BSParam.NumericBool(ShouldRemoveZeroWidthTriangles); }, | ||
226 | (s,p,l,v) => { ShouldRemoveZeroWidthTriangles = BSParam.BoolNumeric(v); } ), | ||
221 | 227 | ||
222 | new ParameterDefn("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)", | 228 | new ParameterDefn("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)", |
223 | 32f, | 229 | 32f, |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index f17e513..f59b9d9 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -640,34 +640,37 @@ public sealed class BSShapeCollection : IDisposable | |||
640 | { | 640 | { |
641 | 641 | ||
642 | int[] indices = meshData.getIndexListAsInt(); | 642 | int[] indices = meshData.getIndexListAsInt(); |
643 | // int realIndicesIndex = indices.Length; | 643 | int realIndicesIndex = indices.Length; |
644 | float[] verticesAsFloats = meshData.getVertexListAsFloat(); | 644 | float[] verticesAsFloats = meshData.getVertexListAsFloat(); |
645 | 645 | ||
646 | // Remove degenerate triangles. These are triangles with two of the vertices | 646 | if (BSParam.ShouldRemoveZeroWidthTriangles) |
647 | // are the same. This is complicated by the problem that vertices are not | ||
648 | // made unique in sculpties so we have to compare the values in the vertex. | ||
649 | int realIndicesIndex = 0; | ||
650 | for (int tri = 0; tri < indices.Length; tri += 3) | ||
651 | { | 647 | { |
652 | int v1 = indices[tri + 0] * 3; | 648 | // Remove degenerate triangles. These are triangles with two of the vertices |
653 | int v2 = indices[tri + 1] * 3; | 649 | // are the same. This is complicated by the problem that vertices are not |
654 | int v3 = indices[tri + 2] * 3; | 650 | // made unique in sculpties so we have to compare the values in the vertex. |
655 | if (!( ( verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] | 651 | realIndicesIndex = 0; |
656 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1] | 652 | for (int tri = 0; tri < indices.Length; tri += 3) |
657 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2] ) | ||
658 | || ( verticesAsFloats[v2 + 0] == verticesAsFloats[v3 + 0] | ||
659 | && verticesAsFloats[v2 + 1] == verticesAsFloats[v3 + 1] | ||
660 | && verticesAsFloats[v2 + 2] == verticesAsFloats[v3 + 2] ) | ||
661 | || ( verticesAsFloats[v1 + 0] == verticesAsFloats[v3 + 0] | ||
662 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v3 + 1] | ||
663 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2] ) ) | ||
664 | ) | ||
665 | { | 653 | { |
666 | // None of the vertices of the triangles are the same. This is a good triangle; | 654 | int v1 = indices[tri + 0] * 3; |
667 | indices[realIndicesIndex + 0] = indices[tri + 0]; | 655 | int v2 = indices[tri + 1] * 3; |
668 | indices[realIndicesIndex + 1] = indices[tri + 1]; | 656 | int v3 = indices[tri + 2] * 3; |
669 | indices[realIndicesIndex + 2] = indices[tri + 2]; | 657 | if (!((verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] |
670 | realIndicesIndex += 3; | 658 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1] |
659 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2]) | ||
660 | || (verticesAsFloats[v2 + 0] == verticesAsFloats[v3 + 0] | ||
661 | && verticesAsFloats[v2 + 1] == verticesAsFloats[v3 + 1] | ||
662 | && verticesAsFloats[v2 + 2] == verticesAsFloats[v3 + 2]) | ||
663 | || (verticesAsFloats[v1 + 0] == verticesAsFloats[v3 + 0] | ||
664 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v3 + 1] | ||
665 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2])) | ||
666 | ) | ||
667 | { | ||
668 | // None of the vertices of the triangles are the same. This is a good triangle; | ||
669 | indices[realIndicesIndex + 0] = indices[tri + 0]; | ||
670 | indices[realIndicesIndex + 1] = indices[tri + 1]; | ||
671 | indices[realIndicesIndex + 2] = indices[tri + 2]; | ||
672 | realIndicesIndex += 3; | ||
673 | } | ||
671 | } | 674 | } |
672 | } | 675 | } |
673 | DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}", | 676 | DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}", |