diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 77 |
1 files changed, 46 insertions, 31 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index f17e513..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 | ); |
@@ -640,41 +640,54 @@ 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 | // Compute displacements into vertex array for each vertex of the triangle |
667 | indices[realIndicesIndex + 0] = indices[tri + 0]; | 655 | int v1 = indices[tri + 0] * 3; |
668 | indices[realIndicesIndex + 1] = indices[tri + 1]; | 656 | int v2 = indices[tri + 1] * 3; |
669 | indices[realIndicesIndex + 2] = indices[tri + 2]; | 657 | int v3 = indices[tri + 2] * 3; |
670 | realIndicesIndex += 3; | 658 | // Check to see if any two of the vertices are the same |
659 | if (!( ( verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] | ||
660 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1] | ||
661 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2]) | ||
662 | || ( verticesAsFloats[v2 + 0] == verticesAsFloats[v3 + 0] | ||
663 | && verticesAsFloats[v2 + 1] == verticesAsFloats[v3 + 1] | ||
664 | && verticesAsFloats[v2 + 2] == verticesAsFloats[v3 + 2]) | ||
665 | || ( verticesAsFloats[v1 + 0] == verticesAsFloats[v3 + 0] | ||
666 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v3 + 1] | ||
667 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2]) ) | ||
668 | ) | ||
669 | { | ||
670 | // None of the vertices of the triangles are the same. This is a good triangle; | ||
671 | indices[realIndicesIndex + 0] = indices[tri + 0]; | ||
672 | indices[realIndicesIndex + 1] = indices[tri + 1]; | ||
673 | indices[realIndicesIndex + 2] = indices[tri + 2]; | ||
674 | realIndicesIndex += 3; | ||
675 | } | ||
671 | } | 676 | } |
672 | } | 677 | } |
673 | DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}", | 678 | DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}", |
674 | BSScene.DetailLogZero, indices.Length / 3, realIndicesIndex / 3, verticesAsFloats.Length / 3); | 679 | BSScene.DetailLogZero, indices.Length / 3, realIndicesIndex / 3, verticesAsFloats.Length / 3); |
675 | 680 | ||
676 | newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, | 681 | if (realIndicesIndex != 0) |
677 | 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 | } | ||
678 | } | 691 | } |
679 | } | 692 | } |
680 | newShape.shapeKey = newMeshKey; | 693 | newShape.shapeKey = newMeshKey; |
@@ -892,9 +905,11 @@ public sealed class BSShapeCollection : IDisposable | |||
892 | // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset | 905 | // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset |
893 | if (prim.BaseShape.SculptEntry && !prim.LastAssetBuildFailed && prim.BaseShape.SculptTexture != OMV.UUID.Zero) | 906 | if (prim.BaseShape.SculptEntry && !prim.LastAssetBuildFailed && prim.BaseShape.SculptTexture != OMV.UUID.Zero) |
894 | { | 907 | { |
908 | DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset,lastFailed={1}", prim.LocalID, prim.LastAssetBuildFailed); | ||
909 | // This will prevent looping through this code as we keep trying to get the failed shape | ||
895 | prim.LastAssetBuildFailed = true; | 910 | prim.LastAssetBuildFailed = true; |
911 | |||
896 | BSPhysObject xprim = prim; | 912 | BSPhysObject xprim = prim; |
897 | DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset,lastFailed={1}", prim.LocalID, prim.LastAssetBuildFailed); | ||
898 | Util.FireAndForget(delegate | 913 | Util.FireAndForget(delegate |
899 | { | 914 | { |
900 | RequestAssetDelegate assetProvider = PhysicsScene.RequestAssetMethod; | 915 | RequestAssetDelegate assetProvider = PhysicsScene.RequestAssetMethod; |
@@ -905,7 +920,7 @@ public sealed class BSShapeCollection : IDisposable | |||
905 | { | 920 | { |
906 | bool assetFound = false; // DEBUG DEBUG | 921 | bool assetFound = false; // DEBUG DEBUG |
907 | string mismatchIDs = String.Empty; // DEBUG DEBUG | 922 | string mismatchIDs = String.Empty; // DEBUG DEBUG |
908 | if (yprim.BaseShape.SculptEntry) | 923 | if (asset != null && yprim.BaseShape.SculptEntry) |
909 | { | 924 | { |
910 | if (yprim.BaseShape.SculptTexture.ToString() == asset.ID) | 925 | if (yprim.BaseShape.SculptTexture.ToString() == asset.ID) |
911 | { | 926 | { |