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