diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 37bccbc..07e34ab 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,55 @@ public sealed class BSShapeCollection : IDisposable | |||
632 | } | 631 | } |
633 | else | 632 | else |
634 | { | 633 | { |
635 | meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false, false, false); | 634 | IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, |
635 | true, | ||
636 | false, // say it is not physical so a bounding box is not built | ||
637 | false, // do not cache the mesh and do not use previously built versions | ||
638 | false // It's NOT for ODE | ||
639 | ); | ||
636 | 640 | ||
637 | if (meshData != null) | 641 | if (meshData != null) |
638 | { | 642 | { |
643 | |||
639 | int[] indices = meshData.getIndexListAsInt(); | 644 | int[] indices = meshData.getIndexListAsInt(); |
640 | List<OMV.Vector3> vertices = meshData.getVertexList(); | 645 | int realIndicesIndex = indices.Length; |
646 | float[] verticesAsFloats = meshData.getVertexListAsFloat(); | ||
641 | 647 | ||
642 | float[] verticesAsFloats = new float[vertices.Count * 3]; | 648 | if (BSParam.ShouldRemoveZeroWidthTriangles) |
643 | int vi = 0; | ||
644 | foreach (OMV.Vector3 vv in vertices) | ||
645 | { | 649 | { |
646 | verticesAsFloats[vi++] = vv.X; | 650 | // Remove degenerate triangles. These are triangles with two of the vertices |
647 | verticesAsFloats[vi++] = vv.Y; | 651 | // are the same. This is complicated by the problem that vertices are not |
648 | verticesAsFloats[vi++] = vv.Z; | 652 | // made unique in sculpties so we have to compare the values in the vertex. |
653 | realIndicesIndex = 0; | ||
654 | for (int tri = 0; tri < indices.Length; tri += 3) | ||
655 | { | ||
656 | int v1 = indices[tri + 0] * 3; | ||
657 | int v2 = indices[tri + 1] * 3; | ||
658 | int v3 = indices[tri + 2] * 3; | ||
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 | } |
650 | 678 | 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}", | 679 | BSScene.DetailLogZero, indices.Length / 3, realIndicesIndex / 3, verticesAsFloats.Length / 3); |
652 | // LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count); | ||
653 | 680 | ||
654 | newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, | 681 | newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, |
655 | indices.GetLength(0), indices, vertices.Count, verticesAsFloats); | 682 | realIndicesIndex, indices, verticesAsFloats.Length/3, verticesAsFloats); |
656 | } | 683 | } |
657 | } | 684 | } |
658 | newShape.shapeKey = newMeshKey; | 685 | newShape.shapeKey = newMeshKey; |
@@ -831,6 +858,11 @@ public sealed class BSShapeCollection : IDisposable | |||
831 | { | 858 | { |
832 | // level of detail based on size and type of the object | 859 | // level of detail based on size and type of the object |
833 | float lod = BSParam.MeshLOD; | 860 | float lod = BSParam.MeshLOD; |
861 | |||
862 | // prims with curvy internal cuts need higher lod | ||
863 | if (pbs.HollowShape == HollowShape.Circle) | ||
864 | lod = BSParam.MeshCircularLOD; | ||
865 | |||
834 | if (pbs.SculptEntry) | 866 | if (pbs.SculptEntry) |
835 | lod = BSParam.SculptLOD; | 867 | lod = BSParam.SculptLOD; |
836 | 868 | ||