aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs82
1 files changed, 62 insertions, 20 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index 9febd90..15747c9 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -602,13 +602,13 @@ public sealed class BSShapeCollection : IDisposable
602 if (newMeshKey == prim.PhysShape.shapeKey && prim.PhysShape.type == BSPhysicsShapeType.SHAPE_MESH) 602 if (newMeshKey == prim.PhysShape.shapeKey && prim.PhysShape.type == BSPhysicsShapeType.SHAPE_MESH)
603 return false; 603 return false;
604 604
605 if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToMesh,create,oldKey={1},newKey={2}", 605 if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToMesh,create,oldKey={1},newKey={2},size={3},lod={4}",
606 prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newMeshKey.ToString("X")); 606 prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newMeshKey.ToString("X"), prim.Size, lod);
607 607
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,10 +619,9 @@ 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 IMesh meshData = null;
626 625
627 MeshDesc meshDesc; 626 MeshDesc meshDesc;
628 if (Meshes.TryGetValue(newMeshKey, out meshDesc)) 627 if (Meshes.TryGetValue(newMeshKey, out meshDesc))
@@ -632,27 +631,63 @@ public sealed class BSShapeCollection : IDisposable
632 } 631 }
633 else 632 else
634 { 633 {
635 meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false); 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
636 false // do not cache the mesh and do not use previously built versions
637 );
636 638
637 if (meshData != null) 639 if (meshData != null)
638 { 640 {
641
639 int[] indices = meshData.getIndexListAsInt(); 642 int[] indices = meshData.getIndexListAsInt();
640 List<OMV.Vector3> vertices = meshData.getVertexList(); 643 int realIndicesIndex = indices.Length;
644 float[] verticesAsFloats = meshData.getVertexListAsFloat();
641 645
642 float[] verticesAsFloats = new float[vertices.Count * 3]; 646 if (BSParam.ShouldRemoveZeroWidthTriangles)
643 int vi = 0;
644 foreach (OMV.Vector3 vv in vertices)
645 { 647 {
646 verticesAsFloats[vi++] = vv.X; 648 // Remove degenerate triangles. These are triangles with two of the vertices
647 verticesAsFloats[vi++] = vv.Y; 649 // are the same. This is complicated by the problem that vertices are not
648 verticesAsFloats[vi++] = vv.Z; 650 // made unique in sculpties so we have to compare the values in the vertex.
651 realIndicesIndex = 0;
652 for (int tri = 0; tri < indices.Length; tri += 3)
653 {
654 // Compute displacements into vertex array for each vertex of the triangle
655 int v1 = indices[tri + 0] * 3;
656 int v2 = indices[tri + 1] * 3;
657 int v3 = indices[tri + 2] * 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 }
676 }
649 } 677 }
678 DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}",
679 BSScene.DetailLogZero, indices.Length / 3, realIndicesIndex / 3, verticesAsFloats.Length / 3);
650 680
651 // m_log.DebugFormat("{0}: BSShapeCollection.CreatePhysicalMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", 681 if (realIndicesIndex != 0)
652 // LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count); 682 {
653 683 newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World,
654 newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, 684 realIndicesIndex, indices, verticesAsFloats.Length / 3, verticesAsFloats);
655 indices.GetLength(0), indices, vertices.Count, 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 }
656 } 691 }
657 } 692 }
658 newShape.shapeKey = newMeshKey; 693 newShape.shapeKey = newMeshKey;
@@ -831,6 +866,11 @@ public sealed class BSShapeCollection : IDisposable
831 { 866 {
832 // level of detail based on size and type of the object 867 // level of detail based on size and type of the object
833 float lod = BSParam.MeshLOD; 868 float lod = BSParam.MeshLOD;
869
870 // prims with curvy internal cuts need higher lod
871 if (pbs.HollowShape == HollowShape.Circle)
872 lod = BSParam.MeshCircularLOD;
873
834 if (pbs.SculptEntry) 874 if (pbs.SculptEntry)
835 lod = BSParam.SculptLOD; 875 lod = BSParam.SculptLOD;
836 876
@@ -865,9 +905,11 @@ public sealed class BSShapeCollection : IDisposable
865 // 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
866 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)
867 { 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
868 prim.LastAssetBuildFailed = true; 910 prim.LastAssetBuildFailed = true;
911
869 BSPhysObject xprim = prim; 912 BSPhysObject xprim = prim;
870 DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset,lastFailed={1}", prim.LocalID, prim.LastAssetBuildFailed);
871 Util.FireAndForget(delegate 913 Util.FireAndForget(delegate
872 { 914 {
873 RequestAssetDelegate assetProvider = PhysicsScene.RequestAssetMethod; 915 RequestAssetDelegate assetProvider = PhysicsScene.RequestAssetMethod;
@@ -878,7 +920,7 @@ public sealed class BSShapeCollection : IDisposable
878 { 920 {
879 bool assetFound = false; // DEBUG DEBUG 921 bool assetFound = false; // DEBUG DEBUG
880 string mismatchIDs = String.Empty; // DEBUG DEBUG 922 string mismatchIDs = String.Empty; // DEBUG DEBUG
881 if (yprim.BaseShape.SculptEntry) 923 if (asset != null && yprim.BaseShape.SculptEntry)
882 { 924 {
883 if (yprim.BaseShape.SculptTexture.ToString() == asset.ID) 925 if (yprim.BaseShape.SculptTexture.ToString() == asset.ID)
884 { 926 {