OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
BSParam.cs
Go to the documentation of this file.
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.Reflection;
30 using System.Text;
31 
32 using OpenSim.Region.PhysicsModules.SharedBase;
33 
34 using OpenMetaverse;
35 using Nini.Config;
36 
37 namespace OpenSim.Region.PhysicsModule.BulletS
38 {
39 public static class BSParam
40 {
41  private static string LogHeader = "[BULLETSIM PARAMETERS]";
42 
43  // Tuning notes:
44  // From: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=6575
45  // Contact points can be added even if the distance is positive. The constraint solver can deal with
46  // contacts with positive distances as well as negative (penetration). Contact points are discarded
47  // if the distance exceeds a certain threshold.
48  // Bullet has a contact processing threshold and a contact breaking threshold.
49  // If the distance is larger than the contact breaking threshold, it will be removed after one frame.
50  // If the distance is larger than the contact processing threshold, the constraint solver will ignore it.
51 
52  // This is separate/independent from the collision margin. The collision margin increases the object a bit
53  // to improve collision detection performance and accuracy.
54  // ===================
55  // From:
56 
63  public static bool Active { get; private set; }
64 
65  public static bool UseSeparatePhysicsThread { get; private set; }
66  public static float PhysicsTimeStep { get; private set; }
67 
68  // Level of Detail values kept as float because that's what the Meshmerizer wants
69  public static float MeshLOD { get; private set; }
70  public static float MeshCircularLOD { get; private set; }
71  public static float MeshMegaPrimLOD { get; private set; }
72  public static float MeshMegaPrimThreshold { get; private set; }
73  public static float SculptLOD { get; private set; }
74 
75  public static int CrossingFailuresBeforeOutOfBounds { get; private set; }
76  public static float UpdateVelocityChangeThreshold { get; private set; }
77 
78  public static float MinimumObjectMass { get; private set; }
79  public static float MaximumObjectMass { get; private set; }
80  public static float MaxLinearVelocity { get; private set; }
81  public static float MaxLinearVelocitySquared { get; private set; }
82  public static float MaxAngularVelocity { get; private set; }
83  public static float MaxAngularVelocitySquared { get; private set; }
84  public static float MaxAddForceMagnitude { get; private set; }
85  public static float MaxAddForceMagnitudeSquared { get; private set; }
86  public static float DensityScaleFactor { get; private set; }
87 
88  public static float LinearDamping { get; private set; }
89  public static float AngularDamping { get; private set; }
90  public static float DeactivationTime { get; private set; }
91  public static float LinearSleepingThreshold { get; private set; }
92  public static float AngularSleepingThreshold { get; private set; }
93  public static float CcdMotionThreshold { get; private set; }
94  public static float CcdSweptSphereRadius { get; private set; }
95  public static float ContactProcessingThreshold { get; private set; }
96 
97  public static bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed
98  public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes
99  public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects
100  public static bool ShouldRemoveZeroWidthTriangles { get; private set; }
101  public static bool ShouldUseBulletHACD { get; set; }
102  public static bool ShouldUseSingleConvexHullForPrims { get; set; }
103  public static bool ShouldUseGImpactShapeForPrims { get; set; }
104  public static bool ShouldUseAssetHulls { get; set; }
105 
106  public static float TerrainImplementation { get; set; }
107  public static int TerrainMeshMagnification { get; private set; }
108  public static float TerrainGroundPlane { get; private set; }
109  public static float TerrainFriction { get; private set; }
110  public static float TerrainHitFraction { get; private set; }
111  public static float TerrainRestitution { get; private set; }
112  public static float TerrainContactProcessingThreshold { get; private set; }
113  public static float TerrainCollisionMargin { get; private set; }
114 
115  public static float DefaultFriction { get; private set; }
116  public static float DefaultDensity { get; private set; }
117  public static float DefaultRestitution { get; private set; }
118  public static float CollisionMargin { get; private set; }
119  public static float Gravity { get; private set; }
120 
121  // Physics Engine operation
122  public static float MaxPersistantManifoldPoolSize { get; private set; }
123  public static float MaxCollisionAlgorithmPoolSize { get; private set; }
124  public static bool ShouldDisableContactPoolDynamicAllocation { get; private set; }
125  public static bool ShouldForceUpdateAllAabbs { get; private set; }
126  public static bool ShouldRandomizeSolverOrder { get; private set; }
127  public static bool ShouldSplitSimulationIslands { get; private set; }
128  public static bool ShouldEnableFrictionCaching { get; private set; }
129  public static float NumberOfSolverIterations { get; private set; }
130  public static bool UseSingleSidedMeshes { get; private set; }
131  public static float GlobalContactBreakingThreshold { get; private set; }
132  public static float PhysicsUnmanLoggingFrames { get; private set; }
133 
134  // Avatar parameters
135  public static bool AvatarToAvatarCollisionsByDefault { get; private set; }
136  public static float AvatarFriction { get; private set; }
137  public static float AvatarStandingFriction { get; private set; }
138  public static float AvatarAlwaysRunFactor { get; private set; }
139  public static float AvatarDensity { get; private set; }
140  public static float AvatarRestitution { get; private set; }
141  public static int AvatarShape { get; private set; }
142  public static float AvatarCapsuleWidth { get; private set; }
143  public static float AvatarCapsuleDepth { get; private set; }
144  public static float AvatarCapsuleHeight { get; private set; }
145  public static bool AvatarUseBefore09SizeComputation { get; private set; }
146  public static float AvatarHeightLowFudge { get; private set; }
147  public static float AvatarHeightMidFudge { get; private set; }
148  public static float AvatarHeightHighFudge { get; private set; }
149  public static float AvatarFlyingGroundMargin { get; private set; }
150  public static float AvatarFlyingGroundUpForce { get; private set; }
151  public static float AvatarTerminalVelocity { get; private set; }
152  public static float AvatarContactProcessingThreshold { get; private set; }
153  public static float AvatarAddForcePushFactor { get; private set; }
154  public static float AvatarStopZeroThreshold { get; private set; }
155  public static float AvatarStopZeroThresholdSquared { get; private set; }
156  public static int AvatarJumpFrames { get; private set; }
157  public static float AvatarBelowGroundUpCorrectionMeters { get; private set; }
158  public static float AvatarStepHeight { get; private set; }
159  public static float AvatarStepAngle { get; private set; }
160  public static float AvatarStepGroundFudge { get; private set; }
161  public static float AvatarStepApproachFactor { get; private set; }
162  public static float AvatarStepForceFactor { get; private set; }
163  public static float AvatarStepUpCorrectionFactor { get; private set; }
164  public static int AvatarStepSmoothingSteps { get; private set; }
165 
166  // Vehicle parameters
167  public static float VehicleMaxLinearVelocity { get; private set; }
168  public static float VehicleMaxLinearVelocitySquared { get; private set; }
169  public static float VehicleMinLinearVelocity { get; private set; }
170  public static float VehicleMinLinearVelocitySquared { get; private set; }
171  public static float VehicleMaxAngularVelocity { get; private set; }
172  public static float VehicleMaxAngularVelocitySq { get; private set; }
173  public static float VehicleAngularDamping { get; private set; }
174  public static float VehicleFriction { get; private set; }
175  public static float VehicleRestitution { get; private set; }
176  public static Vector3 VehicleLinearFactor { get; private set; }
177  public static Vector3 VehicleAngularFactor { get; private set; }
178  public static Vector3 VehicleInertiaFactor { get; private set; }
179  public static float VehicleGroundGravityFudge { get; private set; }
180  public static float VehicleAngularBankingTimescaleFudge { get; private set; }
181  public static bool VehicleEnableLinearDeflection { get; private set; }
182  public static bool VehicleLinearDeflectionNotCollidingNoZ { get; private set; }
183  public static bool VehicleEnableAngularVerticalAttraction { get; private set; }
184  public static int VehicleAngularVerticalAttractionAlgorithm { get; private set; }
185  public static bool VehicleEnableAngularDeflection { get; private set; }
186  public static bool VehicleEnableAngularBanking { get; private set; }
187 
188  // Convex Hulls
189  // Parameters for convex hull routine that ships with Bullet
190  public static int CSHullMaxDepthSplit { get; private set; }
191  public static int CSHullMaxDepthSplitForSimpleShapes { get; private set; }
192  public static float CSHullConcavityThresholdPercent { get; private set; }
193  public static float CSHullVolumeConservationThresholdPercent { get; private set; }
194  public static int CSHullMaxVertices { get; private set; }
195  public static float CSHullMaxSkinWidth { get; private set; }
196  public static float BHullMaxVerticesPerHull { get; private set; } // 100
197  public static float BHullMinClusters { get; private set; } // 2
198  public static float BHullCompacityWeight { get; private set; } // 0.1
199  public static float BHullVolumeWeight { get; private set; } // 0.0
200  public static float BHullConcavity { get; private set; } // 100
201  public static bool BHullAddExtraDistPoints { get; private set; } // false
202  public static bool BHullAddNeighboursDistPoints { get; private set; } // false
203  public static bool BHullAddFacesPoints { get; private set; } // false
204  public static bool BHullShouldAdjustCollisionMargin { get; private set; } // false
205  public static float WhichHACD { get; private set; } // zero if Bullet HACD, non-zero says VHACD
206  // Parameters for VHACD 2.0: http://code.google.com/p/v-hacd
207  // To enable, set both ShouldUseBulletHACD=true and WhichHACD=1
208  // http://kmamou.blogspot.ca/2014/12/v-hacd-20-parameters-description.html
209  public static float VHACDresolution { get; private set; } // 100,000 max number of voxels generated during voxelization stage
210  public static float VHACDdepth { get; private set; } // 20 max number of clipping stages
211  public static float VHACDconcavity { get; private set; } // 0.0025 maximum concavity
212  public static float VHACDplaneDownsampling { get; private set; } // 4 granularity of search for best clipping plane
213  public static float VHACDconvexHullDownsampling { get; private set; } // 4 precision of hull gen process
214  public static float VHACDalpha { get; private set; } // 0.05 bias toward clipping along symmetry planes
215  public static float VHACDbeta { get; private set; } // 0.05 bias toward clipping along revolution axis
216  public static float VHACDgamma { get; private set; } // 0.00125 max concavity when merging
217  public static float VHACDpca { get; private set; } // 0 on/off normalizing mesh before decomp
218  public static float VHACDmode { get; private set; } // 0 0:voxel based, 1: tetrahedron based
219  public static float VHACDmaxNumVerticesPerCH { get; private set; } // 64 max triangles per convex hull
220  public static float VHACDminVolumePerCH { get; private set; } // 0.0001 sampling of generated convex hulls
221 
222  // Linkset implementation parameters
223  public static float LinksetImplementation { get; private set; }
224  public static bool LinksetOffsetCenterOfMass { get; private set; }
225  public static bool LinkConstraintUseFrameOffset { get; private set; }
226  public static bool LinkConstraintEnableTransMotor { get; private set; }
227  public static float LinkConstraintTransMotorMaxVel { get; private set; }
228  public static float LinkConstraintTransMotorMaxForce { get; private set; }
229  public static float LinkConstraintERP { get; private set; }
230  public static float LinkConstraintCFM { get; private set; }
231  public static float LinkConstraintSolverIterations { get; private set; }
232 
233  public static float PID_D { get; private set; } // derivative
234  public static float PID_P { get; private set; } // proportional
235 
236  public static float DebugNumber { get; private set; } // A console setable number used for debugging
237 
238  // Various constants that come from that other virtual world that shall not be named.
239  public const float MinGravityZ = -1f;
240  public const float MaxGravityZ = 28f;
241  public const float MinFriction = 0f;
242  public const float MaxFriction = 255f;
243  public const float MinDensity = 0.01f;
244  public const float MaxDensity = 22587f;
245  public const float MinRestitution = 0f;
246  public const float MaxRestitution = 1f;
247 
248  // =====================================================================================
249  // =====================================================================================
250 
251  // Base parameter definition that gets and sets parameter values via a string
252  public abstract class ParameterDefnBase
253  {
254  public string name; // string name of the parameter
255  public string desc; // a short description of what the parameter means
256  public ParameterDefnBase(string pName, string pDesc)
257  {
258  name = pName;
259  desc = pDesc;
260  }
261  // Set the parameter value to the default
262  public abstract void AssignDefault(BSScene s);
263  // Get the value as a string
264  public abstract string GetValue(BSScene s);
265  // Set the value to this string value
266  public abstract void SetValue(BSScene s, string valAsString);
267  // set the value on a particular object (usually sets in physics engine)
268  public abstract void SetOnObject(BSScene s, BSPhysObject obj);
269  public abstract bool HasSetOnObject { get; }
270  }
271 
272  // Specific parameter definition for a parameter of a specific type.
273  public delegate T PGetValue<T>(BSScene s);
274  public delegate void PSetValue<T>(BSScene s, T val);
275  public delegate void PSetOnObject<T>(BSScene scene, BSPhysObject obj);
276  public sealed class ParameterDefn<T> : ParameterDefnBase
277  {
278  private T defaultValue;
279  private PSetValue<T> setter;
280  private PGetValue<T> getter;
281  private PSetOnObject<T> objectSet;
282  public ParameterDefn(string pName, string pDesc, T pDefault, PGetValue<T> pGetter, PSetValue<T> pSetter)
283  : base(pName, pDesc)
284  {
285  defaultValue = pDefault;
286  setter = pSetter;
287  getter = pGetter;
288  objectSet = null;
289  }
290  public ParameterDefn(string pName, string pDesc, T pDefault, PGetValue<T> pGetter, PSetValue<T> pSetter, PSetOnObject<T> pObjSetter)
291  : base(pName, pDesc)
292  {
293  defaultValue = pDefault;
294  setter = pSetter;
295  getter = pGetter;
296  objectSet = pObjSetter;
297  }
298  // Simple parameter variable where property name is the same as the INI file name
299  // and the value is only a simple get and set.
300  public ParameterDefn(string pName, string pDesc, T pDefault)
301  : base(pName, pDesc)
302  {
303  defaultValue = pDefault;
304  setter = (s, v) => { SetValueByName(s, name, v); };
305  getter = (s) => { return GetValueByName(s, name); };
306  objectSet = null;
307  }
308  // Use reflection to find the property named 'pName' in BSParam and assign 'val' to same.
309  private void SetValueByName(BSScene s, string pName, T val)
310  {
311  PropertyInfo prop = typeof(BSParam).GetProperty(pName, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
312  if (prop == null)
313  {
314  // This should only be output when someone adds a new INI parameter and misspells the name.
315  s.Logger.ErrorFormat("{0} SetValueByName: did not find '{1}'. Verify specified property name is the same as the given INI parameters name.", LogHeader, pName);
316  }
317  else
318  {
319  prop.SetValue(null, val, null);
320  }
321  }
322  // Use reflection to find the property named 'pName' in BSParam and return the value in same.
323  private T GetValueByName(BSScene s, string pName)
324  {
325  PropertyInfo prop = typeof(BSParam).GetProperty(pName, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
326  if (prop == null)
327  {
328  // This should only be output when someone adds a new INI parameter and misspells the name.
329  s.Logger.ErrorFormat("{0} GetValueByName: did not find '{1}'. Verify specified property name is the same as the given INI parameter name.", LogHeader, pName);
330  }
331  return (T)prop.GetValue(null, null);
332  }
333  public override void AssignDefault(BSScene s)
334  {
335  setter(s, defaultValue);
336  }
337  public override string GetValue(BSScene s)
338  {
339  return getter(s).ToString();
340  }
341  public override void SetValue(BSScene s, string valAsString)
342  {
343  // Get the generic type of the setter
344  Type genericType = setter.GetType().GetGenericArguments()[0];
345  // Find the 'Parse' method on that type
346  System.Reflection.MethodInfo parser = null;
347  try
348  {
349  parser = genericType.GetMethod("Parse", new Type[] { typeof(String) } );
350  }
351  catch (Exception e)
352  {
353  s.Logger.ErrorFormat("{0} Exception getting parser for type '{1}': {2}", LogHeader, genericType, e);
354  parser = null;
355  }
356  if (parser != null)
357  {
358  // Parse the input string
359  try
360  {
361  T setValue = (T)parser.Invoke(genericType, new Object[] { valAsString });
362  // Store the parsed value
363  setter(s, setValue);
364  // s.Logger.DebugFormat("{0} Parameter {1} = {2}", LogHeader, name, setValue);
365  }
366  catch
367  {
368  s.Logger.ErrorFormat("{0} Failed parsing parameter value '{1}' as type '{2}'", LogHeader, valAsString, genericType);
369  }
370  }
371  else
372  {
373  s.Logger.ErrorFormat("{0} Could not find parameter parser for type '{1}'", LogHeader, genericType);
374  }
375  }
376  public override bool HasSetOnObject
377  {
378  get { return objectSet != null; }
379  }
380  public override void SetOnObject(BSScene s, BSPhysObject obj)
381  {
382  if (objectSet != null)
383  objectSet(s, obj);
384  }
385  }
386 
387  // List of all of the externally visible parameters.
388  // For each parameter, this table maps a text name to getter and setters.
389  // To add a new externally referencable/settable parameter, add the paramter storage
390  // location somewhere in the program and make an entry in this table with the
391  // getters and setters.
392  // It is easiest to find an existing definition and copy it.
393  //
394  // A ParameterDefn<T>() takes the following parameters:
395  // -- the text name of the parameter. This is used for console input and ini file.
396  // -- a short text description of the parameter. This shows up in the console listing.
397  // -- a default value
398  // -- a delegate for getting the value
399  // -- a delegate for setting the value
400  // -- an optional delegate to update the value in the world. Most often used to
401  // push the new value to an in-world object.
402  //
403  // The single letter parameters for the delegates are:
404  // s = BSScene
405  // o = BSPhysObject
406  // v = value (appropriate type)
407  private static ParameterDefnBase[] ParameterDefinitions =
408  {
409  new ParameterDefn<bool>("Active", "If 'true', false then physics is not active",
410  false ),
411  new ParameterDefn<bool>("UseSeparatePhysicsThread", "If 'true', the physics engine runs independent from the simulator heartbeat",
412  false ),
413  new ParameterDefn<float>("PhysicsTimeStep", "If separate thread, seconds to simulate each interval",
414  0.089f ),
415 
416  new ParameterDefn<bool>("MeshSculptedPrim", "Whether to create meshes for sculpties",
417  true,
418  (s) => { return ShouldMeshSculptedPrim; },
419  (s,v) => { ShouldMeshSculptedPrim = v; } ),
420  new ParameterDefn<bool>("ForceSimplePrimMeshing", "If true, only use primitive meshes for objects",
421  false,
422  (s) => { return ShouldForceSimplePrimMeshing; },
423  (s,v) => { ShouldForceSimplePrimMeshing = v; } ),
424  new ParameterDefn<bool>("UseHullsForPhysicalObjects", "If true, create hulls for physical objects",
425  true,
426  (s) => { return ShouldUseHullsForPhysicalObjects; },
427  (s,v) => { ShouldUseHullsForPhysicalObjects = v; } ),
428  new ParameterDefn<bool>("ShouldRemoveZeroWidthTriangles", "If true, remove degenerate triangles from meshes",
429  true ),
430  new ParameterDefn<bool>("ShouldUseBulletHACD", "If true, use the Bullet version of HACD",
431  false ),
432  new ParameterDefn<bool>("ShouldUseSingleConvexHullForPrims", "If true, use a single convex hull shape for physical prims",
433  true ),
434  new ParameterDefn<bool>("ShouldUseGImpactShapeForPrims", "If true, use a GImpact shape for prims with cuts and twists",
435  false ),
436  new ParameterDefn<bool>("ShouldUseAssetHulls", "If true, use hull if specified in the mesh asset info",
437  true ),
438 
439  new ParameterDefn<int>("CrossingFailuresBeforeOutOfBounds", "How forgiving we are about getting into adjactent regions",
440  5 ),
441  new ParameterDefn<float>("UpdateVelocityChangeThreshold", "Change in updated velocity required before reporting change to simulator",
442  0.1f ),
443 
444  new ParameterDefn<float>("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)",
445  32f,
446  (s) => { return MeshLOD; },
447  (s,v) => { MeshLOD = v; } ),
448  new ParameterDefn<float>("MeshLevelOfDetailCircular", "Level of detail for prims with circular cuts or shapes",
449  32f,
450  (s) => { return MeshCircularLOD; },
451  (s,v) => { MeshCircularLOD = v; } ),
452  new ParameterDefn<float>("MeshLevelOfDetailMegaPrimThreshold", "Size (in meters) of a mesh before using MeshMegaPrimLOD",
453  10f,
454  (s) => { return MeshMegaPrimThreshold; },
455  (s,v) => { MeshMegaPrimThreshold = v; } ),
456  new ParameterDefn<float>("MeshLevelOfDetailMegaPrim", "Level of detail to render meshes larger than threshold meters",
457  32f,
458  (s) => { return MeshMegaPrimLOD; },
459  (s,v) => { MeshMegaPrimLOD = v; } ),
460  new ParameterDefn<float>("SculptLevelOfDetail", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)",
461  32f,
462  (s) => { return SculptLOD; },
463  (s,v) => { SculptLOD = v; } ),
464 
465  new ParameterDefn<int>("MaxSubStep", "In simulation step, maximum number of substeps",
466  10,
467  (s) => { return s.m_maxSubSteps; },
468  (s,v) => { s.m_maxSubSteps = (int)v; } ),
469  new ParameterDefn<float>("FixedTimeStep", "In simulation step, seconds of one substep (1/60)",
470  1f / 60f,
471  (s) => { return s.m_fixedTimeStep; },
472  (s,v) => { s.m_fixedTimeStep = v; } ),
473  new ParameterDefn<float>("NominalFrameRate", "The base frame rate we claim",
474  55f,
475  (s) => { return s.NominalFrameRate; },
476  (s,v) => { s.NominalFrameRate = (int)v; } ),
477  new ParameterDefn<int>("MaxCollisionsPerFrame", "Max collisions returned at end of each frame",
478  2048,
479  (s) => { return s.m_maxCollisionsPerFrame; },
480  (s,v) => { s.m_maxCollisionsPerFrame = (int)v; } ),
481  new ParameterDefn<int>("MaxUpdatesPerFrame", "Max updates returned at end of each frame",
482  8000,
483  (s) => { return s.m_maxUpdatesPerFrame; },
484  (s,v) => { s.m_maxUpdatesPerFrame = (int)v; } ),
485 
486  new ParameterDefn<float>("MinObjectMass", "Minimum object mass (0.0001)",
487  0.0001f,
488  (s) => { return MinimumObjectMass; },
489  (s,v) => { MinimumObjectMass = v; } ),
490  new ParameterDefn<float>("MaxObjectMass", "Maximum object mass (10000.01)",
491  10000.01f,
492  (s) => { return MaximumObjectMass; },
493  (s,v) => { MaximumObjectMass = v; } ),
494  new ParameterDefn<float>("MaxLinearVelocity", "Maximum velocity magnitude that can be assigned to an object",
495  1000.0f,
496  (s) => { return MaxLinearVelocity; },
497  (s,v) => { MaxLinearVelocity = v; MaxLinearVelocitySquared = v * v; } ),
498  new ParameterDefn<float>("MaxAngularVelocity", "Maximum rotational velocity magnitude that can be assigned to an object",
499  1000.0f,
500  (s) => { return MaxAngularVelocity; },
501  (s,v) => { MaxAngularVelocity = v; MaxAngularVelocitySquared = v * v; } ),
502  // LL documentation says thie number should be 20f for llApplyImpulse and 200f for llRezObject
503  new ParameterDefn<float>("MaxAddForceMagnitude", "Maximum force that can be applied by llApplyImpulse (SL says 20f)",
504  20000.0f,
505  (s) => { return MaxAddForceMagnitude; },
506  (s,v) => { MaxAddForceMagnitude = v; MaxAddForceMagnitudeSquared = v * v; } ),
507  // Density is passed around as 100kg/m3. This scales that to 1kg/m3.
508  // Reduce by power of 100 because Bullet doesn't seem to handle objects with large mass very well
509  new ParameterDefn<float>("DensityScaleFactor", "Conversion for simulator/viewer density (100kg/m3) to physical density (1kg/m3)",
510  0.01f ),
511 
512  new ParameterDefn<float>("PID_D", "Derivitive factor for motion smoothing",
513  2200f ),
514  new ParameterDefn<float>("PID_P", "Parameteric factor for motion smoothing",
515  900f ),
516 
517  new ParameterDefn<float>("DefaultFriction", "Friction factor used on new objects",
518  0.2f,
519  (s) => { return DefaultFriction; },
520  (s,v) => { DefaultFriction = v; s.UnmanagedParams[0].defaultFriction = v; } ),
521  // For historical reasons, the viewer and simulator multiply the density by 100
522  new ParameterDefn<float>("DefaultDensity", "Density for new objects" ,
523  1000.0006836f, // Aluminum g/cm3 * 100
524  (s) => { return DefaultDensity; },
525  (s,v) => { DefaultDensity = v; s.UnmanagedParams[0].defaultDensity = v; } ),
526  new ParameterDefn<float>("DefaultRestitution", "Bouncyness of an object" ,
527  0f,
528  (s) => { return DefaultRestitution; },
529  (s,v) => { DefaultRestitution = v; s.UnmanagedParams[0].defaultRestitution = v; } ),
530  new ParameterDefn<float>("CollisionMargin", "Margin around objects before collisions are calculated (must be zero!)",
531  0.04f,
532  (s) => { return CollisionMargin; },
533  (s,v) => { CollisionMargin = v; s.UnmanagedParams[0].collisionMargin = v; } ),
534  new ParameterDefn<float>("Gravity", "Vertical force of gravity (negative means down)",
535  -9.80665f,
536  (s) => { return Gravity; },
537  (s,v) => { Gravity = v; s.UnmanagedParams[0].gravity = v; },
538  (s,o) => { s.PE.SetGravity(o.PhysBody, new Vector3(0f,0f,Gravity)); } ),
539 
540 
541  new ParameterDefn<float>("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)",
542  0f,
543  (s) => { return LinearDamping; },
544  (s,v) => { LinearDamping = v; },
545  (s,o) => { s.PE.SetDamping(o.PhysBody, LinearDamping, AngularDamping); } ),
546  new ParameterDefn<float>("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)",
547  0f,
548  (s) => { return AngularDamping; },
549  (s,v) => { AngularDamping = v; },
550  (s,o) => { s.PE.SetDamping(o.PhysBody, LinearDamping, AngularDamping); } ),
551  new ParameterDefn<float>("DeactivationTime", "Seconds before considering an object potentially static",
552  0.2f,
553  (s) => { return DeactivationTime; },
554  (s,v) => { DeactivationTime = v; },
555  (s,o) => { s.PE.SetDeactivationTime(o.PhysBody, DeactivationTime); } ),
556  new ParameterDefn<float>("LinearSleepingThreshold", "Seconds to measure linear movement before considering static",
557  0.8f,
558  (s) => { return LinearSleepingThreshold; },
559  (s,v) => { LinearSleepingThreshold = v;},
560  (s,o) => { s.PE.SetSleepingThresholds(o.PhysBody, LinearSleepingThreshold, AngularSleepingThreshold); } ),
561  new ParameterDefn<float>("AngularSleepingThreshold", "Seconds to measure angular movement before considering static",
562  1.0f,
563  (s) => { return AngularSleepingThreshold; },
564  (s,v) => { AngularSleepingThreshold = v;},
565  (s,o) => { s.PE.SetSleepingThresholds(o.PhysBody, LinearSleepingThreshold, AngularSleepingThreshold); } ),
566  new ParameterDefn<float>("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" ,
567  0.0f, // set to zero to disable
568  (s) => { return CcdMotionThreshold; },
569  (s,v) => { CcdMotionThreshold = v;},
570  (s,o) => { s.PE.SetCcdMotionThreshold(o.PhysBody, CcdMotionThreshold); } ),
571  new ParameterDefn<float>("CcdSweptSphereRadius", "Continuious collision detection test radius" ,
572  0.2f,
573  (s) => { return CcdSweptSphereRadius; },
574  (s,v) => { CcdSweptSphereRadius = v;},
575  (s,o) => { s.PE.SetCcdSweptSphereRadius(o.PhysBody, CcdSweptSphereRadius); } ),
576  new ParameterDefn<float>("ContactProcessingThreshold", "Distance above which contacts can be discarded (0 means no discard)" ,
577  0.0f,
578  (s) => { return ContactProcessingThreshold; },
579  (s,v) => { ContactProcessingThreshold = v;},
580  (s,o) => { s.PE.SetContactProcessingThreshold(o.PhysBody, ContactProcessingThreshold); } ),
581 
582  new ParameterDefn<float>("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)",
583  (float)BSTerrainPhys.TerrainImplementation.Heightmap ),
584  new ParameterDefn<int>("TerrainMeshMagnification", "Number of times the 256x256 heightmap is multiplied to create the terrain mesh" ,
585  2 ),
586  new ParameterDefn<float>("TerrainGroundPlane", "Altitude of ground plane used to keep things from falling to infinity" ,
587  -500.0f ),
588  new ParameterDefn<float>("TerrainFriction", "Factor to reduce movement against terrain surface" ,
589  0.3f ),
590  new ParameterDefn<float>("TerrainHitFraction", "Distance to measure hit collisions" ,
591  0.8f ),
592  new ParameterDefn<float>("TerrainRestitution", "Bouncyness" ,
593  0f ),
594  new ParameterDefn<float>("TerrainContactProcessingThreshold", "Distance from terrain to stop processing collisions" ,
595  0.0f ),
596  new ParameterDefn<float>("TerrainCollisionMargin", "Margin where collision checking starts" ,
597  0.04f ),
598 
599  new ParameterDefn<bool>("AvatarToAvatarCollisionsByDefault", "Should avatars collide with other avatars by default?",
600  true),
601  new ParameterDefn<float>("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.",
602  0.2f ),
603  new ParameterDefn<float>("AvatarStandingFriction", "Avatar friction when standing. Changed on avatar recreation.",
604  0.95f ),
605  new ParameterDefn<float>("AvatarAlwaysRunFactor", "Speed multiplier if avatar is set to always run",
606  1.3f ),
607  // For historical reasons, density is reported * 100
608  new ParameterDefn<float>("AvatarDensity", "Density of an avatar. Changed on avatar recreation. Scaled times 100.",
609  350f) , // 3.5 * 100
610  new ParameterDefn<float>("AvatarRestitution", "Bouncyness. Changed on avatar recreation.",
611  0f ),
612  new ParameterDefn<int>("AvatarShape", "Code for avatar physical shape: 0:capsule, 1:cube, 2:ovoid, 2:mesh",
613  BSShapeCollection.AvatarShapeCube ) ,
614  new ParameterDefn<float>("AvatarCapsuleWidth", "The distance between the sides of the avatar capsule",
615  0.6f ) ,
616  new ParameterDefn<float>("AvatarCapsuleDepth", "The distance between the front and back of the avatar capsule",
617  0.45f ),
618  new ParameterDefn<float>("AvatarCapsuleHeight", "Default height of space around avatar",
619  1.5f ),
620  new ParameterDefn<bool>("AvatarUseBefore09SizeComputation", "Use the old fudge method of computing avatar capsule size",
621  true ),
622  new ParameterDefn<float>("AvatarHeightLowFudge", "A fudge factor to make small avatars stand on the ground",
623  0f ),
624  new ParameterDefn<float>("AvatarHeightMidFudge", "A fudge distance to adjust average sized avatars to be standing on ground",
625  0f ),
626  new ParameterDefn<float>("AvatarHeightHighFudge", "A fudge factor to make tall avatars stand on the ground",
627  0f ),
628  new ParameterDefn<float>("AvatarFlyingGroundMargin", "Meters avatar is kept above the ground when flying",
629  5f ),
630  new ParameterDefn<float>("AvatarFlyingGroundUpForce", "Upward force applied to the avatar to keep it at flying ground margin",
631  2.0f ),
632  new ParameterDefn<float>("AvatarTerminalVelocity", "Terminal Velocity of falling avatar",
633  -54.0f ),
634  new ParameterDefn<float>("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions",
635  0.1f ),
636  new ParameterDefn<float>("AvatarAddForcePushFactor", "BSCharacter.AddForce is multiplied by this and mass to be like other physics engines",
637  0.315f ),
638  new ParameterDefn<float>("AvatarStopZeroThreshold", "Movement velocity below which avatar is assumed to be stopped",
639  0.45f,
640  (s) => { return (float)AvatarStopZeroThreshold; },
641  (s,v) => { AvatarStopZeroThreshold = v; AvatarStopZeroThresholdSquared = v * v; } ),
642  new ParameterDefn<float>("AvatarBelowGroundUpCorrectionMeters", "Meters to move avatar up if it seems to be below ground",
643  1.0f ),
644  new ParameterDefn<int>("AvatarJumpFrames", "Number of frames to allow jump forces. Changes jump height.",
645  4 ),
646  new ParameterDefn<float>("AvatarStepHeight", "Height of a step obstacle to consider step correction",
647  0.999f ) ,
648  new ParameterDefn<float>("AvatarStepAngle", "The angle (in radians) for a vertical surface to be considered a step",
649  0.3f ) ,
650  new ParameterDefn<float>("AvatarStepGroundFudge", "Fudge factor subtracted from avatar base when comparing collision height",
651  0.1f ) ,
652  new ParameterDefn<float>("AvatarStepApproachFactor", "Factor to control angle of approach to step (0=straight on)",
653  2f ),
654  new ParameterDefn<float>("AvatarStepForceFactor", "Controls the amount of force up applied to step up onto a step",
655  0f ),
656  new ParameterDefn<float>("AvatarStepUpCorrectionFactor", "Multiplied by height of step collision to create up movement at step",
657  0.8f ),
658  new ParameterDefn<int>("AvatarStepSmoothingSteps", "Number of frames after a step collision that we continue walking up stairs",
659  1 ),
660 
661  new ParameterDefn<float>("VehicleMaxLinearVelocity", "Maximum velocity magnitude that can be assigned to a vehicle",
662  1000.0f,
663  (s) => { return (float)VehicleMaxLinearVelocity; },
664  (s,v) => { VehicleMaxLinearVelocity = v; VehicleMaxLinearVelocitySquared = v * v; } ),
665  new ParameterDefn<float>("VehicleMinLinearVelocity", "Maximum velocity magnitude that can be assigned to a vehicle",
666  0.001f,
667  (s) => { return (float)VehicleMinLinearVelocity; },
668  (s,v) => { VehicleMinLinearVelocity = v; VehicleMinLinearVelocitySquared = v * v; } ),
669  new ParameterDefn<float>("VehicleMaxAngularVelocity", "Maximum rotational velocity magnitude that can be assigned to a vehicle",
670  12.0f,
671  (s) => { return (float)VehicleMaxAngularVelocity; },
672  (s,v) => { VehicleMaxAngularVelocity = v; VehicleMaxAngularVelocitySq = v * v; } ),
673  new ParameterDefn<float>("VehicleAngularDamping", "Factor to damp vehicle angular movement per second (0.0 - 1.0)",
674  0.0f ),
675  new ParameterDefn<Vector3>("VehicleLinearFactor", "Fraction of physical linear changes applied to vehicle (<0,0,0> to <1,1,1>)",
676  new Vector3(1f, 1f, 1f) ),
677  new ParameterDefn<Vector3>("VehicleAngularFactor", "Fraction of physical angular changes applied to vehicle (<0,0,0> to <1,1,1>)",
678  new Vector3(1f, 1f, 1f) ),
679  new ParameterDefn<Vector3>("VehicleInertiaFactor", "Fraction of physical inertia applied (<0,0,0> to <1,1,1>)",
680  new Vector3(1f, 1f, 1f) ),
681  new ParameterDefn<float>("VehicleFriction", "Friction of vehicle on the ground (0.0 - 1.0)",
682  0.0f ),
683  new ParameterDefn<float>("VehicleRestitution", "Bouncyness factor for vehicles (0.0 - 1.0)",
684  0.0f ),
685  new ParameterDefn<float>("VehicleGroundGravityFudge", "Factor to multiply gravity if a ground vehicle is probably on the ground (0.0 - 1.0)",
686  0.2f ),
687  new ParameterDefn<float>("VehicleAngularBankingTimescaleFudge", "Factor to multiple angular banking timescale. Tune to increase realism.",
688  60.0f ),
689  new ParameterDefn<bool>("VehicleEnableLinearDeflection", "Turn on/off vehicle linear deflection effect",
690  true ),
691  new ParameterDefn<bool>("VehicleLinearDeflectionNotCollidingNoZ", "Turn on/off linear deflection Z effect on non-colliding vehicles",
692  true ),
693  new ParameterDefn<bool>("VehicleEnableAngularVerticalAttraction", "Turn on/off vehicle angular vertical attraction effect",
694  true ),
695  new ParameterDefn<int>("VehicleAngularVerticalAttractionAlgorithm", "Select vertical attraction algo. You need to look at the source.",
696  0 ),
697  new ParameterDefn<bool>("VehicleEnableAngularDeflection", "Turn on/off vehicle angular deflection effect",
698  true ),
699  new ParameterDefn<bool>("VehicleEnableAngularBanking", "Turn on/off vehicle angular banking effect",
700  true ),
701 
702  new ParameterDefn<float>("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)",
703  0f,
704  (s) => { return MaxPersistantManifoldPoolSize; },
705  (s,v) => { MaxPersistantManifoldPoolSize = v; s.UnmanagedParams[0].maxPersistantManifoldPoolSize = v; } ),
706  new ParameterDefn<float>("MaxCollisionAlgorithmPoolSize", "Number of collisions pooled (0 means default of 4096)",
707  0f,
708  (s) => { return MaxCollisionAlgorithmPoolSize; },
709  (s,v) => { MaxCollisionAlgorithmPoolSize = v; s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize = v; } ),
710  new ParameterDefn<bool>("ShouldDisableContactPoolDynamicAllocation", "Enable to allow large changes in object count",
711  false,
712  (s) => { return ShouldDisableContactPoolDynamicAllocation; },
713  (s,v) => { ShouldDisableContactPoolDynamicAllocation = v;
714  s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation = NumericBool(v); } ),
715  new ParameterDefn<bool>("ShouldForceUpdateAllAabbs", "Enable to recomputer AABBs every simulator step",
716  false,
717  (s) => { return ShouldForceUpdateAllAabbs; },
718  (s,v) => { ShouldForceUpdateAllAabbs = v; s.UnmanagedParams[0].shouldForceUpdateAllAabbs = NumericBool(v); } ),
719  new ParameterDefn<bool>("ShouldRandomizeSolverOrder", "Enable for slightly better stacking interaction",
720  true,
721  (s) => { return ShouldRandomizeSolverOrder; },
722  (s,v) => { ShouldRandomizeSolverOrder = v; s.UnmanagedParams[0].shouldRandomizeSolverOrder = NumericBool(v); } ),
723  new ParameterDefn<bool>("ShouldSplitSimulationIslands", "Enable splitting active object scanning islands",
724  true,
725  (s) => { return ShouldSplitSimulationIslands; },
726  (s,v) => { ShouldSplitSimulationIslands = v; s.UnmanagedParams[0].shouldSplitSimulationIslands = NumericBool(v); } ),
727  new ParameterDefn<bool>("ShouldEnableFrictionCaching", "Enable friction computation caching",
728  true,
729  (s) => { return ShouldEnableFrictionCaching; },
730  (s,v) => { ShouldEnableFrictionCaching = v; s.UnmanagedParams[0].shouldEnableFrictionCaching = NumericBool(v); } ),
731  new ParameterDefn<float>("NumberOfSolverIterations", "Number of internal iterations (0 means default)",
732  0f, // zero says use Bullet default
733  (s) => { return NumberOfSolverIterations; },
734  (s,v) => { NumberOfSolverIterations = v; s.UnmanagedParams[0].numberOfSolverIterations = v; } ),
735  new ParameterDefn<bool>("UseSingleSidedMeshes", "Whether to compute collisions based on single sided meshes.",
736  true,
737  (s) => { return UseSingleSidedMeshes; },
738  (s,v) => { UseSingleSidedMeshes = v; s.UnmanagedParams[0].useSingleSidedMeshes = NumericBool(v); } ),
739  new ParameterDefn<float>("GlobalContactBreakingThreshold", "Amount of shape radius before breaking a collision contact (0 says Bullet default (0.2))",
740  0f,
741  (s) => { return GlobalContactBreakingThreshold; },
742  (s,v) => { GlobalContactBreakingThreshold = v; s.UnmanagedParams[0].globalContactBreakingThreshold = v; } ),
743  new ParameterDefn<float>("PhysicsUnmanLoggingFrames", "If non-zero, frames between output of detailed unmanaged physics statistics",
744  0f,
745  (s) => { return PhysicsUnmanLoggingFrames; },
746  (s,v) => { PhysicsUnmanLoggingFrames = v; s.UnmanagedParams[0].physicsLoggingFrames = v; } ),
747 
748  new ParameterDefn<int>("CSHullMaxDepthSplit", "CS impl: max depth to split for hull. 1-10 but > 7 is iffy",
749  7 ),
750  new ParameterDefn<int>("CSHullMaxDepthSplitForSimpleShapes", "CS impl: max depth setting for simple prim shapes",
751  2 ),
752  new ParameterDefn<float>("CSHullConcavityThresholdPercent", "CS impl: concavity threshold percent (0-20)",
753  5f ),
754  new ParameterDefn<float>("CSHullVolumeConservationThresholdPercent", "percent volume conservation to collapse hulls (0-30)",
755  5f ),
756  new ParameterDefn<int>("CSHullMaxVertices", "CS impl: maximum number of vertices in output hulls. Keep < 50.",
757  32 ),
758  new ParameterDefn<float>("CSHullMaxSkinWidth", "CS impl: skin width to apply to output hulls.",
759  0f ),
760 
761  new ParameterDefn<float>("BHullMaxVerticesPerHull", "Bullet impl: max number of vertices per created hull",
762  200f ),
763  new ParameterDefn<float>("BHullMinClusters", "Bullet impl: minimum number of hulls to create per mesh",
764  10f ),
765  new ParameterDefn<float>("BHullCompacityWeight", "Bullet impl: weight factor for how compact to make hulls",
766  20f ),
767  new ParameterDefn<float>("BHullVolumeWeight", "Bullet impl: weight factor for volume in created hull",
768  0.1f ),
769  new ParameterDefn<float>("BHullConcavity", "Bullet impl: weight factor for how convex a created hull can be",
770  10f ),
771  new ParameterDefn<bool>("BHullAddExtraDistPoints", "Bullet impl: whether to add extra vertices for long distance vectors",
772  true ),
773  new ParameterDefn<bool>("BHullAddNeighboursDistPoints", "Bullet impl: whether to add extra vertices between neighbor hulls",
774  true ),
775  new ParameterDefn<bool>("BHullAddFacesPoints", "Bullet impl: whether to add extra vertices to break up hull faces",
776  true ),
777  new ParameterDefn<bool>("BHullShouldAdjustCollisionMargin", "Bullet impl: whether to shrink resulting hulls to account for collision margin",
778  false ),
779 
780  new ParameterDefn<float>("WhichHACD", "zero if Bullet HACD, non-zero says VHACD",
781  0f ),
782  new ParameterDefn<float>("VHACDresolution", "max number of voxels generated during voxelization stage",
783  100000f ),
784  new ParameterDefn<float>("VHACDdepth", "max number of clipping stages",
785  20f ),
786  new ParameterDefn<float>("VHACDconcavity", "maximum concavity",
787  0.0025f ),
788  new ParameterDefn<float>("VHACDplaneDownsampling", "granularity of search for best clipping plane",
789  4f ),
790  new ParameterDefn<float>("VHACDconvexHullDownsampling", "precision of hull gen process",
791  4f ),
792  new ParameterDefn<float>("VHACDalpha", "bias toward clipping along symmetry planes",
793  0.05f ),
794  new ParameterDefn<float>("VHACDbeta", "bias toward clipping along revolution axis",
795  0.05f ),
796  new ParameterDefn<float>("VHACDgamma", "max concavity when merging",
797  0.00125f ),
798  new ParameterDefn<float>("VHACDpca", "on/off normalizing mesh before decomp",
799  0f ),
800  new ParameterDefn<float>("VHACDmode", "0:voxel based, 1: tetrahedron based",
801  0f ),
802  new ParameterDefn<float>("VHACDmaxNumVerticesPerCH", "max triangles per convex hull",
803  64f ),
804  new ParameterDefn<float>("VHACDminVolumePerCH", "sampling of generated convex hulls",
805  0.0001f ),
806 
807  new ParameterDefn<float>("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)",
808  (float)BSLinkset.LinksetImplementation.Compound ),
809  new ParameterDefn<bool>("LinksetOffsetCenterOfMass", "If 'true', compute linkset center-of-mass and offset linkset position to account for same",
810  true ),
811  new ParameterDefn<bool>("LinkConstraintUseFrameOffset", "For linksets built with constraints, enable frame offsetFor linksets built with constraints, enable frame offset.",
812  false ),
813  new ParameterDefn<bool>("LinkConstraintEnableTransMotor", "Whether to enable translational motor on linkset constraints",
814  true ),
815  new ParameterDefn<float>("LinkConstraintTransMotorMaxVel", "Maximum velocity to be applied by translational motor in linkset constraints",
816  5.0f ),
817  new ParameterDefn<float>("LinkConstraintTransMotorMaxForce", "Maximum force to be applied by translational motor in linkset constraints",
818  0.1f ),
819  new ParameterDefn<float>("LinkConstraintCFM", "Amount constraint can be violated. 0=no violation, 1=infinite. Default=0.1",
820  0.1f ),
821  new ParameterDefn<float>("LinkConstraintERP", "Amount constraint is corrected each tick. 0=none, 1=all. Default = 0.2",
822  0.1f ),
823  new ParameterDefn<float>("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)",
824  40 ),
825 
826  new ParameterDefn<float>("DebugNumber", "A console setable number sometimes used for debugging",
827  1.0f ),
828 
829  new ParameterDefn<int>("PhysicsMetricFrames", "Frames between outputting detailed phys metrics. (0 is off)",
830  0,
831  (s) => { return s.PhysicsMetricDumpFrames; },
832  (s,v) => { s.PhysicsMetricDumpFrames = v; } ),
833  new ParameterDefn<float>("ResetBroadphasePool", "Setting this is any value resets the broadphase collision pool",
834  0f,
835  (s) => { return 0f; },
836  (s,v) => { BSParam.ResetBroadphasePoolTainted(s, v, false /* inTaintTime */); } ),
837  new ParameterDefn<float>("ResetConstraintSolver", "Setting this is any value resets the constraint solver",
838  0f,
839  (s) => { return 0f; },
840  (s,v) => { BSParam.ResetConstraintSolverTainted(s, v); } ),
841  };
842 
843  // Convert a boolean to our numeric true and false values
844  public static float NumericBool(bool b)
845  {
846  return (b ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse);
847  }
848 
849  // Convert numeric true and false values to a boolean
850  public static bool BoolNumeric(float b)
851  {
852  return (b == ConfigurationParameters.numericTrue ? true : false);
853  }
854 
855  // Search through the parameter definitions and return the matching
856  // ParameterDefn structure.
857  // Case does not matter as names are compared after converting to lower case.
858  // Returns 'false' if the parameter is not found.
859  internal static bool TryGetParameter(string paramName, out ParameterDefnBase defn)
860  {
861  bool ret = false;
862  ParameterDefnBase foundDefn = null;
863  string pName = paramName.ToLower();
864 
865  foreach (ParameterDefnBase parm in ParameterDefinitions)
866  {
867  if (pName == parm.name.ToLower())
868  {
869  foundDefn = parm;
870  ret = true;
871  break;
872  }
873  }
874  defn = foundDefn;
875  return ret;
876  }
877 
878  // Pass through the settable parameters and set the default values
879  internal static void SetParameterDefaultValues(BSScene physicsScene)
880  {
881  foreach (ParameterDefnBase parm in ParameterDefinitions)
882  {
883  parm.AssignDefault(physicsScene);
884  }
885  }
886 
887  // Get user set values out of the ini file.
888  internal static void SetParameterConfigurationValues(BSScene physicsScene, IConfig cfg)
889  {
890  foreach (ParameterDefnBase parm in ParameterDefinitions)
891  {
892  parm.SetValue(physicsScene, cfg.GetString(parm.name, parm.GetValue(physicsScene)));
893  }
894  }
895 
896  internal static PhysParameterEntry[] SettableParameters = new PhysParameterEntry[1];
897 
898  // This creates an array in the correct format for returning the list of
899  // parameters. This is used by the 'list' option of the 'physics' command.
900  internal static void BuildParameterTable()
901  {
902  if (SettableParameters.Length < ParameterDefinitions.Length)
903  {
904  List<PhysParameterEntry> entries = new List<PhysParameterEntry>();
905  for (int ii = 0; ii < ParameterDefinitions.Length; ii++)
906  {
907  ParameterDefnBase pd = ParameterDefinitions[ii];
908  entries.Add(new PhysParameterEntry(pd.name, pd.desc));
909  }
910 
911  // make the list alphabetical for ease of finding anything
912  entries.Sort((ppe1, ppe2) => { return ppe1.name.CompareTo(ppe2.name); });
913 
914  SettableParameters = entries.ToArray();
915  }
916  }
917 
918  // =====================================================================
919  // =====================================================================
920  // There are parameters that, when set, cause things to happen in the physics engine.
921  // This causes the broadphase collision cache to be cleared.
922  private static void ResetBroadphasePoolTainted(BSScene pPhysScene, float v, bool inTaintTime)
923  {
924  BSScene physScene = pPhysScene;
925  physScene.TaintedObject(inTaintTime, "BSParam.ResetBroadphasePoolTainted", delegate()
926  {
927  physScene.PE.ResetBroadphasePool(physScene.World);
928  });
929  }
930 
931  // This causes the constraint solver cache to be cleared and reset.
932  private static void ResetConstraintSolverTainted(BSScene pPhysScene, float v)
933  {
934  BSScene physScene = pPhysScene;
935  physScene.TaintedObject(BSScene.DetailLogZero, "BSParam.ResetConstraintSolver", delegate()
936  {
937  physScene.PE.ResetConstraintSolver(physScene.World);
938  });
939  }
940 }
941 }
override void SetOnObject(BSScene s, BSPhysObject obj)
Definition: BSParam.cs:380
ParameterDefn(string pName, string pDesc, T pDefault, PGetValue< T > pGetter, PSetValue< T > pSetter, PSetOnObject< T > pObjSetter)
Definition: BSParam.cs:290
override void SetValue(BSScene s, string valAsString)
Definition: BSParam.cs:341
ParameterDefn(string pName, string pDesc, T pDefault, PGetValue< T > pGetter, PSetValue< T > pSetter)
Definition: BSParam.cs:282
ParameterDefn(string pName, string pDesc, T pDefault)
Definition: BSParam.cs:300