From 36463612794f95776e8ddea14333827cbce35eff Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 5 Feb 2013 17:19:55 -0800 Subject: [PATCH] BulletSim: make removing zero width triangles from meshes optional and, for the moment, default to 'off'. --- .../Region/Physics/BulletSPlugin/BSParam.cs | 6 +++ .../BulletSPlugin/BSShapeCollection.cs | 51 +++++++++--------- bin/lib32/BulletSim.dll | Bin 546304 -> 546304 bytes bin/lib64/BulletSim.dll | Bin 694272 -> 694272 bytes 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index bdd9ce44d8..306928ad33 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -62,6 +62,7 @@ public static class BSParam 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 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 TerrainFriction { get; private set; } @@ -218,6 +219,11 @@ public static class BSParam (s,cf,p,v) => { ShouldUseHullsForPhysicalObjects = cf.GetBoolean(p, BSParam.BoolNumeric(v)); }, (s) => { return BSParam.NumericBool(ShouldUseHullsForPhysicalObjects); }, (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)", 32f, diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index f17e51340c..f59b9d973b 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -640,34 +640,37 @@ public sealed class BSShapeCollection : IDisposable { int[] indices = meshData.getIndexListAsInt(); - // int realIndicesIndex = indices.Length; + int realIndicesIndex = indices.Length; float[] verticesAsFloats = meshData.getVertexListAsFloat(); - // Remove degenerate triangles. These are triangles with two of the vertices - // 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) + if (BSParam.ShouldRemoveZeroWidthTriangles) { - int v1 = indices[tri + 0] * 3; - int v2 = indices[tri + 1] * 3; - int v3 = indices[tri + 2] * 3; - if (!( ( verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] - && 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] ) ) - ) + // Remove degenerate triangles. These are triangles with two of the vertices + // 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. + realIndicesIndex = 0; + for (int tri = 0; tri < indices.Length; tri += 3) { - // 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; + int v1 = indices[tri + 0] * 3; + int v2 = indices[tri + 1] * 3; + int v3 = indices[tri + 2] * 3; + if (!((verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] + && 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}", diff --git a/bin/lib32/BulletSim.dll b/bin/lib32/BulletSim.dll index 0d24f121c095374b445098ad73884a0ffd76912c..de4f95ad08c7abbb05070781ff91ab75db689792 100755 GIT binary patch delta 1114 zcmZ8fT}YEr82&!@Z9CHiXE<|0qSj0o6YTtmm4uNOgJx*k#h^h-KQ5THQb|E*BO$tp zL4#wUunQ3{CKL=dXg7mFT^JZF5ZuKqA}5zyvS=W`HFZ(5r!brRv>K@E>l4R3P|`@}ahy3$hZ zMi{^OUm%N?#i#{c(EZ{W{MZcXC~7z_-doVyGao;fle44#;nh!~$5?kJf6+&~^3;0Ep$9)vpjR7uK7u!j}9td9bp z2ds!W8Bt{!c?FS;BauAtQaw_Hh`u5A5Nhr_R9prm4R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