diff options
author | Diva Canto | 2015-08-30 20:06:53 -0700 |
---|---|---|
committer | Diva Canto | 2015-08-30 20:06:53 -0700 |
commit | 1d6b33bc2da3b312cff1d1802a73aacdf72b0385 (patch) | |
tree | 393736b501aac3b31eb0810bb72d926c7f14fbf8 /OpenSim/Region/PhysicsModules/BulletS/Tests | |
parent | Moved instantiation of SceneCommunicationService object to inside the scene c... (diff) | |
download | opensim-SC_OLD-1d6b33bc2da3b312cff1d1802a73aacdf72b0385.zip opensim-SC_OLD-1d6b33bc2da3b312cff1d1802a73aacdf72b0385.tar.gz opensim-SC_OLD-1d6b33bc2da3b312cff1d1802a73aacdf72b0385.tar.bz2 opensim-SC_OLD-1d6b33bc2da3b312cff1d1802a73aacdf72b0385.tar.xz |
Major renaming of Physics dlls / folders. No functional changes, just renames.
Diffstat (limited to 'OpenSim/Region/PhysicsModules/BulletS/Tests')
4 files changed, 517 insertions, 0 deletions
diff --git a/OpenSim/Region/PhysicsModules/BulletS/Tests/BasicVehicles.cs b/OpenSim/Region/PhysicsModules/BulletS/Tests/BasicVehicles.cs new file mode 100755 index 0000000..48e74eb --- /dev/null +++ b/OpenSim/Region/PhysicsModules/BulletS/Tests/BasicVehicles.cs | |||
@@ -0,0 +1,156 @@ | |||
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 BasicVehicles : 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 | BSPrim TestVehicle { get; set; } | ||
53 | Vector3 TestVehicleInitPosition { get; set; } | ||
54 | float simulationTimeStep = 0.089f; | ||
55 | |||
56 | [TestFixtureSetUp] | ||
57 | public void Init() | ||
58 | { | ||
59 | Dictionary<string, string> engineParams = new Dictionary<string, string>(); | ||
60 | engineParams.Add("VehicleEnableAngularVerticalAttraction", "true"); | ||
61 | engineParams.Add("VehicleAngularVerticalAttractionAlgorithm", "1"); | ||
62 | PhysicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams); | ||
63 | |||
64 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateSphere(); | ||
65 | Vector3 pos = new Vector3(100.0f, 100.0f, 0f); | ||
66 | pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 2f; | ||
67 | TestVehicleInitPosition = pos; | ||
68 | Vector3 size = new Vector3(1f, 1f, 1f); | ||
69 | pbs.Scale = size; | ||
70 | Quaternion rot = Quaternion.Identity; | ||
71 | bool isPhys = false; | ||
72 | uint localID = 123; | ||
73 | |||
74 | PhysicsScene.AddPrimShape("testPrim", pbs, pos, size, rot, isPhys, localID); | ||
75 | TestVehicle = (BSPrim)PhysicsScene.PhysObjects[localID]; | ||
76 | // The actual prim shape creation happens at taint time | ||
77 | PhysicsScene.ProcessTaints(); | ||
78 | |||
79 | } | ||
80 | |||
81 | [TestFixtureTearDown] | ||
82 | public void TearDown() | ||
83 | { | ||
84 | if (PhysicsScene != null) | ||
85 | { | ||
86 | // The Dispose() will also free any physical objects in the scene | ||
87 | PhysicsScene.Dispose(); | ||
88 | PhysicsScene = null; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | [TestCase(2f, 0.2f, 0.25f, 0.25f, 0.25f)] | ||
93 | [TestCase(2f, 0.2f, -0.25f, 0.25f, 0.25f)] | ||
94 | [TestCase(2f, 0.2f, 0.25f, -0.25f, 0.25f)] | ||
95 | [TestCase(2f, 0.2f, -0.25f, -0.25f, 0.25f)] | ||
96 | // [TestCase(2f, 0.2f, 0.785f, 0.0f, 0.25f) /*, "Leaning 45 degrees to the side" */] | ||
97 | // [TestCase(2f, 0.2f, 1.650f, 0.0f, 0.25f) /*, "Leaning more than 90 degrees to the side" */] | ||
98 | // [TestCase(2f, 0.2f, 2.750f, 0.0f, 0.25f) /*, "Almost upside down, tipped right" */] | ||
99 | // [TestCase(2f, 0.2f,-2.750f, 0.0f, 0.25f) /*, "Almost upside down, tipped left" */] | ||
100 | // [TestCase(2f, 0.2f, 0.0f, 0.785f, 0.25f) /*, "Tipped back 45 degrees" */] | ||
101 | // [TestCase(2f, 0.2f, 0.0f, 1.650f, 0.25f) /*, "Tipped back more than 90 degrees" */] | ||
102 | // [TestCase(2f, 0.2f, 0.0f, 2.750f, 0.25f) /*, "Almost upside down, tipped back" */] | ||
103 | // [TestCase(2f, 0.2f, 0.0f,-2.750f, 0.25f) /*, "Almost upside down, tipped forward" */] | ||
104 | public void AngularVerticalAttraction(float timeScale, float efficiency, float initRoll, float initPitch, float initYaw) | ||
105 | { | ||
106 | // Enough simulation steps to cover the timescale the operation should take | ||
107 | int simSteps = (int)(timeScale / simulationTimeStep) + 1; | ||
108 | |||
109 | // Tip the vehicle | ||
110 | Quaternion initOrientation = Quaternion.CreateFromEulers(initRoll, initPitch, initYaw); | ||
111 | TestVehicle.Orientation = initOrientation; | ||
112 | |||
113 | TestVehicle.Position = TestVehicleInitPosition; | ||
114 | |||
115 | // The vehicle controller is not enabled directly (by setting a vehicle type). | ||
116 | // Instead the appropriate values are set and calls are made just the parts of the | ||
117 | // controller we want to exercise. Stepping the physics engine then applies | ||
118 | // the actions of that one feature. | ||
119 | BSDynamics vehicleActor = TestVehicle.GetVehicleActor(true /* createIfNone */); | ||
120 | if (vehicleActor != null) | ||
121 | { | ||
122 | vehicleActor.ProcessFloatVehicleParam(Vehicle.VERTICAL_ATTRACTION_EFFICIENCY, efficiency); | ||
123 | vehicleActor.ProcessFloatVehicleParam(Vehicle.VERTICAL_ATTRACTION_TIMESCALE, timeScale); | ||
124 | // vehicleActor.enableAngularVerticalAttraction = true; | ||
125 | |||
126 | TestVehicle.IsPhysical = true; | ||
127 | PhysicsScene.ProcessTaints(); | ||
128 | |||
129 | // Step the simulator a bunch of times and vertical attraction should orient the vehicle up | ||
130 | for (int ii = 0; ii < simSteps; ii++) | ||
131 | { | ||
132 | vehicleActor.ForgetKnownVehicleProperties(); | ||
133 | vehicleActor.ComputeAngularVerticalAttraction(); | ||
134 | vehicleActor.PushKnownChanged(); | ||
135 | |||
136 | PhysicsScene.Simulate(simulationTimeStep); | ||
137 | } | ||
138 | } | ||
139 | |||
140 | TestVehicle.IsPhysical = false; | ||
141 | PhysicsScene.ProcessTaints(); | ||
142 | |||
143 | // After these steps, the vehicle should be upright | ||
144 | /* | ||
145 | float finalRoll, finalPitch, finalYaw; | ||
146 | TestVehicle.Orientation.GetEulerAngles(out finalRoll, out finalPitch, out finalYaw); | ||
147 | Assert.That(finalRoll, Is.InRange(-0.01f, 0.01f)); | ||
148 | Assert.That(finalPitch, Is.InRange(-0.01f, 0.01f)); | ||
149 | Assert.That(finalYaw, Is.InRange(initYaw - 0.1f, initYaw + 0.1f)); | ||
150 | */ | ||
151 | |||
152 | Vector3 upPointer = Vector3.UnitZ * TestVehicle.Orientation; | ||
153 | Assert.That(upPointer.Z, Is.GreaterThan(0.99f)); | ||
154 | } | ||
155 | } | ||
156 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTests.cs b/OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTests.cs new file mode 100755 index 0000000..35cbc1d --- /dev/null +++ b/OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTests.cs | |||
@@ -0,0 +1,56 @@ | |||
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.Tests.Common; | ||
37 | |||
38 | namespace OpenSim.Region.Physics.BulletSPlugin.Tests | ||
39 | { | ||
40 | [TestFixture] | ||
41 | public class BulletSimTests : OpenSimTestCase | ||
42 | { | ||
43 | // Documentation on attributes: http://www.nunit.org/index.php?p=attributes&r=2.6.1 | ||
44 | // Documentation on assertions: http://www.nunit.org/index.php?p=assertions&r=2.6.1 | ||
45 | |||
46 | [TestFixtureSetUp] | ||
47 | public void Init() | ||
48 | { | ||
49 | } | ||
50 | |||
51 | [TestFixtureTearDown] | ||
52 | public void TearDown() | ||
53 | { | ||
54 | } | ||
55 | } | ||
56 | } | ||
diff --git a/OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTestsUtil.cs b/OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTestsUtil.cs new file mode 100755 index 0000000..775bca2 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTestsUtil.cs | |||
@@ -0,0 +1,100 @@ | |||
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.IO; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | using Nini.Config; | ||
34 | |||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Region.Physics.Manager; | ||
37 | using OpenSim.Region.Physics.Meshing; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | |||
41 | namespace OpenSim.Region.Physics.BulletSPlugin.Tests | ||
42 | { | ||
43 | // Utility functions for building up and tearing down the sample physics environments | ||
44 | public static class BulletSimTestsUtil | ||
45 | { | ||
46 | // 'engineName' is the Bullet engine to use. Either null (for unmanaged), "BulletUnmanaged" or "BulletXNA" | ||
47 | // 'params' is a set of keyValue pairs to set in the engine's configuration file (override defaults) | ||
48 | // May be 'null' if there are no overrides. | ||
49 | public static BSScene CreateBasicPhysicsEngine(Dictionary<string,string> paramOverrides) | ||
50 | { | ||
51 | IConfigSource openSimINI = new IniConfigSource(); | ||
52 | IConfig startupConfig = openSimINI.AddConfig("Startup"); | ||
53 | startupConfig.Set("physics", "BulletSim"); | ||
54 | startupConfig.Set("meshing", "Meshmerizer"); | ||
55 | startupConfig.Set("cacheSculptMaps", "false"); // meshmerizer shouldn't save maps | ||
56 | |||
57 | IConfig bulletSimConfig = openSimINI.AddConfig("BulletSim"); | ||
58 | // If the caller cares, specify the bullet engine otherwise it will default to "BulletUnmanaged". | ||
59 | // bulletSimConfig.Set("BulletEngine", "BulletUnmanaged"); | ||
60 | // bulletSimConfig.Set("BulletEngine", "BulletXNA"); | ||
61 | bulletSimConfig.Set("MeshSculptedPrim", "false"); | ||
62 | bulletSimConfig.Set("ForceSimplePrimMeshing", "true"); | ||
63 | if (paramOverrides != null) | ||
64 | { | ||
65 | foreach (KeyValuePair<string, string> kvp in paramOverrides) | ||
66 | { | ||
67 | bulletSimConfig.Set(kvp.Key, kvp.Value); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | // If a special directory exists, put detailed logging therein. | ||
72 | // This allows local testing/debugging without having to worry that the build engine will output logs. | ||
73 | if (Directory.Exists("physlogs")) | ||
74 | { | ||
75 | bulletSimConfig.Set("PhysicsLoggingDir","./physlogs"); | ||
76 | bulletSimConfig.Set("PhysicsLoggingEnabled","True"); | ||
77 | bulletSimConfig.Set("PhysicsLoggingDoFlush","True"); | ||
78 | bulletSimConfig.Set("VehicleLoggingEnabled","True"); | ||
79 | } | ||
80 | |||
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); | ||
89 | |||
90 | BSScene bsScene = pScene as BSScene; | ||
91 | |||
92 | // Since the asset requestor is not initialized, any mesh or sculptie will be a cube. | ||
93 | // In the future, add a fake asset fetcher to get meshes and sculpts. | ||
94 | // bsScene.RequestAssetMethod = ???; | ||
95 | |||
96 | return bsScene; | ||
97 | } | ||
98 | |||
99 | } | ||
100 | } | ||
diff --git a/OpenSim/Region/PhysicsModules/BulletS/Tests/HullCreation.cs b/OpenSim/Region/PhysicsModules/BulletS/Tests/HullCreation.cs new file mode 100644 index 0000000..5a5de11 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/BulletS/Tests/HullCreation.cs | |||
@@ -0,0 +1,205 @@ | |||
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 | |||
54 | [TestFixtureSetUp] | ||
55 | public void Init() | ||
56 | { | ||
57 | |||
58 | } | ||
59 | |||
60 | [TestFixtureTearDown] | ||
61 | public void TearDown() | ||
62 | { | ||
63 | if (PhysicsScene != null) | ||
64 | { | ||
65 | // The Dispose() will also free any physical objects in the scene | ||
66 | PhysicsScene.Dispose(); | ||
67 | PhysicsScene = null; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | [TestCase(7, 2, 5f, 5f, 32, 0f)] /* default hull parameters */ | ||
72 | public void GeomHullConvexDecomp( int maxDepthSplit, | ||
73 | int maxDepthSplitForSimpleShapes, | ||
74 | float concavityThresholdPercent, | ||
75 | float volumeConservationThresholdPercent, | ||
76 | int maxVertices, | ||
77 | float maxSkinWidth) | ||
78 | { | ||
79 | // Setup the physics engine to use the C# version of convex decomp | ||
80 | Dictionary<string, string> engineParams = new Dictionary<string, string>(); | ||
81 | engineParams.Add("MeshSculptedPrim", "true"); // ShouldMeshSculptedPrim | ||
82 | engineParams.Add("ForceSimplePrimMeshing", "false"); // ShouldForceSimplePrimMeshing | ||
83 | engineParams.Add("UseHullsForPhysicalObjects", "true"); // ShouldUseHullsForPhysicalObjects | ||
84 | engineParams.Add("ShouldRemoveZeroWidthTriangles", "true"); | ||
85 | engineParams.Add("ShouldUseBulletHACD", "false"); | ||
86 | engineParams.Add("ShouldUseSingleConvexHullForPrims", "true"); | ||
87 | engineParams.Add("ShouldUseGImpactShapeForPrims", "false"); | ||
88 | engineParams.Add("ShouldUseAssetHulls", "true"); | ||
89 | |||
90 | engineParams.Add("CSHullMaxDepthSplit", maxDepthSplit.ToString()); | ||
91 | engineParams.Add("CSHullMaxDepthSplitForSimpleShapes", maxDepthSplitForSimpleShapes.ToString()); | ||
92 | engineParams.Add("CSHullConcavityThresholdPercent", concavityThresholdPercent.ToString()); | ||
93 | engineParams.Add("CSHullVolumeConservationThresholdPercent", volumeConservationThresholdPercent.ToString()); | ||
94 | engineParams.Add("CSHullMaxVertices", maxVertices.ToString()); | ||
95 | engineParams.Add("CSHullMaxSkinWidth", maxSkinWidth.ToString()); | ||
96 | |||
97 | PhysicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams); | ||
98 | |||
99 | PrimitiveBaseShape pbs; | ||
100 | Vector3 pos; | ||
101 | Vector3 size; | ||
102 | Quaternion rot; | ||
103 | bool isPhys; | ||
104 | |||
105 | // Cylinder | ||
106 | pbs = PrimitiveBaseShape.CreateCylinder(); | ||
107 | pos = new Vector3(100.0f, 100.0f, 0f); | ||
108 | pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 10f; | ||
109 | ObjectInitPosition = pos; | ||
110 | size = new Vector3(2f, 2f, 2f); | ||
111 | pbs.Scale = size; | ||
112 | rot = Quaternion.Identity; | ||
113 | isPhys = true; | ||
114 | uint cylinderLocalID = 123; | ||
115 | PhysicsScene.AddPrimShape("testCylinder", pbs, pos, size, rot, isPhys, cylinderLocalID); | ||
116 | BSPrim primTypeCylinder = (BSPrim)PhysicsScene.PhysObjects[cylinderLocalID]; | ||
117 | |||
118 | // Hollow Cylinder | ||
119 | pbs = PrimitiveBaseShape.CreateCylinder(); | ||
120 | pbs.ProfileHollow = (ushort)(0.70f * 50000); | ||
121 | pos = new Vector3(110.0f, 110.0f, 0f); | ||
122 | pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 10f; | ||
123 | ObjectInitPosition = pos; | ||
124 | size = new Vector3(2f, 2f, 2f); | ||
125 | pbs.Scale = size; | ||
126 | rot = Quaternion.Identity; | ||
127 | isPhys = true; | ||
128 | uint hollowCylinderLocalID = 124; | ||
129 | PhysicsScene.AddPrimShape("testHollowCylinder", pbs, pos, size, rot, isPhys, hollowCylinderLocalID); | ||
130 | BSPrim primTypeHollowCylinder = (BSPrim)PhysicsScene.PhysObjects[hollowCylinderLocalID]; | ||
131 | |||
132 | // Torus | ||
133 | // ProfileCurve = Circle, PathCurve = Curve1 | ||
134 | pbs = PrimitiveBaseShape.CreateSphere(); | ||
135 | pbs.ProfileShape = (byte)ProfileShape.Circle; | ||
136 | pbs.PathCurve = (byte)Extrusion.Curve1; | ||
137 | pbs.PathScaleX = 100; // default hollow info as set in the viewer | ||
138 | pbs.PathScaleY = (int)(.25f / 0.01f) + 200; | ||
139 | pos = new Vector3(120.0f, 120.0f, 0f); | ||
140 | pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 10f; | ||
141 | ObjectInitPosition = pos; | ||
142 | size = new Vector3(2f, 4f, 4f); | ||
143 | pbs.Scale = size; | ||
144 | rot = Quaternion.Identity; | ||
145 | isPhys = true; | ||
146 | uint torusLocalID = 125; | ||
147 | PhysicsScene.AddPrimShape("testTorus", pbs, pos, size, rot, isPhys, torusLocalID); | ||
148 | BSPrim primTypeTorus = (BSPrim)PhysicsScene.PhysObjects[torusLocalID]; | ||
149 | |||
150 | // The actual prim shape creation happens at taint time | ||
151 | PhysicsScene.ProcessTaints(); | ||
152 | |||
153 | // Check out the created hull shapes and report their characteristics | ||
154 | ReportShapeGeom(primTypeCylinder); | ||
155 | ReportShapeGeom(primTypeHollowCylinder); | ||
156 | ReportShapeGeom(primTypeTorus); | ||
157 | } | ||
158 | |||
159 | [TestCase] | ||
160 | public void GeomHullBulletHACD() | ||
161 | { | ||
162 | // Cylinder | ||
163 | // Hollow Cylinder | ||
164 | // Torus | ||
165 | } | ||
166 | |||
167 | private void ReportShapeGeom(BSPrim prim) | ||
168 | { | ||
169 | if (prim != null) | ||
170 | { | ||
171 | if (prim.PhysShape.HasPhysicalShape) | ||
172 | { | ||
173 | BSShape physShape = prim.PhysShape; | ||
174 | string shapeType = physShape.GetType().ToString(); | ||
175 | switch (shapeType) | ||
176 | { | ||
177 | case "OpenSim.Region.Physics.BulletSPlugin.BSShapeNative": | ||
178 | BSShapeNative nShape = physShape as BSShapeNative; | ||
179 | prim.PhysScene.DetailLog("{0}, type={1}", prim.Name, shapeType); | ||
180 | break; | ||
181 | case "OpenSim.Region.Physics.BulletSPlugin.BSShapeMesh": | ||
182 | BSShapeMesh mShape = physShape as BSShapeMesh; | ||
183 | prim.PhysScene.DetailLog("{0}, mesh, shapeInfo={1}", prim.Name, mShape.shapeInfo); | ||
184 | break; | ||
185 | case "OpenSim.Region.Physics.BulletSPlugin.BSShapeHull": | ||
186 | // BSShapeHull hShape = physShape as BSShapeHull; | ||
187 | // prim.PhysScene.DetailLog("{0}, hull, shapeInfo={1}", prim.Name, hShape.shapeInfo); | ||
188 | break; | ||
189 | case "OpenSim.Region.Physics.BulletSPlugin.BSShapeConvexHull": | ||
190 | BSShapeConvexHull chShape = physShape as BSShapeConvexHull; | ||
191 | prim.PhysScene.DetailLog("{0}, convexHull, shapeInfo={1}", prim.Name, chShape.shapeInfo); | ||
192 | break; | ||
193 | case "OpenSim.Region.Physics.BulletSPlugin.BSShapeCompound": | ||
194 | BSShapeCompound cShape = physShape as BSShapeCompound; | ||
195 | prim.PhysScene.DetailLog("{0}, type={1}", prim.Name, shapeType); | ||
196 | break; | ||
197 | default: | ||
198 | prim.PhysScene.DetailLog("{0}, type={1}", prim.Name, shapeType); | ||
199 | break; | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | } | ||
205 | } \ No newline at end of file | ||