aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSParam.cs628
1 files changed, 628 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
new file mode 100755
index 0000000..23d573f
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
@@ -0,0 +1,628 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyrightD
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30
31using OpenSim.Region.Physics.Manager;
32
33using OpenMetaverse;
34using Nini.Config;
35
36namespace OpenSim.Region.Physics.BulletSPlugin
37{
38public static class BSParam
39{
40 // Level of Detail values kept as float because that's what the Meshmerizer wants
41 public static float MeshLOD { get; private set; }
42 public static float MeshMegaPrimLOD { get; private set; }
43 public static float MeshMegaPrimThreshold { get; private set; }
44 public static float SculptLOD { get; private set; }
45
46 public static float MinimumObjectMass { get; private set; }
47 public static float MaximumObjectMass { get; private set; }
48
49 public static float LinearDamping { get; private set; }
50 public static float AngularDamping { get; private set; }
51 public static float DeactivationTime { get; private set; }
52 public static float LinearSleepingThreshold { get; private set; }
53 public static float AngularSleepingThreshold { get; private set; }
54 public static float CcdMotionThreshold { get; private set; }
55 public static float CcdSweptSphereRadius { get; private set; }
56 public static float ContactProcessingThreshold { get; private set; }
57
58 public static bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed
59 public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes
60 public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects
61
62 public static float TerrainImplementation { get; private set; }
63 public static float TerrainFriction { get; private set; }
64 public static float TerrainHitFraction { get; private set; }
65 public static float TerrainRestitution { get; private set; }
66 public static float TerrainCollisionMargin { get; private set; }
67
68 // Avatar parameters
69 public static float AvatarFriction { get; private set; }
70 public static float AvatarStandingFriction { get; private set; }
71 public static float AvatarAlwaysRunFactor { get; private set; }
72 public static float AvatarDensity { get; private set; }
73 public static float AvatarRestitution { get; private set; }
74 public static float AvatarCapsuleWidth { get; private set; }
75 public static float AvatarCapsuleDepth { get; private set; }
76 public static float AvatarCapsuleHeight { get; private set; }
77 public static float AvatarContactProcessingThreshold { get; private set; }
78 public static float AvatarStepHeight { get; private set; }
79 public static float AvatarStepApproachFactor { get; private set; }
80 public static float AvatarStepForceFactor { get; private set; }
81
82 public static float VehicleAngularDamping { get; private set; }
83
84 public static float LinksetImplementation { get; private set; }
85 public static float LinkConstraintUseFrameOffset { get; private set; }
86 public static float LinkConstraintEnableTransMotor { get; private set; }
87 public static float LinkConstraintTransMotorMaxVel { get; private set; }
88 public static float LinkConstraintTransMotorMaxForce { get; private set; }
89 public static float LinkConstraintERP { get; private set; }
90 public static float LinkConstraintCFM { get; private set; }
91 public static float LinkConstraintSolverIterations { get; private set; }
92
93 public static float PID_D { get; private set; } // derivative
94 public static float PID_P { get; private set; } // proportional
95
96 // Various constants that come from that other virtual world that shall not be named
97 public const float MinGravityZ = -1f;
98 public const float MaxGravityZ = 28f;
99 public const float MinFriction = 0f;
100 public const float MaxFriction = 255f;
101 public const float MinDensity = 0f;
102 public const float MaxDensity = 22587f;
103 public const float MinRestitution = 0f;
104 public const float MaxRestitution = 1f;
105 public const float MaxAddForceMagnitude = 20000f;
106
107 // ===========================================================================
108 public delegate void ParamUser(BSScene scene, IConfig conf, string paramName, float val);
109 public delegate float ParamGet(BSScene scene);
110 public delegate void ParamSet(BSScene scene, string paramName, uint localID, float val);
111 public delegate void SetOnObject(BSScene scene, BSPhysObject obj, float val);
112
113 public struct ParameterDefn
114 {
115 public string name; // string name of the parameter
116 public string desc; // a short description of what the parameter means
117 public float defaultValue; // default value if not specified anywhere else
118 public ParamUser userParam; // get the value from the configuration file
119 public ParamGet getter; // return the current value stored for this parameter
120 public ParamSet setter; // set the current value for this parameter
121 public SetOnObject onObject; // set the value on an object in the physical domain
122 public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s)
123 {
124 name = n;
125 desc = d;
126 defaultValue = v;
127 userParam = u;
128 getter = g;
129 setter = s;
130 onObject = null;
131 }
132 public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s, SetOnObject o)
133 {
134 name = n;
135 desc = d;
136 defaultValue = v;
137 userParam = u;
138 getter = g;
139 setter = s;
140 onObject = o;
141 }
142 }
143
144 // List of all of the externally visible parameters.
145 // For each parameter, this table maps a text name to getter and setters.
146 // To add a new externally referencable/settable parameter, add the paramter storage
147 // location somewhere in the program and make an entry in this table with the
148 // getters and setters.
149 // It is easiest to find an existing definition and copy it.
150 // Parameter values are floats. Booleans are converted to a floating value.
151 //
152 // A ParameterDefn() takes the following parameters:
153 // -- the text name of the parameter. This is used for console input and ini file.
154 // -- a short text description of the parameter. This shows up in the console listing.
155 // -- a default value (float)
156 // -- a delegate for fetching the parameter from the ini file.
157 // Should handle fetching the right type from the ini file and converting it.
158 // -- a delegate for getting the value as a float
159 // -- a delegate for setting the value from a float
160 // -- an optional delegate to update the value in the world. Most often used to
161 // push the new value to an in-world object.
162 //
163 // The single letter parameters for the delegates are:
164 // s = BSScene
165 // o = BSPhysObject
166 // p = string parameter name
167 // l = localID of referenced object
168 // v = value (float)
169 // cf = parameter configuration class (for fetching values from ini file)
170 private static ParameterDefn[] ParameterDefinitions =
171 {
172 new ParameterDefn("MeshSculptedPrim", "Whether to create meshes for sculpties",
173 ConfigurationParameters.numericTrue,
174 (s,cf,p,v) => { ShouldMeshSculptedPrim = cf.GetBoolean(p, BSParam.BoolNumeric(v)); },
175 (s) => { return BSParam.NumericBool(ShouldMeshSculptedPrim); },
176 (s,p,l,v) => { ShouldMeshSculptedPrim = BSParam.BoolNumeric(v); } ),
177 new ParameterDefn("ForceSimplePrimMeshing", "If true, only use primitive meshes for objects",
178 ConfigurationParameters.numericFalse,
179 (s,cf,p,v) => { ShouldForceSimplePrimMeshing = cf.GetBoolean(p, BSParam.BoolNumeric(v)); },
180 (s) => { return BSParam.NumericBool(ShouldForceSimplePrimMeshing); },
181 (s,p,l,v) => { ShouldForceSimplePrimMeshing = BSParam.BoolNumeric(v); } ),
182 new ParameterDefn("UseHullsForPhysicalObjects", "If true, create hulls for physical objects",
183 ConfigurationParameters.numericTrue,
184 (s,cf,p,v) => { ShouldUseHullsForPhysicalObjects = cf.GetBoolean(p, BSParam.BoolNumeric(v)); },
185 (s) => { return BSParam.NumericBool(ShouldUseHullsForPhysicalObjects); },
186 (s,p,l,v) => { ShouldUseHullsForPhysicalObjects = BSParam.BoolNumeric(v); } ),
187
188 new ParameterDefn("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)",
189 8f,
190 (s,cf,p,v) => { MeshLOD = (float)cf.GetInt(p, (int)v); },
191 (s) => { return MeshLOD; },
192 (s,p,l,v) => { MeshLOD = v; } ),
193 new ParameterDefn("MeshLevelOfDetailMegaPrim", "Level of detail to render meshes larger than threshold meters",
194 16f,
195 (s,cf,p,v) => { MeshMegaPrimLOD = (float)cf.GetInt(p, (int)v); },
196 (s) => { return MeshMegaPrimLOD; },
197 (s,p,l,v) => { MeshMegaPrimLOD = v; } ),
198 new ParameterDefn("MeshLevelOfDetailMegaPrimThreshold", "Size (in meters) of a mesh before using MeshMegaPrimLOD",
199 10f,
200 (s,cf,p,v) => { MeshMegaPrimThreshold = (float)cf.GetInt(p, (int)v); },
201 (s) => { return MeshMegaPrimThreshold; },
202 (s,p,l,v) => { MeshMegaPrimThreshold = v; } ),
203 new ParameterDefn("SculptLevelOfDetail", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)",
204 32f,
205 (s,cf,p,v) => { SculptLOD = (float)cf.GetInt(p, (int)v); },
206 (s) => { return SculptLOD; },
207 (s,p,l,v) => { SculptLOD = v; } ),
208
209 new ParameterDefn("MaxSubStep", "In simulation step, maximum number of substeps",
210 10f,
211 (s,cf,p,v) => { s.m_maxSubSteps = cf.GetInt(p, (int)v); },
212 (s) => { return (float)s.m_maxSubSteps; },
213 (s,p,l,v) => { s.m_maxSubSteps = (int)v; } ),
214 new ParameterDefn("FixedTimeStep", "In simulation step, seconds of one substep (1/60)",
215 1f / 60f,
216 (s,cf,p,v) => { s.m_fixedTimeStep = cf.GetFloat(p, v); },
217 (s) => { return (float)s.m_fixedTimeStep; },
218 (s,p,l,v) => { s.m_fixedTimeStep = v; } ),
219 new ParameterDefn("NominalFrameRate", "The base frame rate we claim",
220 55f,
221 (s,cf,p,v) => { s.NominalFrameRate = cf.GetInt(p, (int)v); },
222 (s) => { return (float)s.NominalFrameRate; },
223 (s,p,l,v) => { s.NominalFrameRate = (int)v; } ),
224 new ParameterDefn("MaxCollisionsPerFrame", "Max collisions returned at end of each frame",
225 2048f,
226 (s,cf,p,v) => { s.m_maxCollisionsPerFrame = cf.GetInt(p, (int)v); },
227 (s) => { return (float)s.m_maxCollisionsPerFrame; },
228 (s,p,l,v) => { s.m_maxCollisionsPerFrame = (int)v; } ),
229 new ParameterDefn("MaxUpdatesPerFrame", "Max updates returned at end of each frame",
230 8000f,
231 (s,cf,p,v) => { s.m_maxUpdatesPerFrame = cf.GetInt(p, (int)v); },
232 (s) => { return (float)s.m_maxUpdatesPerFrame; },
233 (s,p,l,v) => { s.m_maxUpdatesPerFrame = (int)v; } ),
234 new ParameterDefn("MaxTaintsToProcessPerStep", "Number of update taints to process before each simulation step",
235 500f,
236 (s,cf,p,v) => { s.m_taintsToProcessPerStep = cf.GetInt(p, (int)v); },
237 (s) => { return (float)s.m_taintsToProcessPerStep; },
238 (s,p,l,v) => { s.m_taintsToProcessPerStep = (int)v; } ),
239 new ParameterDefn("MinObjectMass", "Minimum object mass (0.0001)",
240 0.0001f,
241 (s,cf,p,v) => { MinimumObjectMass = cf.GetFloat(p, v); },
242 (s) => { return (float)MinimumObjectMass; },
243 (s,p,l,v) => { MinimumObjectMass = v; } ),
244 new ParameterDefn("MaxObjectMass", "Maximum object mass (10000.01)",
245 10000.01f,
246 (s,cf,p,v) => { MaximumObjectMass = cf.GetFloat(p, v); },
247 (s) => { return (float)MaximumObjectMass; },
248 (s,p,l,v) => { MaximumObjectMass = v; } ),
249
250 new ParameterDefn("PID_D", "Derivitive factor for motion smoothing",
251 2200f,
252 (s,cf,p,v) => { PID_D = cf.GetFloat(p, v); },
253 (s) => { return (float)PID_D; },
254 (s,p,l,v) => { PID_D = v; } ),
255 new ParameterDefn("PID_P", "Parameteric factor for motion smoothing",
256 900f,
257 (s,cf,p,v) => { PID_P = cf.GetFloat(p, v); },
258 (s) => { return (float)PID_P; },
259 (s,p,l,v) => { PID_P = v; } ),
260
261 new ParameterDefn("DefaultFriction", "Friction factor used on new objects",
262 0.2f,
263 (s,cf,p,v) => { s.UnmanagedParams[0].defaultFriction = cf.GetFloat(p, v); },
264 (s) => { return s.UnmanagedParams[0].defaultFriction; },
265 (s,p,l,v) => { s.UnmanagedParams[0].defaultFriction = v; } ),
266 new ParameterDefn("DefaultDensity", "Density for new objects" ,
267 10.000006836f, // Aluminum g/cm3
268 (s,cf,p,v) => { s.UnmanagedParams[0].defaultDensity = cf.GetFloat(p, v); },
269 (s) => { return s.UnmanagedParams[0].defaultDensity; },
270 (s,p,l,v) => { s.UnmanagedParams[0].defaultDensity = v; } ),
271 new ParameterDefn("DefaultRestitution", "Bouncyness of an object" ,
272 0f,
273 (s,cf,p,v) => { s.UnmanagedParams[0].defaultRestitution = cf.GetFloat(p, v); },
274 (s) => { return s.UnmanagedParams[0].defaultRestitution; },
275 (s,p,l,v) => { s.UnmanagedParams[0].defaultRestitution = v; } ),
276 new ParameterDefn("CollisionMargin", "Margin around objects before collisions are calculated (must be zero!)",
277 0.04f,
278 (s,cf,p,v) => { s.UnmanagedParams[0].collisionMargin = cf.GetFloat(p, v); },
279 (s) => { return s.UnmanagedParams[0].collisionMargin; },
280 (s,p,l,v) => { s.UnmanagedParams[0].collisionMargin = v; } ),
281 new ParameterDefn("Gravity", "Vertical force of gravity (negative means down)",
282 -9.80665f,
283 (s,cf,p,v) => { s.UnmanagedParams[0].gravity = cf.GetFloat(p, v); },
284 (s) => { return s.UnmanagedParams[0].gravity; },
285 (s,p,l,v) => { s.UpdateParameterObject((x)=>{s.UnmanagedParams[0].gravity=x;}, p, PhysParameterEntry.APPLY_TO_NONE, v); },
286 (s,o,v) => { s.PE.SetGravity(o.PhysBody, new Vector3(0f,0f,v)); } ),
287
288
289 new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)",
290 0f,
291 (s,cf,p,v) => { LinearDamping = cf.GetFloat(p, v); },
292 (s) => { return LinearDamping; },
293 (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearDamping=x;}, p, l, v); },
294 (s,o,v) => { s.PE.SetDamping(o.PhysBody, v, AngularDamping); } ),
295 new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)",
296 0f,
297 (s,cf,p,v) => { AngularDamping = cf.GetFloat(p, v); },
298 (s) => { return AngularDamping; },
299 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularDamping=x;}, p, l, v); },
300 (s,o,v) => { s.PE.SetDamping(o.PhysBody, LinearDamping, v); } ),
301 new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static",
302 0.2f,
303 (s,cf,p,v) => { DeactivationTime = cf.GetFloat(p, v); },
304 (s) => { return DeactivationTime; },
305 (s,p,l,v) => { s.UpdateParameterObject((x)=>{DeactivationTime=x;}, p, l, v); },
306 (s,o,v) => { s.PE.SetDeactivationTime(o.PhysBody, v); } ),
307 new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static",
308 0.8f,
309 (s,cf,p,v) => { LinearSleepingThreshold = cf.GetFloat(p, v); },
310 (s) => { return LinearSleepingThreshold; },
311 (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearSleepingThreshold=x;}, p, l, v); },
312 (s,o,v) => { s.PE.SetSleepingThresholds(o.PhysBody, v, v); } ),
313 new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static",
314 1.0f,
315 (s,cf,p,v) => { AngularSleepingThreshold = cf.GetFloat(p, v); },
316 (s) => { return AngularSleepingThreshold; },
317 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularSleepingThreshold=x;}, p, l, v); },
318 (s,o,v) => { s.PE.SetSleepingThresholds(o.PhysBody, v, v); } ),
319 new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" ,
320 0f, // set to zero to disable
321 (s,cf,p,v) => { CcdMotionThreshold = cf.GetFloat(p, v); },
322 (s) => { return CcdMotionThreshold; },
323 (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdMotionThreshold=x;}, p, l, v); },
324 (s,o,v) => { s.PE.SetCcdMotionThreshold(o.PhysBody, v); } ),
325 new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" ,
326 0f,
327 (s,cf,p,v) => { CcdSweptSphereRadius = cf.GetFloat(p, v); },
328 (s) => { return CcdSweptSphereRadius; },
329 (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdSweptSphereRadius=x;}, p, l, v); },
330 (s,o,v) => { s.PE.SetCcdSweptSphereRadius(o.PhysBody, v); } ),
331 new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" ,
332 0.1f,
333 (s,cf,p,v) => { ContactProcessingThreshold = cf.GetFloat(p, v); },
334 (s) => { return ContactProcessingThreshold; },
335 (s,p,l,v) => { s.UpdateParameterObject((x)=>{ContactProcessingThreshold=x;}, p, l, v); },
336 (s,o,v) => { s.PE.SetContactProcessingThreshold(o.PhysBody, v); } ),
337
338 new ParameterDefn("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)",
339 (float)BSTerrainPhys.TerrainImplementation.Mesh,
340 (s,cf,p,v) => { TerrainImplementation = cf.GetFloat(p,v); },
341 (s) => { return TerrainImplementation; },
342 (s,p,l,v) => { TerrainImplementation = v; } ),
343 new ParameterDefn("TerrainFriction", "Factor to reduce movement against terrain surface" ,
344 0.3f,
345 (s,cf,p,v) => { TerrainFriction = cf.GetFloat(p, v); },
346 (s) => { return TerrainFriction; },
347 (s,p,l,v) => { TerrainFriction = v; /* TODO: set on real terrain */} ),
348 new ParameterDefn("TerrainHitFraction", "Distance to measure hit collisions" ,
349 0.8f,
350 (s,cf,p,v) => { TerrainHitFraction = cf.GetFloat(p, v); },
351 (s) => { return TerrainHitFraction; },
352 (s,p,l,v) => { TerrainHitFraction = v; /* TODO: set on real terrain */ } ),
353 new ParameterDefn("TerrainRestitution", "Bouncyness" ,
354 0f,
355 (s,cf,p,v) => { TerrainRestitution = cf.GetFloat(p, v); },
356 (s) => { return TerrainRestitution; },
357 (s,p,l,v) => { TerrainRestitution = v; /* TODO: set on real terrain */ } ),
358 new ParameterDefn("TerrainCollisionMargin", "Margin where collision checking starts" ,
359 0.04f,
360 (s,cf,p,v) => { TerrainCollisionMargin = cf.GetFloat(p, v); },
361 (s) => { return TerrainCollisionMargin; },
362 (s,p,l,v) => { TerrainCollisionMargin = v; /* TODO: set on real terrain */ } ),
363
364 new ParameterDefn("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.",
365 0.2f,
366 (s,cf,p,v) => { AvatarFriction = cf.GetFloat(p, v); },
367 (s) => { return AvatarFriction; },
368 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarFriction=x;}, p, l, v); } ),
369 new ParameterDefn("AvatarStandingFriction", "Avatar friction when standing. Changed on avatar recreation.",
370 10.0f,
371 (s,cf,p,v) => { AvatarStandingFriction = cf.GetFloat(p, v); },
372 (s) => { return AvatarStandingFriction; },
373 (s,p,l,v) => { AvatarStandingFriction = v; } ),
374 new ParameterDefn("AvatarAlwaysRunFactor", "Speed multiplier if avatar is set to always run",
375 1.3f,
376 (s,cf,p,v) => { AvatarAlwaysRunFactor = cf.GetFloat(p, v); },
377 (s) => { return AvatarAlwaysRunFactor; },
378 (s,p,l,v) => { AvatarAlwaysRunFactor = v; } ),
379 new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.",
380 3.5f,
381 (s,cf,p,v) => { AvatarDensity = cf.GetFloat(p, v); },
382 (s) => { return AvatarDensity; },
383 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarDensity=x;}, p, l, v); } ),
384 new ParameterDefn("AvatarRestitution", "Bouncyness. Changed on avatar recreation.",
385 0f,
386 (s,cf,p,v) => { AvatarRestitution = cf.GetFloat(p, v); },
387 (s) => { return AvatarRestitution; },
388 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarRestitution=x;}, p, l, v); } ),
389 new ParameterDefn("AvatarCapsuleWidth", "The distance between the sides of the avatar capsule",
390 0.6f,
391 (s,cf,p,v) => { AvatarCapsuleWidth = cf.GetFloat(p, v); },
392 (s) => { return AvatarCapsuleWidth; },
393 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarCapsuleWidth=x;}, p, l, v); } ),
394 new ParameterDefn("AvatarCapsuleDepth", "The distance between the front and back of the avatar capsule",
395 0.45f,
396 (s,cf,p,v) => { AvatarCapsuleDepth = cf.GetFloat(p, v); },
397 (s) => { return AvatarCapsuleDepth; },
398 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarCapsuleDepth=x;}, p, l, v); } ),
399 new ParameterDefn("AvatarCapsuleHeight", "Default height of space around avatar",
400 1.5f,
401 (s,cf,p,v) => { AvatarCapsuleHeight = cf.GetFloat(p, v); },
402 (s) => { return AvatarCapsuleHeight; },
403 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarCapsuleHeight=x;}, p, l, v); } ),
404 new ParameterDefn("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions",
405 0.1f,
406 (s,cf,p,v) => { AvatarContactProcessingThreshold = cf.GetFloat(p, v); },
407 (s) => { return AvatarContactProcessingThreshold; },
408 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarContactProcessingThreshold=x;}, p, l, v); } ),
409 new ParameterDefn("AvatarStepHeight", "Height of a step obstacle to consider step correction",
410 0.3f,
411 (s,cf,p,v) => { AvatarStepHeight = cf.GetFloat(p, v); },
412 (s) => { return AvatarStepHeight; },
413 (s,p,l,v) => { AvatarStepHeight = v; } ),
414 new ParameterDefn("AvatarStepApproachFactor", "Factor to control angle of approach to step (0=straight on)",
415 0.6f,
416 (s,cf,p,v) => { AvatarStepApproachFactor = cf.GetFloat(p, v); },
417 (s) => { return AvatarStepApproachFactor; },
418 (s,p,l,v) => { AvatarStepApproachFactor = v; } ),
419 new ParameterDefn("AvatarStepForceFactor", "Controls the amount of force up applied to step up onto a step",
420 2.0f,
421 (s,cf,p,v) => { AvatarStepForceFactor = cf.GetFloat(p, v); },
422 (s) => { return AvatarStepForceFactor; },
423 (s,p,l,v) => { AvatarStepForceFactor = v; } ),
424
425 new ParameterDefn("VehicleAngularDamping", "Factor to damp vehicle angular movement per second (0.0 - 1.0)",
426 0.95f,
427 (s,cf,p,v) => { VehicleAngularDamping = cf.GetFloat(p, v); },
428 (s) => { return VehicleAngularDamping; },
429 (s,p,l,v) => { VehicleAngularDamping = v; } ),
430
431 new ParameterDefn("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)",
432 0f,
433 (s,cf,p,v) => { s.UnmanagedParams[0].maxPersistantManifoldPoolSize = cf.GetFloat(p, v); },
434 (s) => { return s.UnmanagedParams[0].maxPersistantManifoldPoolSize; },
435 (s,p,l,v) => { s.UnmanagedParams[0].maxPersistantManifoldPoolSize = v; } ),
436 new ParameterDefn("MaxCollisionAlgorithmPoolSize", "Number of collisions pooled (0 means default of 4096)",
437 0f,
438 (s,cf,p,v) => { s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize = cf.GetFloat(p, v); },
439 (s) => { return s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize; },
440 (s,p,l,v) => { s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize = v; } ),
441 new ParameterDefn("ShouldDisableContactPoolDynamicAllocation", "Enable to allow large changes in object count",
442 ConfigurationParameters.numericFalse,
443 (s,cf,p,v) => { s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
444 (s) => { return s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation; },
445 (s,p,l,v) => { s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation = v; } ),
446 new ParameterDefn("ShouldForceUpdateAllAabbs", "Enable to recomputer AABBs every simulator step",
447 ConfigurationParameters.numericFalse,
448 (s,cf,p,v) => { s.UnmanagedParams[0].shouldForceUpdateAllAabbs = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
449 (s) => { return s.UnmanagedParams[0].shouldForceUpdateAllAabbs; },
450 (s,p,l,v) => { s.UnmanagedParams[0].shouldForceUpdateAllAabbs = v; } ),
451 new ParameterDefn("ShouldRandomizeSolverOrder", "Enable for slightly better stacking interaction",
452 ConfigurationParameters.numericTrue,
453 (s,cf,p,v) => { s.UnmanagedParams[0].shouldRandomizeSolverOrder = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
454 (s) => { return s.UnmanagedParams[0].shouldRandomizeSolverOrder; },
455 (s,p,l,v) => { s.UnmanagedParams[0].shouldRandomizeSolverOrder = v; } ),
456 new ParameterDefn("ShouldSplitSimulationIslands", "Enable splitting active object scanning islands",
457 ConfigurationParameters.numericTrue,
458 (s,cf,p,v) => { s.UnmanagedParams[0].shouldSplitSimulationIslands = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
459 (s) => { return s.UnmanagedParams[0].shouldSplitSimulationIslands; },
460 (s,p,l,v) => { s.UnmanagedParams[0].shouldSplitSimulationIslands = v; } ),
461 new ParameterDefn("ShouldEnableFrictionCaching", "Enable friction computation caching",
462 ConfigurationParameters.numericFalse,
463 (s,cf,p,v) => { s.UnmanagedParams[0].shouldEnableFrictionCaching = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
464 (s) => { return s.UnmanagedParams[0].shouldEnableFrictionCaching; },
465 (s,p,l,v) => { s.UnmanagedParams[0].shouldEnableFrictionCaching = v; } ),
466 new ParameterDefn("NumberOfSolverIterations", "Number of internal iterations (0 means default)",
467 0f, // zero says use Bullet default
468 (s,cf,p,v) => { s.UnmanagedParams[0].numberOfSolverIterations = cf.GetFloat(p, v); },
469 (s) => { return s.UnmanagedParams[0].numberOfSolverIterations; },
470 (s,p,l,v) => { s.UnmanagedParams[0].numberOfSolverIterations = v; } ),
471
472 new ParameterDefn("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)",
473 (float)BSLinkset.LinksetImplementation.Compound,
474 (s,cf,p,v) => { LinksetImplementation = cf.GetFloat(p,v); },
475 (s) => { return LinksetImplementation; },
476 (s,p,l,v) => { LinksetImplementation = v; } ),
477 new ParameterDefn("LinkConstraintUseFrameOffset", "For linksets built with constraints, enable frame offsetFor linksets built with constraints, enable frame offset.",
478 ConfigurationParameters.numericFalse,
479 (s,cf,p,v) => { LinkConstraintUseFrameOffset = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
480 (s) => { return LinkConstraintUseFrameOffset; },
481 (s,p,l,v) => { LinkConstraintUseFrameOffset = v; } ),
482 new ParameterDefn("LinkConstraintEnableTransMotor", "Whether to enable translational motor on linkset constraints",
483 ConfigurationParameters.numericTrue,
484 (s,cf,p,v) => { LinkConstraintEnableTransMotor = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
485 (s) => { return LinkConstraintEnableTransMotor; },
486 (s,p,l,v) => { LinkConstraintEnableTransMotor = v; } ),
487 new ParameterDefn("LinkConstraintTransMotorMaxVel", "Maximum velocity to be applied by translational motor in linkset constraints",
488 5.0f,
489 (s,cf,p,v) => { LinkConstraintTransMotorMaxVel = cf.GetFloat(p, v); },
490 (s) => { return LinkConstraintTransMotorMaxVel; },
491 (s,p,l,v) => { LinkConstraintTransMotorMaxVel = v; } ),
492 new ParameterDefn("LinkConstraintTransMotorMaxForce", "Maximum force to be applied by translational motor in linkset constraints",
493 0.1f,
494 (s,cf,p,v) => { LinkConstraintTransMotorMaxForce = cf.GetFloat(p, v); },
495 (s) => { return LinkConstraintTransMotorMaxForce; },
496 (s,p,l,v) => { LinkConstraintTransMotorMaxForce = v; } ),
497 new ParameterDefn("LinkConstraintCFM", "Amount constraint can be violated. 0=no violation, 1=infinite. Default=0.1",
498 0.1f,
499 (s,cf,p,v) => { LinkConstraintCFM = cf.GetFloat(p, v); },
500 (s) => { return LinkConstraintCFM; },
501 (s,p,l,v) => { LinkConstraintCFM = v; } ),
502 new ParameterDefn("LinkConstraintERP", "Amount constraint is corrected each tick. 0=none, 1=all. Default = 0.2",
503 0.1f,
504 (s,cf,p,v) => { LinkConstraintERP = cf.GetFloat(p, v); },
505 (s) => { return LinkConstraintERP; },
506 (s,p,l,v) => { LinkConstraintERP = v; } ),
507 new ParameterDefn("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)",
508 40,
509 (s,cf,p,v) => { LinkConstraintSolverIterations = cf.GetFloat(p, v); },
510 (s) => { return LinkConstraintSolverIterations; },
511 (s,p,l,v) => { LinkConstraintSolverIterations = v; } ),
512
513 new ParameterDefn("PhysicsMetricFrames", "Frames between outputting detailed phys metrics. (0 is off)",
514 0f,
515 (s,cf,p,v) => { s.PhysicsMetricDumpFrames = cf.GetFloat(p, (int)v); },
516 (s) => { return (float)s.PhysicsMetricDumpFrames; },
517 (s,p,l,v) => { s.PhysicsMetricDumpFrames = (int)v; } ),
518 new ParameterDefn("ResetBroadphasePool", "Setting this is any value resets the broadphase collision pool",
519 0f,
520 (s,cf,p,v) => { ; },
521 (s) => { return 0f; },
522 (s,p,l,v) => { BSParam.ResetBroadphasePoolTainted(s, v); } ),
523 new ParameterDefn("ResetConstraintSolver", "Setting this is any value resets the constraint solver",
524 0f,
525 (s,cf,p,v) => { ; },
526 (s) => { return 0f; },
527 (s,p,l,v) => { BSParam.ResetConstraintSolverTainted(s, v); } ),
528 };
529
530 // Convert a boolean to our numeric true and false values
531 public static float NumericBool(bool b)
532 {
533 return (b ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse);
534 }
535
536 // Convert numeric true and false values to a boolean
537 public static bool BoolNumeric(float b)
538 {
539 return (b == ConfigurationParameters.numericTrue ? true : false);
540 }
541
542 private static void ResetBroadphasePoolTainted(BSScene pPhysScene, float v)
543 {
544 BSScene physScene = pPhysScene;
545 physScene.TaintedObject("BSParam.ResetBroadphasePoolTainted", delegate()
546 {
547 physScene.PE.ResetBroadphasePool(physScene.World);
548 });
549 }
550
551 private static void ResetConstraintSolverTainted(BSScene pPhysScene, float v)
552 {
553 BSScene physScene = pPhysScene;
554 physScene.TaintedObject("BSParam.ResetConstraintSolver", delegate()
555 {
556 physScene.PE.ResetConstraintSolver(physScene.World);
557 });
558 }
559
560 // Search through the parameter definitions and return the matching
561 // ParameterDefn structure.
562 // Case does not matter as names are compared after converting to lower case.
563 // Returns 'false' if the parameter is not found.
564 internal static bool TryGetParameter(string paramName, out ParameterDefn defn)
565 {
566 bool ret = false;
567 ParameterDefn foundDefn = new ParameterDefn();
568 string pName = paramName.ToLower();
569
570 foreach (ParameterDefn parm in ParameterDefinitions)
571 {
572 if (pName == parm.name.ToLower())
573 {
574 foundDefn = parm;
575 ret = true;
576 break;
577 }
578 }
579 defn = foundDefn;
580 return ret;
581 }
582
583 // Pass through the settable parameters and set the default values
584 internal static void SetParameterDefaultValues(BSScene physicsScene)
585 {
586 foreach (ParameterDefn parm in ParameterDefinitions)
587 {
588 parm.setter(physicsScene, parm.name, PhysParameterEntry.APPLY_TO_NONE, parm.defaultValue);
589 }
590 }
591
592 // Get user set values out of the ini file.
593 internal static void SetParameterConfigurationValues(BSScene physicsScene, IConfig cfg)
594 {
595 foreach (ParameterDefn parm in ParameterDefinitions)
596 {
597 parm.userParam(physicsScene, cfg, parm.name, parm.defaultValue);
598 }
599 }
600
601 internal static PhysParameterEntry[] SettableParameters = new PhysParameterEntry[1];
602
603 // This creates an array in the correct format for returning the list of
604 // parameters. This is used by the 'list' option of the 'physics' command.
605 internal static void BuildParameterTable()
606 {
607 if (SettableParameters.Length < ParameterDefinitions.Length)
608 {
609 List<PhysParameterEntry> entries = new List<PhysParameterEntry>();
610 for (int ii = 0; ii < ParameterDefinitions.Length; ii++)
611 {
612 ParameterDefn pd = ParameterDefinitions[ii];
613 entries.Add(new PhysParameterEntry(pd.name, pd.desc));
614 }
615
616 // make the list in alphabetical order for estetic reasons
617 entries.Sort(delegate(PhysParameterEntry ppe1, PhysParameterEntry ppe2)
618 {
619 return ppe1.name.CompareTo(ppe2.name);
620 });
621
622 SettableParameters = entries.ToArray();
623 }
624 }
625
626
627}
628}