BSParam.cs 58 KB

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