diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | 111 |
1 files changed, 109 insertions, 2 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs index 09f5bc4..aa04726 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | |||
@@ -38,6 +38,76 @@ using OMV = OpenMetaverse; | |||
38 | 38 | ||
39 | namespace OpenSim.Region.Physics.BulletSPlugin | 39 | namespace OpenSim.Region.Physics.BulletSPlugin |
40 | { | 40 | { |
41 | // Information class that holds stats for the shape. Which values mean | ||
42 | // something depends on the type of shape. | ||
43 | // This information is used for debugging and stats and is not used | ||
44 | // for operational things. | ||
45 | public class ShapeInfoInfo | ||
46 | { | ||
47 | public int Vertices { get; set; } | ||
48 | private int m_hullCount; | ||
49 | private int[] m_verticesPerHull; | ||
50 | public ShapeInfoInfo() | ||
51 | { | ||
52 | Vertices = 0; | ||
53 | m_hullCount = 0; | ||
54 | m_verticesPerHull = null; | ||
55 | } | ||
56 | public int HullCount | ||
57 | { | ||
58 | set | ||
59 | { | ||
60 | m_hullCount = value; | ||
61 | m_verticesPerHull = new int[m_hullCount]; | ||
62 | Array.Clear(m_verticesPerHull, 0, m_hullCount); | ||
63 | } | ||
64 | get { return m_hullCount; } | ||
65 | } | ||
66 | public void SetVerticesPerHull(int hullNum, int vertices) | ||
67 | { | ||
68 | if (m_verticesPerHull != null && hullNum < m_verticesPerHull.Length) | ||
69 | { | ||
70 | m_verticesPerHull[hullNum] = vertices; | ||
71 | } | ||
72 | } | ||
73 | public int GetVerticesPerHull(int hullNum) | ||
74 | { | ||
75 | if (m_verticesPerHull != null && hullNum < m_verticesPerHull.Length) | ||
76 | { | ||
77 | return m_verticesPerHull[hullNum]; | ||
78 | } | ||
79 | return 0; | ||
80 | } | ||
81 | public override string ToString() | ||
82 | { | ||
83 | StringBuilder buff = new StringBuilder(); | ||
84 | // buff.Append("ShapeInfo=<"); | ||
85 | buff.Append("<"); | ||
86 | if (Vertices > 0) | ||
87 | { | ||
88 | buff.Append("verts="); | ||
89 | buff.Append(Vertices.ToString()); | ||
90 | } | ||
91 | |||
92 | if (Vertices > 0 && HullCount > 0) buff.Append(","); | ||
93 | |||
94 | if (HullCount > 0) | ||
95 | { | ||
96 | buff.Append("nHulls="); | ||
97 | buff.Append(HullCount.ToString()); | ||
98 | buff.Append(","); | ||
99 | buff.Append("hullVerts="); | ||
100 | for (int ii = 0; ii < HullCount; ii++) | ||
101 | { | ||
102 | if (ii != 0) buff.Append(","); | ||
103 | buff.Append(GetVerticesPerHull(ii).ToString()); | ||
104 | } | ||
105 | } | ||
106 | buff.Append(">"); | ||
107 | return buff.ToString(); | ||
108 | } | ||
109 | } | ||
110 | |||
41 | public abstract class BSShape | 111 | public abstract class BSShape |
42 | { | 112 | { |
43 | private static string LogHeader = "[BULLETSIM SHAPE]"; | 113 | private static string LogHeader = "[BULLETSIM SHAPE]"; |
@@ -45,18 +115,21 @@ public abstract class BSShape | |||
45 | public int referenceCount { get; set; } | 115 | public int referenceCount { get; set; } |
46 | public DateTime lastReferenced { get; set; } | 116 | public DateTime lastReferenced { get; set; } |
47 | public BulletShape physShapeInfo { get; set; } | 117 | public BulletShape physShapeInfo { get; set; } |
118 | public ShapeInfoInfo shapeInfo { get; private set; } | ||
48 | 119 | ||
49 | public BSShape() | 120 | public BSShape() |
50 | { | 121 | { |
51 | referenceCount = 1; | 122 | referenceCount = 1; |
52 | lastReferenced = DateTime.Now; | 123 | lastReferenced = DateTime.Now; |
53 | physShapeInfo = new BulletShape(); | 124 | physShapeInfo = new BulletShape(); |
125 | shapeInfo = new ShapeInfoInfo(); | ||
54 | } | 126 | } |
55 | public BSShape(BulletShape pShape) | 127 | public BSShape(BulletShape pShape) |
56 | { | 128 | { |
57 | referenceCount = 1; | 129 | referenceCount = 1; |
58 | lastReferenced = DateTime.Now; | 130 | lastReferenced = DateTime.Now; |
59 | physShapeInfo = pShape; | 131 | physShapeInfo = pShape; |
132 | shapeInfo = new ShapeInfoInfo(); | ||
60 | } | 133 | } |
61 | 134 | ||
62 | // Get another reference to this shape. | 135 | // Get another reference to this shape. |
@@ -283,6 +356,9 @@ public class BSShapeNull : BSShape | |||
283 | } | 356 | } |
284 | 357 | ||
285 | // ============================================================================================================ | 358 | // ============================================================================================================ |
359 | // BSShapeNative is a wrapper for a Bullet 'native' shape -- cube and sphere. | ||
360 | // They are odd in that they don't allocate meshes but are computated/procedural. | ||
361 | // This means allocation and freeing is different than meshes. | ||
286 | public class BSShapeNative : BSShape | 362 | public class BSShapeNative : BSShape |
287 | { | 363 | { |
288 | private static string LogHeader = "[BULLETSIM SHAPE NATIVE]"; | 364 | private static string LogHeader = "[BULLETSIM SHAPE NATIVE]"; |
@@ -361,6 +437,7 @@ public class BSShapeNative : BSShape | |||
361 | } | 437 | } |
362 | 438 | ||
363 | // ============================================================================================================ | 439 | // ============================================================================================================ |
440 | // BSShapeMesh is a simple mesh. | ||
364 | public class BSShapeMesh : BSShape | 441 | public class BSShapeMesh : BSShape |
365 | { | 442 | { |
366 | private static string LogHeader = "[BULLETSIM SHAPE MESH]"; | 443 | private static string LogHeader = "[BULLETSIM SHAPE MESH]"; |
@@ -457,7 +534,11 @@ public class BSShapeMesh : BSShape | |||
457 | PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | 534 | PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) |
458 | { | 535 | { |
459 | return BSShapeMesh.CreatePhysicalMeshShape(physicsScene, prim, newMeshKey, pbs, size, lod, | 536 | return BSShapeMesh.CreatePhysicalMeshShape(physicsScene, prim, newMeshKey, pbs, size, lod, |
460 | (w, iC, i, vC, v) => physicsScene.PE.CreateMeshShape(w, iC, i, vC, v) ); | 537 | (w, iC, i, vC, v) => |
538 | { | ||
539 | shapeInfo.Vertices = vC; | ||
540 | return physicsScene.PE.CreateMeshShape(w, iC, i, vC, v); | ||
541 | }); | ||
461 | } | 542 | } |
462 | 543 | ||
463 | // Code that uses the mesher to create the index/vertices info for a trimesh shape. | 544 | // Code that uses the mesher to create the index/vertices info for a trimesh shape. |
@@ -545,6 +626,9 @@ public class BSShapeMesh : BSShape | |||
545 | } | 626 | } |
546 | 627 | ||
547 | // ============================================================================================================ | 628 | // ============================================================================================================ |
629 | // BSShapeHull is a physical shape representation htat is made up of many convex hulls. | ||
630 | // The convex hulls are either supplied with the asset or are approximated by one of the | ||
631 | // convex hull creation routines (in OpenSim or in Bullet). | ||
548 | public class BSShapeHull : BSShape | 632 | public class BSShapeHull : BSShape |
549 | { | 633 | { |
550 | #pragma warning disable 414 | 634 | #pragma warning disable 414 |
@@ -553,6 +637,7 @@ public class BSShapeHull : BSShape | |||
553 | 637 | ||
554 | public static Dictionary<System.UInt64, BSShapeHull> Hulls = new Dictionary<System.UInt64, BSShapeHull>(); | 638 | public static Dictionary<System.UInt64, BSShapeHull> Hulls = new Dictionary<System.UInt64, BSShapeHull>(); |
555 | 639 | ||
640 | |||
556 | public BSShapeHull(BulletShape pShape) : base(pShape) | 641 | public BSShapeHull(BulletShape pShape) : base(pShape) |
557 | { | 642 | { |
558 | } | 643 | } |
@@ -615,6 +700,7 @@ public class BSShapeHull : BSShape | |||
615 | // TODO: schedule aging and destruction of unused meshes. | 700 | // TODO: schedule aging and destruction of unused meshes. |
616 | } | 701 | } |
617 | } | 702 | } |
703 | |||
618 | List<ConvexResult> m_hulls; | 704 | List<ConvexResult> m_hulls; |
619 | private BulletShape CreatePhysicalHull(BSScene physicsScene, BSPhysObject prim, System.UInt64 newHullKey, | 705 | private BulletShape CreatePhysicalHull(BSScene physicsScene, BSPhysObject prim, System.UInt64 newHullKey, |
620 | PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | 706 | PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) |
@@ -647,6 +733,7 @@ public class BSShapeHull : BSShape | |||
647 | if (allHulls != null && BSParam.ShouldUseAssetHulls) | 733 | if (allHulls != null && BSParam.ShouldUseAssetHulls) |
648 | { | 734 | { |
649 | int hullCount = allHulls.Count; | 735 | int hullCount = allHulls.Count; |
736 | shapeInfo.HullCount = hullCount; | ||
650 | int totalVertices = 1; // include one for the count of the hulls | 737 | int totalVertices = 1; // include one for the count of the hulls |
651 | // Using the structure described for HACD hulls, create the memory sturcture | 738 | // Using the structure described for HACD hulls, create the memory sturcture |
652 | // to pass the hull data to the creater. | 739 | // to pass the hull data to the creater. |
@@ -659,6 +746,7 @@ public class BSShapeHull : BSShape | |||
659 | 746 | ||
660 | convHulls[0] = (float)hullCount; | 747 | convHulls[0] = (float)hullCount; |
661 | int jj = 1; | 748 | int jj = 1; |
749 | int hullIndex = 0; | ||
662 | foreach (List<OMV.Vector3> hullVerts in allHulls) | 750 | foreach (List<OMV.Vector3> hullVerts in allHulls) |
663 | { | 751 | { |
664 | convHulls[jj + 0] = hullVerts.Count; | 752 | convHulls[jj + 0] = hullVerts.Count; |
@@ -673,6 +761,8 @@ public class BSShapeHull : BSShape | |||
673 | convHulls[jj + 2] = oneVert.Z; | 761 | convHulls[jj + 2] = oneVert.Z; |
674 | jj += 3; | 762 | jj += 3; |
675 | } | 763 | } |
764 | shapeInfo.SetVerticesPerHull(hullIndex, hullVerts.Count); | ||
765 | hullIndex++; | ||
676 | } | 766 | } |
677 | 767 | ||
678 | // create the hull data structure in Bullet | 768 | // create the hull data structure in Bullet |
@@ -708,6 +798,10 @@ public class BSShapeHull : BSShape | |||
708 | physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,hullFromMesh,shape={1}", prim.LocalID, newShape); | 798 | physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,hullFromMesh,shape={1}", prim.LocalID, newShape); |
709 | 799 | ||
710 | // Now done with the mesh shape. | 800 | // Now done with the mesh shape. |
801 | shapeInfo.HullCount = 1; | ||
802 | BSShapeMesh maybeMesh = meshShape as BSShapeMesh; | ||
803 | if (maybeMesh != null) | ||
804 | shapeInfo.SetVerticesPerHull(0, maybeMesh.shapeInfo.Vertices); | ||
711 | meshShape.Dereference(physicsScene); | 805 | meshShape.Dereference(physicsScene); |
712 | } | 806 | } |
713 | physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,bulletHACD,exit,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape); | 807 | physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,bulletHACD,exit,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape); |
@@ -857,6 +951,8 @@ public class BSShapeHull : BSShape | |||
857 | } | 951 | } |
858 | 952 | ||
859 | // ============================================================================================================ | 953 | // ============================================================================================================ |
954 | // BSShapeCompound is a wrapper for the Bullet compound shape which is built from multiple, separate | ||
955 | // meshes. Used by BulletSim for complex shapes like linksets. | ||
860 | public class BSShapeCompound : BSShape | 956 | public class BSShapeCompound : BSShape |
861 | { | 957 | { |
862 | private static string LogHeader = "[BULLETSIM SHAPE COMPOUND]"; | 958 | private static string LogHeader = "[BULLETSIM SHAPE COMPOUND]"; |
@@ -999,6 +1095,9 @@ public class BSShapeCompound : BSShape | |||
999 | } | 1095 | } |
1000 | 1096 | ||
1001 | // ============================================================================================================ | 1097 | // ============================================================================================================ |
1098 | // BSShapeConvexHull is a wrapper for a Bullet single convex hull. A BSShapeHull contains multiple convex | ||
1099 | // hull shapes. This is used for simple prims that are convex and thus can be made into a simple | ||
1100 | // collision shape (a single hull). More complex physical shapes will be BSShapeHull's. | ||
1002 | public class BSShapeConvexHull : BSShape | 1101 | public class BSShapeConvexHull : BSShape |
1003 | { | 1102 | { |
1004 | #pragma warning disable 414 | 1103 | #pragma warning disable 414 |
@@ -1098,6 +1197,9 @@ public class BSShapeConvexHull : BSShape | |||
1098 | } | 1197 | } |
1099 | } | 1198 | } |
1100 | // ============================================================================================================ | 1199 | // ============================================================================================================ |
1200 | // BSShapeGImpact is a wrapper for the Bullet GImpact shape which is a collision mesh shape that | ||
1201 | // can handle concave as well as convex shapes. Much slower computationally but creates smoother | ||
1202 | // shapes than multiple convex hull approximations. | ||
1101 | public class BSShapeGImpact : BSShape | 1203 | public class BSShapeGImpact : BSShape |
1102 | { | 1204 | { |
1103 | #pragma warning disable 414 | 1205 | #pragma warning disable 414 |
@@ -1151,7 +1253,11 @@ public class BSShapeGImpact : BSShape | |||
1151 | PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | 1253 | PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) |
1152 | { | 1254 | { |
1153 | return BSShapeMesh.CreatePhysicalMeshShape(physicsScene, prim, newMeshKey, pbs, size, lod, | 1255 | return BSShapeMesh.CreatePhysicalMeshShape(physicsScene, prim, newMeshKey, pbs, size, lod, |
1154 | (w, iC, i, vC, v) => physicsScene.PE.CreateGImpactShape(w, iC, i, vC, v) ); | 1256 | (w, iC, i, vC, v) => |
1257 | { | ||
1258 | shapeInfo.Vertices = vC; | ||
1259 | return physicsScene.PE.CreateGImpactShape(w, iC, i, vC, v); | ||
1260 | }); | ||
1155 | } | 1261 | } |
1156 | 1262 | ||
1157 | public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) | 1263 | public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) |
@@ -1206,6 +1312,7 @@ public class BSShapeGImpact : BSShape | |||
1206 | } | 1312 | } |
1207 | 1313 | ||
1208 | // ============================================================================================================ | 1314 | // ============================================================================================================ |
1315 | // BSShapeAvatar is a specialized mesh shape for avatars. | ||
1209 | public class BSShapeAvatar : BSShape | 1316 | public class BSShapeAvatar : BSShape |
1210 | { | 1317 | { |
1211 | #pragma warning disable 414 | 1318 | #pragma warning disable 414 |