diff options
author | Robert Adams | 2013-02-06 15:52:28 -0800 |
---|---|---|
committer | Robert Adams | 2013-02-06 15:52:28 -0800 |
commit | 0baa2590bef8ad4e0a78a7c88d55acd0848e0068 (patch) | |
tree | 31bdc677dae7acac5313355a55ecf0dce88272ba /OpenSim/Region/Physics/BulletSPlugin | |
parent | BulletSim: remove an exception which occurs if a physics mesh (diff) | |
download | opensim-SC_OLD-0baa2590bef8ad4e0a78a7c88d55acd0848e0068.zip opensim-SC_OLD-0baa2590bef8ad4e0a78a7c88d55acd0848e0068.tar.gz opensim-SC_OLD-0baa2590bef8ad4e0a78a7c88d55acd0848e0068.tar.bz2 opensim-SC_OLD-0baa2590bef8ad4e0a78a7c88d55acd0848e0068.tar.xz |
BulletSim: check for completely degenerate meshes (ones with all
triangles having zero width) and output an error rather than
throwing and exception.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index fe0f984..15747c9 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -608,7 +608,7 @@ public sealed class BSShapeCollection : IDisposable | |||
608 | // Since we're recreating new, get rid of the reference to the previous shape | 608 | // Since we're recreating new, get rid of the reference to the previous shape |
609 | DereferenceShape(prim.PhysShape, shapeCallback); | 609 | DereferenceShape(prim.PhysShape, shapeCallback); |
610 | 610 | ||
611 | newShape = CreatePhysicalMesh(prim.PhysObjectName, newMeshKey, prim.BaseShape, prim.Size, lod); | 611 | newShape = CreatePhysicalMesh(prim, newMeshKey, prim.BaseShape, prim.Size, lod); |
612 | // Take evasive action if the mesh was not constructed. | 612 | // Take evasive action if the mesh was not constructed. |
613 | newShape = VerifyMeshCreated(newShape, prim); | 613 | newShape = VerifyMeshCreated(newShape, prim); |
614 | 614 | ||
@@ -619,7 +619,7 @@ public sealed class BSShapeCollection : IDisposable | |||
619 | return true; // 'true' means a new shape has been added to this prim | 619 | return true; // 'true' means a new shape has been added to this prim |
620 | } | 620 | } |
621 | 621 | ||
622 | private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | 622 | private BulletShape CreatePhysicalMesh(BSPhysObject prim, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) |
623 | { | 623 | { |
624 | BulletShape newShape = new BulletShape(); | 624 | BulletShape newShape = new BulletShape(); |
625 | 625 | ||
@@ -631,7 +631,7 @@ public sealed class BSShapeCollection : IDisposable | |||
631 | } | 631 | } |
632 | else | 632 | else |
633 | { | 633 | { |
634 | IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, | 634 | IMesh meshData = PhysicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, |
635 | false, // say it is not physical so a bounding box is not built | 635 | false, // say it is not physical so a bounding box is not built |
636 | false // do not cache the mesh and do not use previously built versions | 636 | false // do not cache the mesh and do not use previously built versions |
637 | ); | 637 | ); |
@@ -651,18 +651,20 @@ public sealed class BSShapeCollection : IDisposable | |||
651 | realIndicesIndex = 0; | 651 | realIndicesIndex = 0; |
652 | for (int tri = 0; tri < indices.Length; tri += 3) | 652 | for (int tri = 0; tri < indices.Length; tri += 3) |
653 | { | 653 | { |
654 | // Compute displacements into vertex array for each vertex of the triangle | ||
654 | int v1 = indices[tri + 0] * 3; | 655 | int v1 = indices[tri + 0] * 3; |
655 | int v2 = indices[tri + 1] * 3; | 656 | int v2 = indices[tri + 1] * 3; |
656 | int v3 = indices[tri + 2] * 3; | 657 | int v3 = indices[tri + 2] * 3; |
657 | if (!((verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] | 658 | // Check to see if any two of the vertices are the same |
659 | if (!( ( verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] | ||
658 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1] | 660 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1] |
659 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2]) | 661 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2]) |
660 | || (verticesAsFloats[v2 + 0] == verticesAsFloats[v3 + 0] | 662 | || ( verticesAsFloats[v2 + 0] == verticesAsFloats[v3 + 0] |
661 | && verticesAsFloats[v2 + 1] == verticesAsFloats[v3 + 1] | 663 | && verticesAsFloats[v2 + 1] == verticesAsFloats[v3 + 1] |
662 | && verticesAsFloats[v2 + 2] == verticesAsFloats[v3 + 2]) | 664 | && verticesAsFloats[v2 + 2] == verticesAsFloats[v3 + 2]) |
663 | || (verticesAsFloats[v1 + 0] == verticesAsFloats[v3 + 0] | 665 | || ( verticesAsFloats[v1 + 0] == verticesAsFloats[v3 + 0] |
664 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v3 + 1] | 666 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v3 + 1] |
665 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2])) | 667 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2]) ) |
666 | ) | 668 | ) |
667 | { | 669 | { |
668 | // None of the vertices of the triangles are the same. This is a good triangle; | 670 | // None of the vertices of the triangles are the same. This is a good triangle; |
@@ -676,8 +678,16 @@ public sealed class BSShapeCollection : IDisposable | |||
676 | DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}", | 678 | DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}", |
677 | BSScene.DetailLogZero, indices.Length / 3, realIndicesIndex / 3, verticesAsFloats.Length / 3); | 679 | BSScene.DetailLogZero, indices.Length / 3, realIndicesIndex / 3, verticesAsFloats.Length / 3); |
678 | 680 | ||
679 | newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, | 681 | if (realIndicesIndex != 0) |
680 | realIndicesIndex, indices, verticesAsFloats.Length/3, verticesAsFloats); | 682 | { |
683 | newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, | ||
684 | realIndicesIndex, indices, verticesAsFloats.Length / 3, verticesAsFloats); | ||
685 | } | ||
686 | else | ||
687 | { | ||
688 | PhysicsScene.Logger.ErrorFormat("{0} All mesh triangles degenerate. Prim {1} at {2} in {3}", | ||
689 | LogHeader, prim.PhysObjectName, prim.RawPosition, PhysicsScene.Name); | ||
690 | } | ||
681 | } | 691 | } |
682 | } | 692 | } |
683 | newShape.shapeKey = newMeshKey; | 693 | newShape.shapeKey = newMeshKey; |