aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
diff options
context:
space:
mode:
authorRobert Adams2013-02-05 17:19:55 -0800
committerRobert Adams2013-02-05 17:19:55 -0800
commit36463612794f95776e8ddea14333827cbce35eff (patch)
treef90d645c0543cc473a6468bc5811ae1d3ae21a47 /OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
parentBulletSim: remove degenerate triangles from meshes. This fixes the (diff)
downloadopensim-SC_OLD-36463612794f95776e8ddea14333827cbce35eff.zip
opensim-SC_OLD-36463612794f95776e8ddea14333827cbce35eff.tar.gz
opensim-SC_OLD-36463612794f95776e8ddea14333827cbce35eff.tar.bz2
opensim-SC_OLD-36463612794f95776e8ddea14333827cbce35eff.tar.xz
BulletSim: make removing zero width triangles from meshes optional
and, for the moment, default to 'off'.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs51
1 files changed, 27 insertions, 24 deletions
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}",