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