diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSParam.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 742 |
1 files changed, 742 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs new file mode 100755 index 0000000..2af8468 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | |||
@@ -0,0 +1,742 @@ | |||
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 copyrightD | ||
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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | |||
31 | using OpenSim.Region.Physics.Manager; | ||
32 | |||
33 | using OpenMetaverse; | ||
34 | using Nini.Config; | ||
35 | |||
36 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
37 | { | ||
38 | public static class BSParam | ||
39 | { | ||
40 | private static string LogHeader = "[BULLETSIM PARAMETERS]"; | ||
41 | |||
42 | // Level of Detail values kept as float because that's what the Meshmerizer wants | ||
43 | public static float MeshLOD { get; private set; } | ||
44 | public static float MeshCircularLOD { get; private set; } | ||
45 | public static float MeshMegaPrimLOD { get; private set; } | ||
46 | public static float MeshMegaPrimThreshold { get; private set; } | ||
47 | public static float SculptLOD { get; private set; } | ||
48 | |||
49 | public static int CrossingFailuresBeforeOutOfBounds { get; private set; } | ||
50 | public static float UpdateVelocityChangeThreshold { get; private set; } | ||
51 | |||
52 | public static float MinimumObjectMass { get; private set; } | ||
53 | public static float MaximumObjectMass { get; private set; } | ||
54 | public static float MaxLinearVelocity { get; private set; } | ||
55 | public static float MaxLinearVelocitySquared { get; private set; } | ||
56 | public static float MaxAngularVelocity { get; private set; } | ||
57 | public static float MaxAngularVelocitySquared { get; private set; } | ||
58 | public static float MaxAddForceMagnitude { get; private set; } | ||
59 | public static float MaxAddForceMagnitudeSquared { get; private set; } | ||
60 | public static float DensityScaleFactor { get; private set; } | ||
61 | |||
62 | public static float LinearDamping { get; private set; } | ||
63 | public static float AngularDamping { get; private set; } | ||
64 | public static float DeactivationTime { get; private set; } | ||
65 | public static float LinearSleepingThreshold { get; private set; } | ||
66 | public static float AngularSleepingThreshold { get; private set; } | ||
67 | public static float CcdMotionThreshold { get; private set; } | ||
68 | public static float CcdSweptSphereRadius { get; private set; } | ||
69 | public static float ContactProcessingThreshold { get; private set; } | ||
70 | |||
71 | public static bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed | ||
72 | public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes | ||
73 | public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects | ||
74 | public static bool ShouldRemoveZeroWidthTriangles { get; private set; } | ||
75 | |||
76 | public static float TerrainImplementation { get; private set; } | ||
77 | public static float TerrainFriction { get; private set; } | ||
78 | public static float TerrainHitFraction { get; private set; } | ||
79 | public static float TerrainRestitution { get; private set; } | ||
80 | public static float TerrainCollisionMargin { get; private set; } | ||
81 | |||
82 | public static float DefaultFriction { get; private set; } | ||
83 | public static float DefaultDensity { get; private set; } | ||
84 | public static float DefaultRestitution { get; private set; } | ||
85 | public static float CollisionMargin { get; private set; } | ||
86 | public static float Gravity { get; private set; } | ||
87 | |||
88 | // Physics Engine operation | ||
89 | public static float MaxPersistantManifoldPoolSize { get; private set; } | ||
90 | public static float MaxCollisionAlgorithmPoolSize { get; private set; } | ||
91 | public static bool ShouldDisableContactPoolDynamicAllocation { get; private set; } | ||
92 | public static bool ShouldForceUpdateAllAabbs { get; private set; } | ||
93 | public static bool ShouldRandomizeSolverOrder { get; private set; } | ||
94 | public static bool ShouldSplitSimulationIslands { get; private set; } | ||
95 | public static bool ShouldEnableFrictionCaching { get; private set; } | ||
96 | public static float NumberOfSolverIterations { get; private set; } | ||
97 | public static bool UseSingleSidedMeshes { get; private set; } | ||
98 | public static float GlobalContactBreakingThreshold { get; private set; } | ||
99 | |||
100 | // Avatar parameters | ||
101 | public static float AvatarFriction { get; private set; } | ||
102 | public static float AvatarStandingFriction { get; private set; } | ||
103 | public static float AvatarAlwaysRunFactor { get; private set; } | ||
104 | public static float AvatarDensity { get; private set; } | ||
105 | public static float AvatarRestitution { get; private set; } | ||
106 | public static float AvatarCapsuleWidth { get; private set; } | ||
107 | public static float AvatarCapsuleDepth { get; private set; } | ||
108 | public static float AvatarCapsuleHeight { get; private set; } | ||
109 | public static float AvatarContactProcessingThreshold { get; private set; } | ||
110 | public static float AvatarBelowGroundUpCorrectionMeters { get; private set; } | ||
111 | public static float AvatarStepHeight { get; private set; } | ||
112 | public static float AvatarStepApproachFactor { get; private set; } | ||
113 | public static float AvatarStepForceFactor { get; private set; } | ||
114 | |||
115 | // Vehicle parameters | ||
116 | public static float VehicleMaxLinearVelocity { get; private set; } | ||
117 | public static float VehicleMaxLinearVelocitySquared { get; private set; } | ||
118 | public static float VehicleMaxAngularVelocity { get; private set; } | ||
119 | public static float VehicleMaxAngularVelocitySq { get; private set; } | ||
120 | public static float VehicleAngularDamping { get; private set; } | ||
121 | public static float VehicleFriction { get; private set; } | ||
122 | public static float VehicleRestitution { get; private set; } | ||
123 | public static Vector3 VehicleLinearFactor { get; private set; } | ||
124 | public static Vector3 VehicleAngularFactor { get; private set; } | ||
125 | public static float VehicleGroundGravityFudge { get; private set; } | ||
126 | public static bool VehicleDebuggingEnabled { get; private set; } | ||
127 | |||
128 | // Linkset implementation parameters | ||
129 | public static float LinksetImplementation { get; private set; } | ||
130 | public static bool LinkConstraintUseFrameOffset { get; private set; } | ||
131 | public static bool LinkConstraintEnableTransMotor { get; private set; } | ||
132 | public static float LinkConstraintTransMotorMaxVel { get; private set; } | ||
133 | public static float LinkConstraintTransMotorMaxForce { get; private set; } | ||
134 | public static float LinkConstraintERP { get; private set; } | ||
135 | public static float LinkConstraintCFM { get; private set; } | ||
136 | public static float LinkConstraintSolverIterations { get; private set; } | ||
137 | |||
138 | public static float PID_D { get; private set; } // derivative | ||
139 | public static float PID_P { get; private set; } // proportional | ||
140 | |||
141 | // Various constants that come from that other virtual world that shall not be named. | ||
142 | public const float MinGravityZ = -1f; | ||
143 | public const float MaxGravityZ = 28f; | ||
144 | public const float MinFriction = 0f; | ||
145 | public const float MaxFriction = 255f; | ||
146 | public const float MinDensity = 0.01f; | ||
147 | public const float MaxDensity = 22587f; | ||
148 | public const float MinRestitution = 0f; | ||
149 | public const float MaxRestitution = 1f; | ||
150 | |||
151 | // ===================================================================================== | ||
152 | // ===================================================================================== | ||
153 | |||
154 | // Base parameter definition that gets and sets parameter values via a string | ||
155 | public abstract class ParameterDefnBase | ||
156 | { | ||
157 | public string name; // string name of the parameter | ||
158 | public string desc; // a short description of what the parameter means | ||
159 | public ParameterDefnBase(string pName, string pDesc) | ||
160 | { | ||
161 | name = pName; | ||
162 | desc = pDesc; | ||
163 | } | ||
164 | // Set the parameter value to the default | ||
165 | public abstract void AssignDefault(BSScene s); | ||
166 | // Get the value as a string | ||
167 | public abstract string GetValue(BSScene s); | ||
168 | // Set the value to this string value | ||
169 | public abstract void SetValue(BSScene s, string valAsString); | ||
170 | // set the value on a particular object (usually sets in physics engine) | ||
171 | public abstract void SetOnObject(BSScene s, BSPhysObject obj); | ||
172 | public abstract bool HasSetOnObject { get; } | ||
173 | } | ||
174 | |||
175 | // Specific parameter definition for a parameter of a specific type. | ||
176 | public delegate T PGetValue<T>(BSScene s); | ||
177 | public delegate void PSetValue<T>(BSScene s, T val); | ||
178 | public delegate void PSetOnObject<T>(BSScene scene, BSPhysObject obj); | ||
179 | public sealed class ParameterDefn<T> : ParameterDefnBase | ||
180 | { | ||
181 | T defaultValue; | ||
182 | PSetValue<T> setter; | ||
183 | PGetValue<T> getter; | ||
184 | PSetOnObject<T> objectSet; | ||
185 | public ParameterDefn(string pName, string pDesc, T pDefault, PGetValue<T> pGetter, PSetValue<T> pSetter) | ||
186 | : base(pName, pDesc) | ||
187 | { | ||
188 | defaultValue = pDefault; | ||
189 | setter = pSetter; | ||
190 | getter = pGetter; | ||
191 | objectSet = null; | ||
192 | } | ||
193 | public ParameterDefn(string pName, string pDesc, T pDefault, PGetValue<T> pGetter, PSetValue<T> pSetter, PSetOnObject<T> pObjSetter) | ||
194 | : base(pName, pDesc) | ||
195 | { | ||
196 | defaultValue = pDefault; | ||
197 | setter = pSetter; | ||
198 | getter = pGetter; | ||
199 | objectSet = pObjSetter; | ||
200 | } | ||
201 | public override void AssignDefault(BSScene s) | ||
202 | { | ||
203 | setter(s, defaultValue); | ||
204 | } | ||
205 | public override string GetValue(BSScene s) | ||
206 | { | ||
207 | return String.Format("{0}", getter(s)); | ||
208 | } | ||
209 | public override void SetValue(BSScene s, string valAsString) | ||
210 | { | ||
211 | // Get the generic type of the setter | ||
212 | Type genericType = setter.GetType().GetGenericArguments()[0]; | ||
213 | // Find the 'Parse' method on that type | ||
214 | System.Reflection.MethodInfo parser = null; | ||
215 | try | ||
216 | { | ||
217 | parser = genericType.GetMethod("Parse", new Type[] { typeof(String) } ); | ||
218 | } | ||
219 | catch (Exception e) | ||
220 | { | ||
221 | s.Logger.ErrorFormat("{0} Exception getting parser for type '{1}': {2}", LogHeader, genericType, e); | ||
222 | parser = null; | ||
223 | } | ||
224 | if (parser != null) | ||
225 | { | ||
226 | // Parse the input string | ||
227 | try | ||
228 | { | ||
229 | T setValue = (T)parser.Invoke(genericType, new Object[] { valAsString }); | ||
230 | setter(s, setValue); | ||
231 | // s.Logger.DebugFormat("{0} Parameter {1} = {2}", LogHeader, name, setValue); | ||
232 | } | ||
233 | catch | ||
234 | { | ||
235 | s.Logger.ErrorFormat("{0} Failed parsing parameter value '{1}' as type '{2}'", LogHeader, valAsString, genericType); | ||
236 | } | ||
237 | } | ||
238 | else | ||
239 | { | ||
240 | s.Logger.ErrorFormat("{0} Could not find parameter parser for type '{1}'", LogHeader, genericType); | ||
241 | } | ||
242 | } | ||
243 | public override bool HasSetOnObject | ||
244 | { | ||
245 | get { return objectSet != null; } | ||
246 | } | ||
247 | public override void SetOnObject(BSScene s, BSPhysObject obj) | ||
248 | { | ||
249 | if (objectSet != null) | ||
250 | objectSet(s, obj); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | // List of all of the externally visible parameters. | ||
255 | // For each parameter, this table maps a text name to getter and setters. | ||
256 | // To add a new externally referencable/settable parameter, add the paramter storage | ||
257 | // location somewhere in the program and make an entry in this table with the | ||
258 | // getters and setters. | ||
259 | // It is easiest to find an existing definition and copy it. | ||
260 | // | ||
261 | // A ParameterDefn<T>() takes the following parameters: | ||
262 | // -- the text name of the parameter. This is used for console input and ini file. | ||
263 | // -- a short text description of the parameter. This shows up in the console listing. | ||
264 | // -- a default value | ||
265 | // -- a delegate for getting the value | ||
266 | // -- a delegate for setting the value | ||
267 | // -- an optional delegate to update the value in the world. Most often used to | ||
268 | // push the new value to an in-world object. | ||
269 | // | ||
270 | // The single letter parameters for the delegates are: | ||
271 | // s = BSScene | ||
272 | // o = BSPhysObject | ||
273 | // v = value (appropriate type) | ||
274 | private static ParameterDefnBase[] ParameterDefinitions = | ||
275 | { | ||
276 | new ParameterDefn<bool>("MeshSculptedPrim", "Whether to create meshes for sculpties", | ||
277 | true, | ||
278 | (s) => { return ShouldMeshSculptedPrim; }, | ||
279 | (s,v) => { ShouldMeshSculptedPrim = v; } ), | ||
280 | new ParameterDefn<bool>("ForceSimplePrimMeshing", "If true, only use primitive meshes for objects", | ||
281 | false, | ||
282 | (s) => { return ShouldForceSimplePrimMeshing; }, | ||
283 | (s,v) => { ShouldForceSimplePrimMeshing = v; } ), | ||
284 | new ParameterDefn<bool>("UseHullsForPhysicalObjects", "If true, create hulls for physical objects", | ||
285 | true, | ||
286 | (s) => { return ShouldUseHullsForPhysicalObjects; }, | ||
287 | (s,v) => { ShouldUseHullsForPhysicalObjects = v; } ), | ||
288 | new ParameterDefn<bool>("ShouldRemoveZeroWidthTriangles", "If true, remove degenerate triangles from meshes", | ||
289 | true, | ||
290 | (s) => { return ShouldRemoveZeroWidthTriangles; }, | ||
291 | (s,v) => { ShouldRemoveZeroWidthTriangles = v; } ), | ||
292 | |||
293 | new ParameterDefn<int>("CrossingFailuresBeforeOutOfBounds", "How forgiving we are about getting into adjactent regions", | ||
294 | 5, | ||
295 | (s) => { return CrossingFailuresBeforeOutOfBounds; }, | ||
296 | (s,v) => { CrossingFailuresBeforeOutOfBounds = v; } ), | ||
297 | new ParameterDefn<float>("UpdateVelocityChangeThreshold", "Change in updated velocity required before reporting change to simulator", | ||
298 | 0.1f, | ||
299 | (s) => { return UpdateVelocityChangeThreshold; }, | ||
300 | (s,v) => { UpdateVelocityChangeThreshold = v; } ), | ||
301 | |||
302 | new ParameterDefn<float>("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)", | ||
303 | 32f, | ||
304 | (s) => { return MeshLOD; }, | ||
305 | (s,v) => { MeshLOD = v; } ), | ||
306 | new ParameterDefn<float>("MeshLevelOfDetailCircular", "Level of detail for prims with circular cuts or shapes", | ||
307 | 32f, | ||
308 | (s) => { return MeshCircularLOD; }, | ||
309 | (s,v) => { MeshCircularLOD = v; } ), | ||
310 | new ParameterDefn<float>("MeshLevelOfDetailMegaPrimThreshold", "Size (in meters) of a mesh before using MeshMegaPrimLOD", | ||
311 | 10f, | ||
312 | (s) => { return MeshMegaPrimThreshold; }, | ||
313 | (s,v) => { MeshMegaPrimThreshold = v; } ), | ||
314 | new ParameterDefn<float>("MeshLevelOfDetailMegaPrim", "Level of detail to render meshes larger than threshold meters", | ||
315 | 32f, | ||
316 | (s) => { return MeshMegaPrimLOD; }, | ||
317 | (s,v) => { MeshMegaPrimLOD = v; } ), | ||
318 | new ParameterDefn<float>("SculptLevelOfDetail", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)", | ||
319 | 32f, | ||
320 | (s) => { return SculptLOD; }, | ||
321 | (s,v) => { SculptLOD = v; } ), | ||
322 | |||
323 | new ParameterDefn<int>("MaxSubStep", "In simulation step, maximum number of substeps", | ||
324 | 10, | ||
325 | (s) => { return s.m_maxSubSteps; }, | ||
326 | (s,v) => { s.m_maxSubSteps = (int)v; } ), | ||
327 | new ParameterDefn<float>("FixedTimeStep", "In simulation step, seconds of one substep (1/60)", | ||
328 | 1f / 60f, | ||
329 | (s) => { return s.m_fixedTimeStep; }, | ||
330 | (s,v) => { s.m_fixedTimeStep = v; } ), | ||
331 | new ParameterDefn<float>("NominalFrameRate", "The base frame rate we claim", | ||
332 | 55f, | ||
333 | (s) => { return s.NominalFrameRate; }, | ||
334 | (s,v) => { s.NominalFrameRate = (int)v; } ), | ||
335 | new ParameterDefn<int>("MaxCollisionsPerFrame", "Max collisions returned at end of each frame", | ||
336 | 2048, | ||
337 | (s) => { return s.m_maxCollisionsPerFrame; }, | ||
338 | (s,v) => { s.m_maxCollisionsPerFrame = (int)v; } ), | ||
339 | new ParameterDefn<int>("MaxUpdatesPerFrame", "Max updates returned at end of each frame", | ||
340 | 8000, | ||
341 | (s) => { return s.m_maxUpdatesPerFrame; }, | ||
342 | (s,v) => { s.m_maxUpdatesPerFrame = (int)v; } ), | ||
343 | |||
344 | new ParameterDefn<float>("MinObjectMass", "Minimum object mass (0.0001)", | ||
345 | 0.0001f, | ||
346 | (s) => { return MinimumObjectMass; }, | ||
347 | (s,v) => { MinimumObjectMass = v; } ), | ||
348 | new ParameterDefn<float>("MaxObjectMass", "Maximum object mass (10000.01)", | ||
349 | 10000.01f, | ||
350 | (s) => { return MaximumObjectMass; }, | ||
351 | (s,v) => { MaximumObjectMass = v; } ), | ||
352 | new ParameterDefn<float>("MaxLinearVelocity", "Maximum velocity magnitude that can be assigned to an object", | ||
353 | 1000.0f, | ||
354 | (s) => { return MaxLinearVelocity; }, | ||
355 | (s,v) => { MaxLinearVelocity = v; MaxLinearVelocitySquared = v * v; } ), | ||
356 | new ParameterDefn<float>("MaxAngularVelocity", "Maximum rotational velocity magnitude that can be assigned to an object", | ||
357 | 1000.0f, | ||
358 | (s) => { return MaxAngularVelocity; }, | ||
359 | (s,v) => { MaxAngularVelocity = v; MaxAngularVelocitySquared = v * v; } ), | ||
360 | // LL documentation says thie number should be 20f for llApplyImpulse and 200f for llRezObject | ||
361 | new ParameterDefn<float>("MaxAddForceMagnitude", "Maximum force that can be applied by llApplyImpulse (SL says 20f)", | ||
362 | 20000.0f, | ||
363 | (s) => { return MaxAddForceMagnitude; }, | ||
364 | (s,v) => { MaxAddForceMagnitude = v; MaxAddForceMagnitudeSquared = v * v; } ), | ||
365 | // Density is passed around as 100kg/m3. This scales that to 1kg/m3. | ||
366 | new ParameterDefn<float>("DensityScaleFactor", "Conversion for simulator/viewer density (100kg/m3) to physical density (1kg/m3)", | ||
367 | 0.01f, | ||
368 | (s) => { return DensityScaleFactor; }, | ||
369 | (s,v) => { DensityScaleFactor = v; } ), | ||
370 | |||
371 | new ParameterDefn<float>("PID_D", "Derivitive factor for motion smoothing", | ||
372 | 2200f, | ||
373 | (s) => { return (float)PID_D; }, | ||
374 | (s,v) => { PID_D = v; } ), | ||
375 | new ParameterDefn<float>("PID_P", "Parameteric factor for motion smoothing", | ||
376 | 900f, | ||
377 | (s) => { return (float)PID_P; }, | ||
378 | (s,v) => { PID_P = v; } ), | ||
379 | |||
380 | new ParameterDefn<float>("DefaultFriction", "Friction factor used on new objects", | ||
381 | 0.2f, | ||
382 | (s) => { return DefaultFriction; }, | ||
383 | (s,v) => { DefaultFriction = v; s.UnmanagedParams[0].defaultFriction = v; } ), | ||
384 | new ParameterDefn<float>("DefaultDensity", "Density for new objects" , | ||
385 | 10.000006836f, // Aluminum g/cm3 | ||
386 | (s) => { return DefaultDensity; }, | ||
387 | (s,v) => { DefaultDensity = v; s.UnmanagedParams[0].defaultDensity = v; } ), | ||
388 | new ParameterDefn<float>("DefaultRestitution", "Bouncyness of an object" , | ||
389 | 0f, | ||
390 | (s) => { return DefaultRestitution; }, | ||
391 | (s,v) => { DefaultRestitution = v; s.UnmanagedParams[0].defaultRestitution = v; } ), | ||
392 | new ParameterDefn<float>("CollisionMargin", "Margin around objects before collisions are calculated (must be zero!)", | ||
393 | 0.04f, | ||
394 | (s) => { return CollisionMargin; }, | ||
395 | (s,v) => { CollisionMargin = v; s.UnmanagedParams[0].collisionMargin = v; } ), | ||
396 | new ParameterDefn<float>("Gravity", "Vertical force of gravity (negative means down)", | ||
397 | -9.80665f, | ||
398 | (s) => { return Gravity; }, | ||
399 | (s,v) => { Gravity = v; s.UnmanagedParams[0].gravity = v; }, | ||
400 | (s,o) => { s.PE.SetGravity(o.PhysBody, new Vector3(0f,0f,Gravity)); } ), | ||
401 | |||
402 | |||
403 | new ParameterDefn<float>("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)", | ||
404 | 0f, | ||
405 | (s) => { return LinearDamping; }, | ||
406 | (s,v) => { LinearDamping = v; }, | ||
407 | (s,o) => { s.PE.SetDamping(o.PhysBody, LinearDamping, AngularDamping); } ), | ||
408 | new ParameterDefn<float>("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)", | ||
409 | 0f, | ||
410 | (s) => { return AngularDamping; }, | ||
411 | (s,v) => { AngularDamping = v; }, | ||
412 | (s,o) => { s.PE.SetDamping(o.PhysBody, LinearDamping, AngularDamping); } ), | ||
413 | new ParameterDefn<float>("DeactivationTime", "Seconds before considering an object potentially static", | ||
414 | 0.2f, | ||
415 | (s) => { return DeactivationTime; }, | ||
416 | (s,v) => { DeactivationTime = v; }, | ||
417 | (s,o) => { s.PE.SetDeactivationTime(o.PhysBody, DeactivationTime); } ), | ||
418 | new ParameterDefn<float>("LinearSleepingThreshold", "Seconds to measure linear movement before considering static", | ||
419 | 0.8f, | ||
420 | (s) => { return LinearSleepingThreshold; }, | ||
421 | (s,v) => { LinearSleepingThreshold = v;}, | ||
422 | (s,o) => { s.PE.SetSleepingThresholds(o.PhysBody, LinearSleepingThreshold, AngularSleepingThreshold); } ), | ||
423 | new ParameterDefn<float>("AngularSleepingThreshold", "Seconds to measure angular movement before considering static", | ||
424 | 1.0f, | ||
425 | (s) => { return AngularSleepingThreshold; }, | ||
426 | (s,v) => { AngularSleepingThreshold = v;}, | ||
427 | (s,o) => { s.PE.SetSleepingThresholds(o.PhysBody, LinearSleepingThreshold, AngularSleepingThreshold); } ), | ||
428 | new ParameterDefn<float>("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" , | ||
429 | 0.0f, // set to zero to disable | ||
430 | (s) => { return CcdMotionThreshold; }, | ||
431 | (s,v) => { CcdMotionThreshold = v;}, | ||
432 | (s,o) => { s.PE.SetCcdMotionThreshold(o.PhysBody, CcdMotionThreshold); } ), | ||
433 | new ParameterDefn<float>("CcdSweptSphereRadius", "Continuious collision detection test radius" , | ||
434 | 0.2f, | ||
435 | (s) => { return CcdSweptSphereRadius; }, | ||
436 | (s,v) => { CcdSweptSphereRadius = v;}, | ||
437 | (s,o) => { s.PE.SetCcdSweptSphereRadius(o.PhysBody, CcdSweptSphereRadius); } ), | ||
438 | new ParameterDefn<float>("ContactProcessingThreshold", "Distance above which contacts can be discarded (0 means no discard)" , | ||
439 | 0.0f, | ||
440 | (s) => { return ContactProcessingThreshold; }, | ||
441 | (s,v) => { ContactProcessingThreshold = v;}, | ||
442 | (s,o) => { s.PE.SetContactProcessingThreshold(o.PhysBody, ContactProcessingThreshold); } ), | ||
443 | |||
444 | new ParameterDefn<float>("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)", | ||
445 | (float)BSTerrainPhys.TerrainImplementation.Mesh, | ||
446 | (s) => { return TerrainImplementation; }, | ||
447 | (s,v) => { TerrainImplementation = v; } ), | ||
448 | new ParameterDefn<float>("TerrainFriction", "Factor to reduce movement against terrain surface" , | ||
449 | 0.3f, | ||
450 | (s) => { return TerrainFriction; }, | ||
451 | (s,v) => { TerrainFriction = v; /* TODO: set on real terrain */} ), | ||
452 | new ParameterDefn<float>("TerrainHitFraction", "Distance to measure hit collisions" , | ||
453 | 0.8f, | ||
454 | (s) => { return TerrainHitFraction; }, | ||
455 | (s,v) => { TerrainHitFraction = v; /* TODO: set on real terrain */ } ), | ||
456 | new ParameterDefn<float>("TerrainRestitution", "Bouncyness" , | ||
457 | 0f, | ||
458 | (s) => { return TerrainRestitution; }, | ||
459 | (s,v) => { TerrainRestitution = v; /* TODO: set on real terrain */ } ), | ||
460 | new ParameterDefn<float>("TerrainCollisionMargin", "Margin where collision checking starts" , | ||
461 | 0.08f, | ||
462 | (s) => { return TerrainCollisionMargin; }, | ||
463 | (s,v) => { TerrainCollisionMargin = v; /* TODO: set on real terrain */ } ), | ||
464 | |||
465 | new ParameterDefn<float>("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.", | ||
466 | 0.2f, | ||
467 | (s) => { return AvatarFriction; }, | ||
468 | (s,v) => { AvatarFriction = v; } ), | ||
469 | new ParameterDefn<float>("AvatarStandingFriction", "Avatar friction when standing. Changed on avatar recreation.", | ||
470 | 0.95f, | ||
471 | (s) => { return AvatarStandingFriction; }, | ||
472 | (s,v) => { AvatarStandingFriction = v; } ), | ||
473 | new ParameterDefn<float>("AvatarAlwaysRunFactor", "Speed multiplier if avatar is set to always run", | ||
474 | 1.3f, | ||
475 | (s) => { return AvatarAlwaysRunFactor; }, | ||
476 | (s,v) => { AvatarAlwaysRunFactor = v; } ), | ||
477 | new ParameterDefn<float>("AvatarDensity", "Density of an avatar. Changed on avatar recreation.", | ||
478 | 3.5f, | ||
479 | (s) => { return AvatarDensity; }, | ||
480 | (s,v) => { AvatarDensity = v; } ), | ||
481 | new ParameterDefn<float>("AvatarRestitution", "Bouncyness. Changed on avatar recreation.", | ||
482 | 0f, | ||
483 | (s) => { return AvatarRestitution; }, | ||
484 | (s,v) => { AvatarRestitution = v; } ), | ||
485 | new ParameterDefn<float>("AvatarCapsuleWidth", "The distance between the sides of the avatar capsule", | ||
486 | 0.6f, | ||
487 | (s) => { return AvatarCapsuleWidth; }, | ||
488 | (s,v) => { AvatarCapsuleWidth = v; } ), | ||
489 | new ParameterDefn<float>("AvatarCapsuleDepth", "The distance between the front and back of the avatar capsule", | ||
490 | 0.45f, | ||
491 | (s) => { return AvatarCapsuleDepth; }, | ||
492 | (s,v) => { AvatarCapsuleDepth = v; } ), | ||
493 | new ParameterDefn<float>("AvatarCapsuleHeight", "Default height of space around avatar", | ||
494 | 1.5f, | ||
495 | (s) => { return AvatarCapsuleHeight; }, | ||
496 | (s,v) => { AvatarCapsuleHeight = v; } ), | ||
497 | new ParameterDefn<float>("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions", | ||
498 | 0.1f, | ||
499 | (s) => { return AvatarContactProcessingThreshold; }, | ||
500 | (s,v) => { AvatarContactProcessingThreshold = v; } ), | ||
501 | new ParameterDefn<float>("AvatarBelowGroundUpCorrectionMeters", "Meters to move avatar up if it seems to be below ground", | ||
502 | 1.0f, | ||
503 | (s) => { return AvatarBelowGroundUpCorrectionMeters; }, | ||
504 | (s,v) => { AvatarBelowGroundUpCorrectionMeters = v; } ), | ||
505 | new ParameterDefn<float>("AvatarStepHeight", "Height of a step obstacle to consider step correction", | ||
506 | 0.3f, | ||
507 | (s) => { return AvatarStepHeight; }, | ||
508 | (s,v) => { AvatarStepHeight = v; } ), | ||
509 | new ParameterDefn<float>("AvatarStepApproachFactor", "Factor to control angle of approach to step (0=straight on)", | ||
510 | 0.6f, | ||
511 | (s) => { return AvatarStepApproachFactor; }, | ||
512 | (s,v) => { AvatarStepApproachFactor = v; } ), | ||
513 | new ParameterDefn<float>("AvatarStepForceFactor", "Controls the amount of force up applied to step up onto a step", | ||
514 | 2.0f, | ||
515 | (s) => { return AvatarStepForceFactor; }, | ||
516 | (s,v) => { AvatarStepForceFactor = v; } ), | ||
517 | |||
518 | new ParameterDefn<float>("VehicleMaxLinearVelocity", "Maximum velocity magnitude that can be assigned to a vehicle", | ||
519 | 1000.0f, | ||
520 | (s) => { return (float)VehicleMaxLinearVelocity; }, | ||
521 | (s,v) => { VehicleMaxLinearVelocity = v; VehicleMaxLinearVelocitySquared = v * v; } ), | ||
522 | new ParameterDefn<float>("VehicleMaxAngularVelocity", "Maximum rotational velocity magnitude that can be assigned to a vehicle", | ||
523 | 12.0f, | ||
524 | (s) => { return (float)VehicleMaxAngularVelocity; }, | ||
525 | (s,v) => { VehicleMaxAngularVelocity = v; VehicleMaxAngularVelocitySq = v * v; } ), | ||
526 | new ParameterDefn<float>("VehicleAngularDamping", "Factor to damp vehicle angular movement per second (0.0 - 1.0)", | ||
527 | 0.0f, | ||
528 | (s) => { return VehicleAngularDamping; }, | ||
529 | (s,v) => { VehicleAngularDamping = v; } ), | ||
530 | new ParameterDefn<Vector3>("VehicleLinearFactor", "Fraction of physical linear changes applied to vehicle (<0,0,0> to <1,1,1>)", | ||
531 | new Vector3(1f, 1f, 1f), | ||
532 | (s) => { return VehicleLinearFactor; }, | ||
533 | (s,v) => { VehicleLinearFactor = v; } ), | ||
534 | new ParameterDefn<Vector3>("VehicleAngularFactor", "Fraction of physical angular changes applied to vehicle (<0,0,0> to <1,1,1>)", | ||
535 | new Vector3(1f, 1f, 1f), | ||
536 | (s) => { return VehicleAngularFactor; }, | ||
537 | (s,v) => { VehicleAngularFactor = v; } ), | ||
538 | new ParameterDefn<float>("VehicleFriction", "Friction of vehicle on the ground (0.0 - 1.0)", | ||
539 | 0.0f, | ||
540 | (s) => { return VehicleFriction; }, | ||
541 | (s,v) => { VehicleFriction = v; } ), | ||
542 | new ParameterDefn<float>("VehicleRestitution", "Bouncyness factor for vehicles (0.0 - 1.0)", | ||
543 | 0.0f, | ||
544 | (s) => { return VehicleRestitution; }, | ||
545 | (s,v) => { VehicleRestitution = v; } ), | ||
546 | new ParameterDefn<float>("VehicleGroundGravityFudge", "Factor to multiple gravity if a ground vehicle is probably on the ground (0.0 - 1.0)", | ||
547 | 0.2f, | ||
548 | (s) => { return VehicleGroundGravityFudge; }, | ||
549 | (s,v) => { VehicleGroundGravityFudge = v; } ), | ||
550 | new ParameterDefn<bool>("VehicleDebuggingEnable", "Turn on/off vehicle debugging", | ||
551 | false, | ||
552 | (s) => { return VehicleDebuggingEnabled; }, | ||
553 | (s,v) => { VehicleDebuggingEnabled = v; } ), | ||
554 | |||
555 | new ParameterDefn<float>("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)", | ||
556 | 0f, | ||
557 | (s) => { return MaxPersistantManifoldPoolSize; }, | ||
558 | (s,v) => { MaxPersistantManifoldPoolSize = v; s.UnmanagedParams[0].maxPersistantManifoldPoolSize = v; } ), | ||
559 | new ParameterDefn<float>("MaxCollisionAlgorithmPoolSize", "Number of collisions pooled (0 means default of 4096)", | ||
560 | 0f, | ||
561 | (s) => { return MaxCollisionAlgorithmPoolSize; }, | ||
562 | (s,v) => { MaxCollisionAlgorithmPoolSize = v; s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize = v; } ), | ||
563 | new ParameterDefn<bool>("ShouldDisableContactPoolDynamicAllocation", "Enable to allow large changes in object count", | ||
564 | false, | ||
565 | (s) => { return ShouldDisableContactPoolDynamicAllocation; }, | ||
566 | (s,v) => { ShouldDisableContactPoolDynamicAllocation = v; | ||
567 | s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation = NumericBool(v); } ), | ||
568 | new ParameterDefn<bool>("ShouldForceUpdateAllAabbs", "Enable to recomputer AABBs every simulator step", | ||
569 | false, | ||
570 | (s) => { return ShouldForceUpdateAllAabbs; }, | ||
571 | (s,v) => { ShouldForceUpdateAllAabbs = v; s.UnmanagedParams[0].shouldForceUpdateAllAabbs = NumericBool(v); } ), | ||
572 | new ParameterDefn<bool>("ShouldRandomizeSolverOrder", "Enable for slightly better stacking interaction", | ||
573 | true, | ||
574 | (s) => { return ShouldRandomizeSolverOrder; }, | ||
575 | (s,v) => { ShouldRandomizeSolverOrder = v; s.UnmanagedParams[0].shouldRandomizeSolverOrder = NumericBool(v); } ), | ||
576 | new ParameterDefn<bool>("ShouldSplitSimulationIslands", "Enable splitting active object scanning islands", | ||
577 | true, | ||
578 | (s) => { return ShouldSplitSimulationIslands; }, | ||
579 | (s,v) => { ShouldSplitSimulationIslands = v; s.UnmanagedParams[0].shouldSplitSimulationIslands = NumericBool(v); } ), | ||
580 | new ParameterDefn<bool>("ShouldEnableFrictionCaching", "Enable friction computation caching", | ||
581 | true, | ||
582 | (s) => { return ShouldEnableFrictionCaching; }, | ||
583 | (s,v) => { ShouldEnableFrictionCaching = v; s.UnmanagedParams[0].shouldEnableFrictionCaching = NumericBool(v); } ), | ||
584 | new ParameterDefn<float>("NumberOfSolverIterations", "Number of internal iterations (0 means default)", | ||
585 | 0f, // zero says use Bullet default | ||
586 | (s) => { return NumberOfSolverIterations; }, | ||
587 | (s,v) => { NumberOfSolverIterations = v; s.UnmanagedParams[0].numberOfSolverIterations = v; } ), | ||
588 | new ParameterDefn<bool>("UseSingleSidedMeshes", "Whether to compute collisions based on single sided meshes.", | ||
589 | true, | ||
590 | (s) => { return UseSingleSidedMeshes; }, | ||
591 | (s,v) => { UseSingleSidedMeshes = v; s.UnmanagedParams[0].useSingleSidedMeshes = NumericBool(v); } ), | ||
592 | new ParameterDefn<float>("GlobalContactBreakingThreshold", "Amount of shape radius before breaking a collision contact (0 says Bullet default (0.2))", | ||
593 | 0f, | ||
594 | (s) => { return GlobalContactBreakingThreshold; }, | ||
595 | (s,v) => { GlobalContactBreakingThreshold = v; s.UnmanagedParams[0].globalContactBreakingThreshold = v; } ), | ||
596 | |||
597 | new ParameterDefn<float>("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)", | ||
598 | (float)BSLinkset.LinksetImplementation.Compound, | ||
599 | (s) => { return LinksetImplementation; }, | ||
600 | (s,v) => { LinksetImplementation = v; } ), | ||
601 | new ParameterDefn<bool>("LinkConstraintUseFrameOffset", "For linksets built with constraints, enable frame offsetFor linksets built with constraints, enable frame offset.", | ||
602 | false, | ||
603 | (s) => { return LinkConstraintUseFrameOffset; }, | ||
604 | (s,v) => { LinkConstraintUseFrameOffset = v; } ), | ||
605 | new ParameterDefn<bool>("LinkConstraintEnableTransMotor", "Whether to enable translational motor on linkset constraints", | ||
606 | true, | ||
607 | (s) => { return LinkConstraintEnableTransMotor; }, | ||
608 | (s,v) => { LinkConstraintEnableTransMotor = v; } ), | ||
609 | new ParameterDefn<float>("LinkConstraintTransMotorMaxVel", "Maximum velocity to be applied by translational motor in linkset constraints", | ||
610 | 5.0f, | ||
611 | (s) => { return LinkConstraintTransMotorMaxVel; }, | ||
612 | (s,v) => { LinkConstraintTransMotorMaxVel = v; } ), | ||
613 | new ParameterDefn<float>("LinkConstraintTransMotorMaxForce", "Maximum force to be applied by translational motor in linkset constraints", | ||
614 | 0.1f, | ||
615 | (s) => { return LinkConstraintTransMotorMaxForce; }, | ||
616 | (s,v) => { LinkConstraintTransMotorMaxForce = v; } ), | ||
617 | new ParameterDefn<float>("LinkConstraintCFM", "Amount constraint can be violated. 0=no violation, 1=infinite. Default=0.1", | ||
618 | 0.1f, | ||
619 | (s) => { return LinkConstraintCFM; }, | ||
620 | (s,v) => { LinkConstraintCFM = v; } ), | ||
621 | new ParameterDefn<float>("LinkConstraintERP", "Amount constraint is corrected each tick. 0=none, 1=all. Default = 0.2", | ||
622 | 0.1f, | ||
623 | (s) => { return LinkConstraintERP; }, | ||
624 | (s,v) => { LinkConstraintERP = v; } ), | ||
625 | new ParameterDefn<float>("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)", | ||
626 | 40, | ||
627 | (s) => { return LinkConstraintSolverIterations; }, | ||
628 | (s,v) => { LinkConstraintSolverIterations = v; } ), | ||
629 | |||
630 | new ParameterDefn<int>("PhysicsMetricFrames", "Frames between outputting detailed phys metrics. (0 is off)", | ||
631 | 0, | ||
632 | (s) => { return s.PhysicsMetricDumpFrames; }, | ||
633 | (s,v) => { s.PhysicsMetricDumpFrames = v; } ), | ||
634 | new ParameterDefn<float>("ResetBroadphasePool", "Setting this is any value resets the broadphase collision pool", | ||
635 | 0f, | ||
636 | (s) => { return 0f; }, | ||
637 | (s,v) => { BSParam.ResetBroadphasePoolTainted(s, v); } ), | ||
638 | new ParameterDefn<float>("ResetConstraintSolver", "Setting this is any value resets the constraint solver", | ||
639 | 0f, | ||
640 | (s) => { return 0f; }, | ||
641 | (s,v) => { BSParam.ResetConstraintSolverTainted(s, v); } ), | ||
642 | }; | ||
643 | |||
644 | // Convert a boolean to our numeric true and false values | ||
645 | public static float NumericBool(bool b) | ||
646 | { | ||
647 | return (b ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse); | ||
648 | } | ||
649 | |||
650 | // Convert numeric true and false values to a boolean | ||
651 | public static bool BoolNumeric(float b) | ||
652 | { | ||
653 | return (b == ConfigurationParameters.numericTrue ? true : false); | ||
654 | } | ||
655 | |||
656 | // Search through the parameter definitions and return the matching | ||
657 | // ParameterDefn structure. | ||
658 | // Case does not matter as names are compared after converting to lower case. | ||
659 | // Returns 'false' if the parameter is not found. | ||
660 | internal static bool TryGetParameter(string paramName, out ParameterDefnBase defn) | ||
661 | { | ||
662 | bool ret = false; | ||
663 | ParameterDefnBase foundDefn = null; | ||
664 | string pName = paramName.ToLower(); | ||
665 | |||
666 | foreach (ParameterDefnBase parm in ParameterDefinitions) | ||
667 | { | ||
668 | if (pName == parm.name.ToLower()) | ||
669 | { | ||
670 | foundDefn = parm; | ||
671 | ret = true; | ||
672 | break; | ||
673 | } | ||
674 | } | ||
675 | defn = foundDefn; | ||
676 | return ret; | ||
677 | } | ||
678 | |||
679 | // Pass through the settable parameters and set the default values | ||
680 | internal static void SetParameterDefaultValues(BSScene physicsScene) | ||
681 | { | ||
682 | foreach (ParameterDefnBase parm in ParameterDefinitions) | ||
683 | { | ||
684 | parm.AssignDefault(physicsScene); | ||
685 | } | ||
686 | } | ||
687 | |||
688 | // Get user set values out of the ini file. | ||
689 | internal static void SetParameterConfigurationValues(BSScene physicsScene, IConfig cfg) | ||
690 | { | ||
691 | foreach (ParameterDefnBase parm in ParameterDefinitions) | ||
692 | { | ||
693 | parm.SetValue(physicsScene, cfg.GetString(parm.name, parm.GetValue(physicsScene))); | ||
694 | } | ||
695 | } | ||
696 | |||
697 | internal static PhysParameterEntry[] SettableParameters = new PhysParameterEntry[1]; | ||
698 | |||
699 | // This creates an array in the correct format for returning the list of | ||
700 | // parameters. This is used by the 'list' option of the 'physics' command. | ||
701 | internal static void BuildParameterTable() | ||
702 | { | ||
703 | if (SettableParameters.Length < ParameterDefinitions.Length) | ||
704 | { | ||
705 | List<PhysParameterEntry> entries = new List<PhysParameterEntry>(); | ||
706 | for (int ii = 0; ii < ParameterDefinitions.Length; ii++) | ||
707 | { | ||
708 | ParameterDefnBase pd = ParameterDefinitions[ii]; | ||
709 | entries.Add(new PhysParameterEntry(pd.name, pd.desc)); | ||
710 | } | ||
711 | |||
712 | // make the list alphabetical for ease of finding anything | ||
713 | entries.Sort((ppe1, ppe2) => { return ppe1.name.CompareTo(ppe2.name); }); | ||
714 | |||
715 | SettableParameters = entries.ToArray(); | ||
716 | } | ||
717 | } | ||
718 | |||
719 | // ===================================================================== | ||
720 | // ===================================================================== | ||
721 | // There are parameters that, when set, cause things to happen in the physics engine. | ||
722 | // This causes the broadphase collision cache to be cleared. | ||
723 | private static void ResetBroadphasePoolTainted(BSScene pPhysScene, float v) | ||
724 | { | ||
725 | BSScene physScene = pPhysScene; | ||
726 | physScene.TaintedObject("BSParam.ResetBroadphasePoolTainted", delegate() | ||
727 | { | ||
728 | physScene.PE.ResetBroadphasePool(physScene.World); | ||
729 | }); | ||
730 | } | ||
731 | |||
732 | // This causes the constraint solver cache to be cleared and reset. | ||
733 | private static void ResetConstraintSolverTainted(BSScene pPhysScene, float v) | ||
734 | { | ||
735 | BSScene physScene = pPhysScene; | ||
736 | physScene.TaintedObject("BSParam.ResetConstraintSolver", delegate() | ||
737 | { | ||
738 | physScene.PE.ResetConstraintSolver(physScene.World); | ||
739 | }); | ||
740 | } | ||
741 | } | ||
742 | } | ||