diff options
5 files changed, 394 insertions, 12 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 9695fcf..5d359e8 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -96,11 +96,9 @@ public class BSPrim : BSPhysObject | |||
96 | _isPhysical = pisPhysical; | 96 | _isPhysical = pisPhysical; |
97 | _isVolumeDetect = false; | 97 | _isVolumeDetect = false; |
98 | 98 | ||
99 | // Add a dynamic vehicle to our set of actors that can move this prim. | ||
100 | // PhysicalActors.Add(VehicleActorName, new BSDynamics(PhysScene, this, VehicleActorName)); | ||
101 | |||
102 | _mass = CalculateMass(); | 99 | _mass = CalculateMass(); |
103 | 100 | ||
101 | DetailLog("{0},BSPrim.constructor,pbs={1}", LocalID, BSScene.PrimitiveBaseShapeToString(pbs)); | ||
104 | // DetailLog("{0},BSPrim.constructor,call", LocalID); | 102 | // DetailLog("{0},BSPrim.constructor,call", LocalID); |
105 | // do the actual object creation at taint time | 103 | // do the actual object creation at taint time |
106 | PhysScene.TaintedObject(LocalID, "BSPrim.create", delegate() | 104 | PhysScene.TaintedObject(LocalID, "BSPrim.create", delegate() |
@@ -168,6 +166,7 @@ public class BSPrim : BSPhysObject | |||
168 | public override PrimitiveBaseShape Shape { | 166 | public override PrimitiveBaseShape Shape { |
169 | set { | 167 | set { |
170 | BaseShape = value; | 168 | BaseShape = value; |
169 | DetailLog("{0},BSPrim.changeShape,pbs={1}", LocalID, BSScene.PrimitiveBaseShapeToString(BaseShape)); | ||
171 | PrimAssetState = PrimAssetCondition.Unknown; | 170 | PrimAssetState = PrimAssetCondition.Unknown; |
172 | ForceBodyShapeRebuild(false); | 171 | ForceBodyShapeRebuild(false); |
173 | } | 172 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 414bc92..238fcc2 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | |||
@@ -947,6 +947,73 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
947 | } | 947 | } |
948 | #endregion // Extensions | 948 | #endregion // Extensions |
949 | 949 | ||
950 | public static string PrimitiveBaseShapeToString(PrimitiveBaseShape pbs) | ||
951 | { | ||
952 | float pathShearX = pbs.PathShearX < 128 ? (float)pbs.PathShearX * 0.01f : (float)(pbs.PathShearX - 256) * 0.01f; | ||
953 | float pathShearY = pbs.PathShearY < 128 ? (float)pbs.PathShearY * 0.01f : (float)(pbs.PathShearY - 256) * 0.01f; | ||
954 | float pathBegin = (float)pbs.PathBegin * 2.0e-5f; | ||
955 | float pathEnd = 1.0f - (float)pbs.PathEnd * 2.0e-5f; | ||
956 | float pathScaleX = (float)(pbs.PathScaleX - 100) * 0.01f; | ||
957 | float pathScaleY = (float)(pbs.PathScaleY - 100) * 0.01f; | ||
958 | |||
959 | float profileBegin = (float)pbs.ProfileBegin * 2.0e-5f; | ||
960 | float profileEnd = 1.0f - (float)pbs.ProfileEnd * 2.0e-5f; | ||
961 | float profileHollow = (float)pbs.ProfileHollow * 2.0e-5f; | ||
962 | if (profileHollow > 0.95f) | ||
963 | profileHollow = 0.95f; | ||
964 | |||
965 | StringBuilder buff = new StringBuilder(); | ||
966 | buff.Append("shape="); | ||
967 | buff.Append(((ProfileShape)pbs.ProfileShape).ToString()); | ||
968 | buff.Append(","); | ||
969 | buff.Append("hollow="); | ||
970 | buff.Append(((HollowShape)pbs.HollowShape).ToString()); | ||
971 | buff.Append(","); | ||
972 | buff.Append("pathCurve="); | ||
973 | buff.Append(((Extrusion)pbs.PathCurve).ToString()); | ||
974 | buff.Append(","); | ||
975 | buff.Append("profCurve="); | ||
976 | buff.Append(((Extrusion)pbs.ProfileCurve).ToString()); | ||
977 | buff.Append(","); | ||
978 | buff.Append("profHollow="); | ||
979 | buff.Append(profileHollow.ToString()); | ||
980 | buff.Append(","); | ||
981 | buff.Append("pathBegEnd="); | ||
982 | buff.Append(pathBegin.ToString()); | ||
983 | buff.Append("/"); | ||
984 | buff.Append(pathEnd.ToString()); | ||
985 | buff.Append(","); | ||
986 | buff.Append("profileBegEnd="); | ||
987 | buff.Append(profileBegin.ToString()); | ||
988 | buff.Append("/"); | ||
989 | buff.Append(profileEnd.ToString()); | ||
990 | buff.Append(","); | ||
991 | buff.Append("scaleXY="); | ||
992 | buff.Append(pathScaleX.ToString()); | ||
993 | buff.Append("/"); | ||
994 | buff.Append(pathScaleY.ToString()); | ||
995 | buff.Append(","); | ||
996 | buff.Append("shearXY="); | ||
997 | buff.Append(pathShearX.ToString()); | ||
998 | buff.Append("/"); | ||
999 | buff.Append(pathShearY.ToString()); | ||
1000 | buff.Append(","); | ||
1001 | buff.Append("taperXY="); | ||
1002 | buff.Append(pbs.PathTaperX.ToString()); | ||
1003 | buff.Append("/"); | ||
1004 | buff.Append(pbs.PathTaperY.ToString()); | ||
1005 | buff.Append(","); | ||
1006 | buff.Append("skew="); | ||
1007 | buff.Append(pbs.PathSkew.ToString()); | ||
1008 | buff.Append(","); | ||
1009 | buff.Append("twist/Beg="); | ||
1010 | buff.Append(pbs.PathTwist.ToString()); | ||
1011 | buff.Append("/"); | ||
1012 | buff.Append(pbs.PathTwistBegin.ToString()); | ||
1013 | |||
1014 | return buff.ToString(); | ||
1015 | } | ||
1016 | |||
950 | #region Taints | 1017 | #region Taints |
951 | // The simulation execution order is: | 1018 | // The simulation execution order is: |
952 | // Simulate() | 1019 | // Simulate() |
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 |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs b/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs index 28207a4..775bca2 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs | |||
@@ -28,15 +28,16 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.IO; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Linq; | ||
32 | using System.Text; | 31 | using System.Text; |
33 | 32 | ||
34 | using Nini.Config; | 33 | using Nini.Config; |
35 | 34 | ||
36 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
37 | using OpenSim.Region.Physics.BulletSPlugin; | 36 | using OpenSim.Region.Physics.Manager; |
38 | using OpenSim.Region.Physics.Meshing; | 37 | using OpenSim.Region.Physics.Meshing; |
39 | 38 | ||
39 | using OpenMetaverse; | ||
40 | |||
40 | namespace OpenSim.Region.Physics.BulletSPlugin.Tests | 41 | namespace OpenSim.Region.Physics.BulletSPlugin.Tests |
41 | { | 42 | { |
42 | // Utility functions for building up and tearing down the sample physics environments | 43 | // Utility functions for building up and tearing down the sample physics environments |
@@ -77,17 +78,21 @@ public static class BulletSimTestsUtil | |||
77 | bulletSimConfig.Set("VehicleLoggingEnabled","True"); | 78 | bulletSimConfig.Set("VehicleLoggingEnabled","True"); |
78 | } | 79 | } |
79 | 80 | ||
80 | BSPlugin bsPlugin = new BSPlugin(); | 81 | PhysicsPluginManager physicsPluginManager; |
82 | physicsPluginManager = new PhysicsPluginManager(); | ||
83 | physicsPluginManager.LoadPluginsFromAssemblies("Physics"); | ||
84 | |||
85 | Vector3 regionExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); | ||
86 | |||
87 | PhysicsScene pScene = physicsPluginManager.GetPhysicsScene( | ||
88 | "BulletSim", "Meshmerizer", openSimINI, "BSTestRegion", regionExtent); | ||
81 | 89 | ||
82 | BSScene bsScene = (BSScene)bsPlugin.GetScene("BSTestRegion"); | 90 | BSScene bsScene = pScene as BSScene; |
83 | 91 | ||
84 | // Since the asset requestor is not initialized, any mesh or sculptie will be a cube. | 92 | // Since the asset requestor is not initialized, any mesh or sculptie will be a cube. |
85 | // In the future, add a fake asset fetcher to get meshes and sculpts. | 93 | // In the future, add a fake asset fetcher to get meshes and sculpts. |
86 | // bsScene.RequestAssetMethod = ???; | 94 | // bsScene.RequestAssetMethod = ???; |
87 | 95 | ||
88 | Meshing.Meshmerizer mesher = new Meshmerizer(openSimINI); | ||
89 | bsScene.Initialise(mesher, openSimINI); | ||
90 | |||
91 | return bsScene; | 96 | return bsScene; |
92 | } | 97 | } |
93 | 98 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/Tests/HullCreation.cs b/OpenSim/Region/Physics/BulletSPlugin/Tests/HullCreation.cs new file mode 100644 index 0000000..da532e0e --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/Tests/HullCreation.cs | |||
@@ -0,0 +1,204 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Text; | ||
32 | |||
33 | using NUnit.Framework; | ||
34 | using log4net; | ||
35 | |||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Physics.BulletSPlugin; | ||
38 | using OpenSim.Region.Physics.Manager; | ||
39 | using OpenSim.Tests.Common; | ||
40 | |||
41 | using OpenMetaverse; | ||
42 | |||
43 | namespace OpenSim.Region.Physics.BulletSPlugin.Tests | ||
44 | { | ||
45 | [TestFixture] | ||
46 | public class HullCreation : OpenSimTestCase | ||
47 | { | ||
48 | // Documentation on attributes: http://www.nunit.org/index.php?p=attributes&r=2.6.1 | ||
49 | // Documentation on assertions: http://www.nunit.org/index.php?p=assertions&r=2.6.1 | ||
50 | |||
51 | BSScene PhysicsScene { get; set; } | ||
52 | Vector3 ObjectInitPosition; | ||
53 | float simulationTimeStep = 0.089f; | ||
54 | |||
55 | [TestFixtureSetUp] | ||
56 | public void Init() | ||
57 | { | ||
58 | |||
59 | } | ||
60 | |||
61 | [TestFixtureTearDown] | ||
62 | public void TearDown() | ||
63 | { | ||
64 | if (PhysicsScene != null) | ||
65 | { | ||
66 | // The Dispose() will also free any physical objects in the scene | ||
67 | PhysicsScene.Dispose(); | ||
68 | PhysicsScene = null; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | [TestCase(7, 2, 5f, 5f, 32, 0f)] /* default hull parameters */ | ||
73 | public void GeomHullConvexDecomp( int maxDepthSplit, | ||
74 | int maxDepthSplitForSimpleShapes, | ||
75 | float concavityThresholdPercent, | ||
76 | float volumeConservationThresholdPercent, | ||
77 | int maxVertices, | ||
78 | float maxSkinWidth) | ||
79 | { | ||
80 | // Setup the physics engine to use the C# version of convex decomp | ||
81 | Dictionary<string, string> engineParams = new Dictionary<string, string>(); | ||
82 | engineParams.Add("MeshSculptedPrim", "true"); // ShouldMeshSculptedPrim | ||
83 | engineParams.Add("ForceSimplePrimMeshing", "false"); // ShouldForceSimplePrimMeshing | ||
84 | engineParams.Add("UseHullsForPhysicalObjects", "true"); // ShouldUseHullsForPhysicalObjects | ||
85 | engineParams.Add("ShouldRemoveZeroWidthTriangles", "true"); | ||
86 | engineParams.Add("ShouldUseBulletHACD", "false"); | ||
87 | engineParams.Add("ShouldUseSingleConvexHullForPrims", "true"); | ||
88 | engineParams.Add("ShouldUseGImpactShapeForPrims", "false"); | ||
89 | engineParams.Add("ShouldUseAssetHulls", "true"); | ||
90 | |||
91 | engineParams.Add("CSHullMaxDepthSplit", maxDepthSplit.ToString()); | ||
92 | engineParams.Add("CSHullMaxDepthSplitForSimpleShapes", maxDepthSplitForSimpleShapes.ToString()); | ||
93 | engineParams.Add("CSHullConcavityThresholdPercent", concavityThresholdPercent.ToString()); | ||
94 | engineParams.Add("CSHullVolumeConservationThresholdPercent", volumeConservationThresholdPercent.ToString()); | ||
95 | engineParams.Add("CSHullMaxVertices", maxVertices.ToString()); | ||
96 | engineParams.Add("CSHullMaxSkinWidth", maxSkinWidth.ToString()); | ||
97 | |||
98 | PhysicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams); | ||
99 | |||
100 | PrimitiveBaseShape pbs; | ||
101 | Vector3 pos; | ||
102 | Vector3 size; | ||
103 | Quaternion rot; | ||
104 | bool isPhys; | ||
105 | |||
106 | // Cylinder | ||
107 | pbs = PrimitiveBaseShape.CreateCylinder(); | ||
108 | pos = new Vector3(100.0f, 100.0f, 0f); | ||
109 | pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 10f; | ||
110 | ObjectInitPosition = pos; | ||
111 | size = new Vector3(2f, 2f, 2f); | ||
112 | pbs.Scale = size; | ||
113 | rot = Quaternion.Identity; | ||
114 | isPhys = true; | ||
115 | uint cylinderLocalID = 123; | ||
116 | PhysicsScene.AddPrimShape("testCylinder", pbs, pos, size, rot, isPhys, cylinderLocalID); | ||
117 | BSPrim primTypeCylinder = (BSPrim)PhysicsScene.PhysObjects[cylinderLocalID]; | ||
118 | |||
119 | // Hollow Cylinder | ||
120 | pbs = PrimitiveBaseShape.CreateCylinder(); | ||
121 | pbs.ProfileHollow = (ushort)(0.70f * 50000); | ||
122 | pos = new Vector3(110.0f, 110.0f, 0f); | ||
123 | pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 10f; | ||
124 | ObjectInitPosition = pos; | ||
125 | size = new Vector3(2f, 2f, 2f); | ||
126 | pbs.Scale = size; | ||
127 | rot = Quaternion.Identity; | ||
128 | isPhys = true; | ||
129 | uint hollowCylinderLocalID = 124; | ||
130 | PhysicsScene.AddPrimShape("testHollowCylinder", pbs, pos, size, rot, isPhys, hollowCylinderLocalID); | ||
131 | BSPrim primTypeHollowCylinder = (BSPrim)PhysicsScene.PhysObjects[hollowCylinderLocalID]; | ||
132 | |||
133 | // Torus | ||
134 | // ProfileCurve = Circle, PathCurve = Curve1 | ||
135 | pbs = PrimitiveBaseShape.CreateSphere(); | ||
136 | pbs.ProfileShape = (byte)ProfileShape.Circle; | ||
137 | pbs.PathCurve = (byte)Extrusion.Curve1; | ||
138 | pos = new Vector3(120.0f, 120.0f, 0f); | ||
139 | pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 10f; | ||
140 | ObjectInitPosition = pos; | ||
141 | size = new Vector3(2f, 4f, 4f); | ||
142 | pbs.Scale = size; | ||
143 | rot = Quaternion.Identity; | ||
144 | isPhys = true; | ||
145 | uint torusLocalID = 125; | ||
146 | PhysicsScene.AddPrimShape("testTorus", pbs, pos, size, rot, isPhys, torusLocalID); | ||
147 | BSPrim primTypeTorus = (BSPrim)PhysicsScene.PhysObjects[torusLocalID]; | ||
148 | |||
149 | // The actual prim shape creation happens at taint time | ||
150 | PhysicsScene.ProcessTaints(); | ||
151 | |||
152 | // Check out the created hull shapes and report their characteristics | ||
153 | ReportShapeGeom(primTypeCylinder); | ||
154 | ReportShapeGeom(primTypeHollowCylinder); | ||
155 | ReportShapeGeom(primTypeTorus); | ||
156 | } | ||
157 | |||
158 | [TestCase] | ||
159 | public void GeomHullBulletHACD() | ||
160 | { | ||
161 | // Cylinder | ||
162 | // Hollow Cylinder | ||
163 | // Torus | ||
164 | } | ||
165 | |||
166 | private void ReportShapeGeom(BSPrim prim) | ||
167 | { | ||
168 | if (prim != null) | ||
169 | { | ||
170 | if (prim.PhysShape.HasPhysicalShape) | ||
171 | { | ||
172 | BSShape physShape = prim.PhysShape; | ||
173 | string shapeType = physShape.GetType().ToString(); | ||
174 | switch (shapeType) | ||
175 | { | ||
176 | case "OpenSim.Region.Physics.BulletSPlugin.BSShapeNative": | ||
177 | BSShapeNative nShape = physShape as BSShapeNative; | ||
178 | prim.PhysScene.DetailLog("{0}, type={1}", prim.Name, shapeType); | ||
179 | break; | ||
180 | case "OpenSim.Region.Physics.BulletSPlugin.BSShapeMesh": | ||
181 | BSShapeMesh mShape = physShape as BSShapeMesh; | ||
182 | prim.PhysScene.DetailLog("{0}, mesh, shapeInfo={1}", prim.Name, mShape.shapeInfo); | ||
183 | break; | ||
184 | case "OpenSim.Region.Physics.BulletSPlugin.BSShapeHull": | ||
185 | BSShapeHull hShape = physShape as BSShapeHull; | ||
186 | prim.PhysScene.DetailLog("{0}, hull, shapeInfo={1}", prim.Name, hShape.shapeInfo); | ||
187 | break; | ||
188 | case "OpenSim.Region.Physics.BulletSPlugin.BSShapeConvexHull": | ||
189 | BSShapeConvexHull chShape = physShape as BSShapeConvexHull; | ||
190 | prim.PhysScene.DetailLog("{0}, convexHull, shapeInfo={1}", prim.Name, chShape.shapeInfo); | ||
191 | break; | ||
192 | case "OpenSim.Region.Physics.BulletSPlugin.BSShapeCompound": | ||
193 | BSShapeCompound cShape = physShape as BSShapeCompound; | ||
194 | prim.PhysScene.DetailLog("{0}, type={1}", prim.Name, shapeType); | ||
195 | break; | ||
196 | default: | ||
197 | prim.PhysScene.DetailLog("{0}, type={1}", prim.Name, shapeType); | ||
198 | break; | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | } \ No newline at end of file | ||