diff options
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/PhysicsModules/BulletS/Tests/BasicVehicles.cs | 156 | ||||
-rwxr-xr-x[-rw-r--r--] | OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTests.cs (renamed from OpenSim/Framework/Communications/XMPP/XmppWriter.cs) | 113 | ||||
-rwxr-xr-x | OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTestsUtil.cs | 109 | ||||
-rw-r--r-- | OpenSim/Region/PhysicsModules/BulletS/Tests/HullCreation.cs | 205 |
4 files changed, 526 insertions, 57 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..35eba29 --- /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.PhysicsModule.BulletS; | ||
38 | using OpenSim.Region.PhysicsModules.SharedBase; | ||
39 | using OpenSim.Tests.Common; | ||
40 | |||
41 | using OpenMetaverse; | ||
42 | |||
43 | namespace OpenSim.Region.PhysicsModule.BulletS.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/Framework/Communications/XMPP/XmppWriter.cs b/OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTests.cs index 415d808..0be1f4c 100644..100755 --- a/OpenSim/Framework/Communications/XMPP/XmppWriter.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTests.cs | |||
@@ -1,57 +1,56 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSimulator Project nor the | 12 | * * Neither the name of the OpenSimulator Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System.IO; | 28 | using System; |
29 | using System.Text; | 29 | using System.Collections.Generic; |
30 | using System.Xml; | 30 | using System.Linq; |
31 | using IOStream = System.IO.Stream; | 31 | using System.Text; |
32 | 32 | ||
33 | namespace OpenSim.Framework.Communications.XMPP | 33 | using NUnit.Framework; |
34 | { | 34 | using log4net; |
35 | public class XMPPWriter: XmlTextWriter | 35 | |
36 | { | 36 | using OpenSim.Tests.Common; |
37 | public XMPPWriter(TextWriter textWriter) : base(textWriter) | 37 | |
38 | { | 38 | namespace OpenSim.Region.PhysicsModule.BulletS.Tests |
39 | } | 39 | { |
40 | 40 | [TestFixture] | |
41 | public XMPPWriter(IOStream stream) : this(stream, Util.UTF8) | 41 | public class BulletSimTests : OpenSimTestCase |
42 | { | 42 | { |
43 | } | 43 | // Documentation on attributes: http://www.nunit.org/index.php?p=attributes&r=2.6.1 |
44 | 44 | // Documentation on assertions: http://www.nunit.org/index.php?p=assertions&r=2.6.1 | |
45 | public XMPPWriter(IOStream stream, Encoding enc) : base(stream, enc) | 45 | |
46 | { | 46 | [TestFixtureSetUp] |
47 | } | 47 | public void Init() |
48 | 48 | { | |
49 | public override void WriteStartDocument() | 49 | } |
50 | { | 50 | |
51 | } | 51 | [TestFixtureTearDown] |
52 | 52 | public void TearDown() | |
53 | public override void WriteStartDocument(bool standalone) | 53 | { |
54 | { | 54 | } |
55 | } | 55 | } |
56 | } | 56 | } |
57 | } | ||
diff --git a/OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTestsUtil.cs b/OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTestsUtil.cs new file mode 100755 index 0000000..4eeea4d --- /dev/null +++ b/OpenSim/Region/PhysicsModules/BulletS/Tests/BulletSimTestsUtil.cs | |||
@@ -0,0 +1,109 @@ | |||
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.PhysicsModules.SharedBase; | ||
37 | using OpenSim.Region.PhysicsModules.Meshing; | ||
38 | using OpenSim.Region.Framework.Interfaces; | ||
39 | |||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace OpenSim.Region.PhysicsModule.BulletS.Tests | ||
43 | { | ||
44 | // Utility functions for building up and tearing down the sample physics environments | ||
45 | public static class BulletSimTestsUtil | ||
46 | { | ||
47 | // 'engineName' is the Bullet engine to use. Either null (for unmanaged), "BulletUnmanaged" or "BulletXNA" | ||
48 | // 'params' is a set of keyValue pairs to set in the engine's configuration file (override defaults) | ||
49 | // May be 'null' if there are no overrides. | ||
50 | public static BSScene CreateBasicPhysicsEngine(Dictionary<string,string> paramOverrides) | ||
51 | { | ||
52 | IConfigSource openSimINI = new IniConfigSource(); | ||
53 | IConfig startupConfig = openSimINI.AddConfig("Startup"); | ||
54 | startupConfig.Set("physics", "BulletSim"); | ||
55 | startupConfig.Set("meshing", "Meshmerizer"); | ||
56 | startupConfig.Set("cacheSculptMaps", "false"); // meshmerizer shouldn't save maps | ||
57 | |||
58 | IConfig bulletSimConfig = openSimINI.AddConfig("BulletSim"); | ||
59 | // If the caller cares, specify the bullet engine otherwise it will default to "BulletUnmanaged". | ||
60 | // bulletSimConfig.Set("BulletEngine", "BulletUnmanaged"); | ||
61 | // bulletSimConfig.Set("BulletEngine", "BulletXNA"); | ||
62 | bulletSimConfig.Set("MeshSculptedPrim", "false"); | ||
63 | bulletSimConfig.Set("ForceSimplePrimMeshing", "true"); | ||
64 | if (paramOverrides != null) | ||
65 | { | ||
66 | foreach (KeyValuePair<string, string> kvp in paramOverrides) | ||
67 | { | ||
68 | bulletSimConfig.Set(kvp.Key, kvp.Value); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | // If a special directory exists, put detailed logging therein. | ||
73 | // This allows local testing/debugging without having to worry that the build engine will output logs. | ||
74 | if (Directory.Exists("physlogs")) | ||
75 | { | ||
76 | bulletSimConfig.Set("PhysicsLoggingDir","./physlogs"); | ||
77 | bulletSimConfig.Set("PhysicsLoggingEnabled","True"); | ||
78 | bulletSimConfig.Set("PhysicsLoggingDoFlush","True"); | ||
79 | bulletSimConfig.Set("VehicleLoggingEnabled","True"); | ||
80 | } | ||
81 | |||
82 | Vector3 regionExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); | ||
83 | |||
84 | RegionInfo info = new RegionInfo(); | ||
85 | info.RegionName = "BSTestRegion"; | ||
86 | info.RegionSizeX = info.RegionSizeY = info.RegionSizeZ = Constants.RegionSize; | ||
87 | OpenSim.Region.Framework.Scenes.Scene scene = new OpenSim.Region.Framework.Scenes.Scene(info); | ||
88 | |||
89 | IMesher mesher = new OpenSim.Region.PhysicsModules.Meshing.Meshmerizer(); | ||
90 | INonSharedRegionModule mod = mesher as INonSharedRegionModule; | ||
91 | mod.Initialise(openSimINI); | ||
92 | mod.AddRegion(scene); | ||
93 | mod.RegionLoaded(scene); | ||
94 | |||
95 | BSScene pScene = new BSScene(); | ||
96 | mod = (pScene as INonSharedRegionModule); | ||
97 | mod.Initialise(openSimINI); | ||
98 | mod.AddRegion(scene); | ||
99 | mod.RegionLoaded(scene); | ||
100 | |||
101 | // Since the asset requestor is not initialized, any mesh or sculptie will be a cube. | ||
102 | // In the future, add a fake asset fetcher to get meshes and sculpts. | ||
103 | // bsScene.RequestAssetMethod = ???; | ||
104 | |||
105 | return pScene; | ||
106 | } | ||
107 | |||
108 | } | ||
109 | } | ||
diff --git a/OpenSim/Region/PhysicsModules/BulletS/Tests/HullCreation.cs b/OpenSim/Region/PhysicsModules/BulletS/Tests/HullCreation.cs new file mode 100644 index 0000000..c0cf19a --- /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.PhysicsModule.BulletS; | ||
38 | using OpenSim.Region.PhysicsModules.SharedBase; | ||
39 | using OpenSim.Tests.Common; | ||
40 | |||
41 | using OpenMetaverse; | ||
42 | |||
43 | namespace OpenSim.Region.PhysicsModule.BulletS.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 | ||