aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/Tests/HullCreation.cs
diff options
context:
space:
mode:
authorRobert Adams2014-12-31 12:48:26 -0800
committerRobert Adams2014-12-31 12:48:26 -0800
commitc89d0e26b2c098cd2c5679fb73987a742a66ce38 (patch)
tree0ee422a9563736aab47385a97a6420d70adc97da /OpenSim/Region/Physics/BulletSPlugin/Tests/HullCreation.cs
parentBulletSim: Add axis locking enabled through the ExtendedPhysics module. (diff)
downloadopensim-SC-c89d0e26b2c098cd2c5679fb73987a742a66ce38.zip
opensim-SC-c89d0e26b2c098cd2c5679fb73987a742a66ce38.tar.gz
opensim-SC-c89d0e26b2c098cd2c5679fb73987a742a66ce38.tar.bz2
opensim-SC-c89d0e26b2c098cd2c5679fb73987a742a66ce38.tar.xz
BulletSim: add the beginnings of hull creation unit testing.
Change how physics engine is created in unit tests to resolve a lib reference problem. Add ShapeInfoInfo class to collect info about the created physical shape for debugging and unit test testing.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/Tests/HullCreation.cs204
1 files changed, 204 insertions, 0 deletions
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
28using System;
29using System.Collections.Generic;
30using System.Linq;
31using System.Text;
32
33using NUnit.Framework;
34using log4net;
35
36using OpenSim.Framework;
37using OpenSim.Region.Physics.BulletSPlugin;
38using OpenSim.Region.Physics.Manager;
39using OpenSim.Tests.Common;
40
41using OpenMetaverse;
42
43namespace OpenSim.Region.Physics.BulletSPlugin.Tests
44{
45[TestFixture]
46public 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