diff options
author | Robert Adams | 2011-08-18 14:32:09 -0700 |
---|---|---|
committer | Mic Bowman | 2011-08-18 14:32:09 -0700 |
commit | fef73a1a1011126d4df2da2279caae9cef7984d1 (patch) | |
tree | af54473f37f419648b98c4b8ddc815ff7aea98a3 /OpenSim/Region/OptionalModules | |
parent | BulletSim: fix problem with not convex hulling large objects by creating unit... (diff) | |
download | opensim-SC-fef73a1a1011126d4df2da2279caae9cef7984d1.zip opensim-SC-fef73a1a1011126d4df2da2279caae9cef7984d1.tar.gz opensim-SC-fef73a1a1011126d4df2da2279caae9cef7984d1.tar.bz2 opensim-SC-fef73a1a1011126d4df2da2279caae9cef7984d1.tar.xz |
BulletSim: add runtime setting of physics parameters. Update default values.
Diffstat (limited to 'OpenSim/Region/OptionalModules')
-rwxr-xr-x | OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs | 277 |
1 files changed, 277 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs b/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs new file mode 100755 index 0000000..2a44360 --- /dev/null +++ b/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs | |||
@@ -0,0 +1,277 @@ | |||
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.Reflection; | ||
30 | using System.Collections.Generic; | ||
31 | using log4net; | ||
32 | using Mono.Addins; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Console; | ||
36 | using OpenSim.Region.CoreModules.Framework.InterfaceCommander; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Region.Physics.Manager; | ||
40 | |||
41 | namespace OpenSim.Region.OptionalModules.PhysicsParameters | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// </summary> | ||
45 | /// <remarks> | ||
46 | /// </remarks> | ||
47 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "PhysicsParameters")] | ||
48 | public class PhysicsParameters : ISharedRegionModule | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | private static string LogHeader = "[PHYSICS PARAMETERS]"; | ||
52 | |||
53 | private List<Scene> m_scenes = new List<Scene>(); | ||
54 | private static bool m_commandsLoaded = false; | ||
55 | |||
56 | #region ISharedRegionModule | ||
57 | public string Name { get { return "Runtime Physics Parameter Module"; } } | ||
58 | |||
59 | public Type ReplaceableInterface { get { return null; } } | ||
60 | |||
61 | public void Initialise(IConfigSource source) | ||
62 | { | ||
63 | // m_log.DebugFormat("{0}: INITIALIZED MODULE", LogHeader); | ||
64 | } | ||
65 | |||
66 | public void PostInitialise() | ||
67 | { | ||
68 | // m_log.DebugFormat("[{0}: POST INITIALIZED MODULE", LogHeader); | ||
69 | InstallInterfaces(); | ||
70 | } | ||
71 | |||
72 | public void Close() | ||
73 | { | ||
74 | // m_log.DebugFormat("{0}: CLOSED MODULE", LogHeader); | ||
75 | } | ||
76 | |||
77 | public void AddRegion(Scene scene) | ||
78 | { | ||
79 | // m_log.DebugFormat("{0}: REGION {1} ADDED", LogHeader, scene.RegionInfo.RegionName); | ||
80 | m_scenes.Add(scene); | ||
81 | } | ||
82 | |||
83 | public void RemoveRegion(Scene scene) | ||
84 | { | ||
85 | // m_log.DebugFormat("{0}: REGION {1} REMOVED", LogHeader, scene.RegionInfo.RegionName); | ||
86 | if (m_scenes.Contains(scene)) | ||
87 | m_scenes.Remove(scene); | ||
88 | } | ||
89 | |||
90 | public void RegionLoaded(Scene scene) | ||
91 | { | ||
92 | // m_log.DebugFormat("{0}: REGION {1} LOADED", LogHeader, scene.RegionInfo.RegionName); | ||
93 | } | ||
94 | #endregion INonSharedRegionModule | ||
95 | |||
96 | private const string getInvocation = "physics get [<param>|ALL]"; | ||
97 | private const string setInvocation = "physics set <param> [<value>|TRUE|FALSE] [localID|ALL]"; | ||
98 | private const string listInvocation = "physics list"; | ||
99 | private void InstallInterfaces() | ||
100 | { | ||
101 | if (!m_commandsLoaded) | ||
102 | { | ||
103 | MainConsole.Instance.Commands.AddCommand("Physics", false, "physics set", | ||
104 | "physics set", | ||
105 | "Set physics parameter from currently selected region" + Environment.NewLine | ||
106 | + "Invocation: " + setInvocation, | ||
107 | ProcessPhysicsSet); | ||
108 | |||
109 | MainConsole.Instance.Commands.AddCommand("Physics", false, "physics get", | ||
110 | "physics get", | ||
111 | "Get physics parameter from currently selected region" + Environment.NewLine | ||
112 | + "Invocation: " + getInvocation, | ||
113 | ProcessPhysicsGet); | ||
114 | |||
115 | MainConsole.Instance.Commands.AddCommand("Physics", false, "physics list", | ||
116 | "physics list", | ||
117 | "List settable physics parameters" + Environment.NewLine | ||
118 | + "Invocation: " + listInvocation, | ||
119 | ProcessPhysicsList); | ||
120 | |||
121 | m_commandsLoaded = true; | ||
122 | } | ||
123 | } | ||
124 | |||
125 | // TODO: extend get so you can get a value from an individual localID | ||
126 | private void ProcessPhysicsGet(string module, string[] cmdparms) | ||
127 | { | ||
128 | if (cmdparms.Length != 3) | ||
129 | { | ||
130 | WriteError("Parameter count error. Invocation: " + getInvocation); | ||
131 | return; | ||
132 | } | ||
133 | string parm = cmdparms[2]; | ||
134 | |||
135 | if (SceneManager.Instance == null || SceneManager.Instance.CurrentScene == null) | ||
136 | { | ||
137 | WriteError("Error: no region selected. Use 'change region' to select a region."); | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | Scene scene = SceneManager.Instance.CurrentScene; | ||
142 | IPhysicsParameters physScene = scene.PhysicsScene as IPhysicsParameters; | ||
143 | if (physScene != null) | ||
144 | { | ||
145 | if (parm.ToLower() == "all") | ||
146 | { | ||
147 | foreach (PhysParameterEntry ppe in physScene.GetParameterList()) | ||
148 | { | ||
149 | float val = 0.0f; | ||
150 | if (physScene.GetPhysicsParameter(ppe.name, out val)) | ||
151 | { | ||
152 | WriteOut(" {0}/{1} = {2}", scene.RegionInfo.RegionName, ppe.name, val); | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | WriteOut(" {0}/{1} = {2}", scene.RegionInfo.RegionName, ppe.name, "unknown"); | ||
157 | } | ||
158 | } | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | float val = 0.0f; | ||
163 | if (physScene.GetPhysicsParameter(parm, out val)) | ||
164 | { | ||
165 | WriteOut(" {0}/{1} = {2}", scene.RegionInfo.RegionName, parm, val); | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | WriteError("Failed fetch of parameter '{0}' from region '{1}'", parm, scene.RegionInfo.RegionName); | ||
170 | } | ||
171 | } | ||
172 | } | ||
173 | else | ||
174 | { | ||
175 | WriteError("Region '{0}' physics engine has no gettable physics parameters", scene.RegionInfo.RegionName); | ||
176 | } | ||
177 | return; | ||
178 | } | ||
179 | |||
180 | private void ProcessPhysicsSet(string module, string[] cmdparms) | ||
181 | { | ||
182 | if (cmdparms.Length < 4 || cmdparms.Length > 5) | ||
183 | { | ||
184 | WriteError("Parameter count error. Invocation: " + getInvocation); | ||
185 | return; | ||
186 | } | ||
187 | string parm = "xxx"; | ||
188 | float val = 0f; | ||
189 | uint localID = (uint)PhysParameterEntry.APPLY_TO_NONE; // set default value | ||
190 | try | ||
191 | { | ||
192 | parm = cmdparms[2]; | ||
193 | string valparm = cmdparms[3].ToLower(); | ||
194 | if (valparm == "true") | ||
195 | val = PhysParameterEntry.NUMERIC_TRUE; | ||
196 | else | ||
197 | { | ||
198 | if (valparm == "false") | ||
199 | val = PhysParameterEntry.NUMERIC_FALSE; | ||
200 | else | ||
201 | val = float.Parse(valparm, Culture.NumberFormatInfo); | ||
202 | } | ||
203 | if (cmdparms.Length > 4) | ||
204 | { | ||
205 | if (cmdparms[4].ToLower() == "all") | ||
206 | localID = (uint)PhysParameterEntry.APPLY_TO_ALL; | ||
207 | else | ||
208 | localID = uint.Parse(cmdparms[2], Culture.NumberFormatInfo); | ||
209 | } | ||
210 | } | ||
211 | catch | ||
212 | { | ||
213 | WriteError(" Error parsing parameters. Invocation: " + setInvocation); | ||
214 | return; | ||
215 | } | ||
216 | |||
217 | if (SceneManager.Instance == null || SceneManager.Instance.CurrentScene == null) | ||
218 | { | ||
219 | WriteError("Error: no region selected. Use 'change region' to select a region."); | ||
220 | return; | ||
221 | } | ||
222 | |||
223 | Scene scene = SceneManager.Instance.CurrentScene; | ||
224 | IPhysicsParameters physScene = scene.PhysicsScene as IPhysicsParameters; | ||
225 | if (physScene != null) | ||
226 | { | ||
227 | if (!physScene.SetPhysicsParameter(parm, val, localID)) | ||
228 | { | ||
229 | WriteError("Failed set of parameter '{0}' for region '{1}'", parm, scene.RegionInfo.RegionName); | ||
230 | } | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | WriteOut("Region '{0}'s physics engine has no settable physics parameters", scene.RegionInfo.RegionName); | ||
235 | } | ||
236 | return; | ||
237 | } | ||
238 | |||
239 | private void ProcessPhysicsList(string module, string[] cmdparms) | ||
240 | { | ||
241 | if (SceneManager.Instance == null || SceneManager.Instance.CurrentScene == null) | ||
242 | { | ||
243 | WriteError("Error: no region selected. Use 'change region' to select a region."); | ||
244 | return; | ||
245 | } | ||
246 | Scene scene = SceneManager.Instance.CurrentScene; | ||
247 | |||
248 | IPhysicsParameters physScene = scene.PhysicsScene as IPhysicsParameters; | ||
249 | if (physScene != null) | ||
250 | { | ||
251 | WriteOut("Available physics parameters:"); | ||
252 | PhysParameterEntry[] parms = physScene.GetParameterList(); | ||
253 | foreach (PhysParameterEntry ent in parms) | ||
254 | { | ||
255 | WriteOut(" {0}: {1}", ent.name, ent.desc); | ||
256 | } | ||
257 | } | ||
258 | else | ||
259 | { | ||
260 | WriteError("Current regions's physics engine has no settable physics parameters"); | ||
261 | } | ||
262 | return; | ||
263 | } | ||
264 | |||
265 | private void WriteOut(string msg, params object[] args) | ||
266 | { | ||
267 | m_log.InfoFormat(msg, args); | ||
268 | // MainConsole.Instance.OutputFormat(msg, args); | ||
269 | } | ||
270 | |||
271 | private void WriteError(string msg, params object[] args) | ||
272 | { | ||
273 | m_log.ErrorFormat(msg, args); | ||
274 | // MainConsole.Instance.OutputFormat(msg, args); | ||
275 | } | ||
276 | } | ||
277 | } \ No newline at end of file | ||