diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 9febd90..f59b9d9 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -602,8 +602,8 @@ 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); |
@@ -622,7 +622,6 @@ public sealed class BSShapeCollection : IDisposable | |||
622 | private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | 622 | private BulletShape CreatePhysicalMesh(string objName, 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,53 @@ 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(objName, 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 | int v1 = indices[tri + 0] * 3; | ||
655 | int v2 = indices[tri + 1] * 3; | ||
656 | int v3 = indices[tri + 2] * 3; | ||
657 | if (!((verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] | ||
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 | } | ||
674 | } | ||
649 | } | 675 | } |
650 | 676 | DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}", | |
651 | // m_log.DebugFormat("{0}: BSShapeCollection.CreatePhysicalMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", | 677 | BSScene.DetailLogZero, indices.Length / 3, realIndicesIndex / 3, verticesAsFloats.Length / 3); |
652 | // LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count); | ||
653 | 678 | ||
654 | newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, | 679 | newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, |
655 | indices.GetLength(0), indices, vertices.Count, verticesAsFloats); | 680 | realIndicesIndex, indices, verticesAsFloats.Length/3, verticesAsFloats); |
656 | } | 681 | } |
657 | } | 682 | } |
658 | newShape.shapeKey = newMeshKey; | 683 | newShape.shapeKey = newMeshKey; |
@@ -831,6 +856,11 @@ public sealed class BSShapeCollection : IDisposable | |||
831 | { | 856 | { |
832 | // level of detail based on size and type of the object | 857 | // level of detail based on size and type of the object |
833 | float lod = BSParam.MeshLOD; | 858 | float lod = BSParam.MeshLOD; |
859 | |||
860 | // prims with curvy internal cuts need higher lod | ||
861 | if (pbs.HollowShape == HollowShape.Circle) | ||
862 | lod = BSParam.MeshCircularLOD; | ||
863 | |||
834 | if (pbs.SculptEntry) | 864 | if (pbs.SculptEntry) |
835 | lod = BSParam.SculptLOD; | 865 | lod = BSParam.SculptLOD; |
836 | 866 | ||