From 19417fca41e59e931193ee99d3e4a12092488f1f Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 7 Aug 2012 17:15:06 -0700 Subject: BulletSim: Added avatar capsule scaling for size of avatar. This also fixes computation of avatar mass. Added parameter MaxPersistantManifoldPoolSize. Fixed a parameter setting bug which caused crashes of there were more than 400 or so physical objects. I tested up to 5000. Updated BulletSim DLLs and SOs. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 41 ++++++++++++++++++---- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 8 ++--- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 11 ++++-- .../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 1 + 4 files changed, 47 insertions(+), 14 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index ee485b4..d4f5c63 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -102,7 +102,9 @@ public class BSCharacter : PhysicsActor _orientation = Quaternion.Identity; _velocity = Vector3.Zero; _buoyancy = ComputeBuoyancyFromFlying(isFlying); - _scale = new Vector3(1f, 1f, 1f); + // The dimensions of the avatar capsule are kept in the scale. + // Physics creates a unit capsule which is scaled by the physics engine. + _scale = new Vector3(_scene.Params.avatarCapsuleRadius, _scene.Params.avatarCapsuleRadius, size.Z); _density = _scene.Params.avatarDensity; ComputeAvatarVolumeAndMass(); // set _avatarVolume and _mass based on capsule size, _density and _scale @@ -150,9 +152,28 @@ public class BSCharacter : PhysicsActor public override bool Stopped { get { return false; } } - public override Vector3 Size { - get { return _size; } - set { _size = value; + public override Vector3 Size { + get + { + // Avatar capsule size is kept in the scale parameter. + return new Vector3(_scale.X * 2, _scale.Y * 2, _scale.Z); + } + + set { + // When an avatar's size is set, only the height is changed + // and that really only depends on the radius. + _size = value; + _scale.Z = (_size.Z * 1.15f) - (_scale.X + _scale.Y); + + // TODO: something has to be done with the avatar's vertical position + + ComputeAvatarVolumeAndMass(); + + _scene.TaintedObject(delegate() + { + BulletSimAPI.SetObjectScaleMass(_scene.WorldID, LocalID, _scale, _mass, true); + }); + } } public override PrimitiveBaseShape Shape { @@ -419,9 +440,15 @@ public class BSCharacter : PhysicsActor { _avatarVolume = (float)( Math.PI - * _scene.Params.avatarCapsuleRadius * _scale.X - * _scene.Params.avatarCapsuleRadius * _scale.Y - * _scene.Params.avatarCapsuleHeight * _scale.Z); + * _scale.X + * _scale.Y // the area of capsule cylinder + * _scale.Z // times height of capsule cylinder + + 1.33333333f + * Math.PI + * _scale.X + * Math.Min(_scale.X, _scale.Y) + * _scale.Y // plus the volume of the capsule end caps + ); _mass = _density * _avatarVolume; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 8e6685b..11868bc 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -977,8 +977,8 @@ public sealed class BSPrim : PhysicsActor { if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1) { - if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z) - { + // if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z) + // { // m_log.DebugFormat("{0}: CreateGeom: Defaulting to sphere of size {1}", LogHeader, _size); if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_SPHERE)) { @@ -989,7 +989,7 @@ public sealed class BSPrim : PhysicsActor // TODO: do we need to check for and destroy a mesh or hull that might have been left from before? ret = true; } - } + // } } else { @@ -1039,7 +1039,7 @@ public sealed class BSPrim : PhysicsActor // if this new shape is the same as last time, don't recreate the mesh if (_meshKey == newMeshKey) return; - DetailLog("{0},CreateGeomMesh,create,key={1}", LocalID, _meshKey); + DetailLog("{0},CreateGeomMesh,create,key={1}", LocalID, newMeshKey); // Since we're recreating new, get rid of any previously generated shape if (_meshKey != 0) { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 7151908..0e257b6 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -1027,14 +1027,19 @@ public class BSScene : PhysicsScene, IPhysicsParameters (s,p,l,v) => { s.UpdateParameterAvatars(ref s.m_params[0].avatarContactProcessingThreshold, p, l, v); } ), - new ParameterDefn("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default)", + new ParameterDefn("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)", 0f, // zero to disable (s,cf,p,v) => { s.m_params[0].maxPersistantManifoldPoolSize = cf.GetFloat(p, v); }, (s) => { return s.m_params[0].maxPersistantManifoldPoolSize; }, (s,p,l,v) => { s.m_params[0].maxPersistantManifoldPoolSize = v; } ), + new ParameterDefn("MaxCollisionAlgorithmPoolSize", "Number of collisions pooled (0 means default of 4096)", + 0f, // zero to disable + (s,cf,p,v) => { s.m_params[0].maxCollisionAlgorithmPoolSize = cf.GetFloat(p, v); }, + (s) => { return s.m_params[0].maxCollisionAlgorithmPoolSize; }, + (s,p,l,v) => { s.m_params[0].maxCollisionAlgorithmPoolSize = v; } ), new ParameterDefn("ShouldDisableContactPoolDynamicAllocation", "Enable to allow large changes in object count", - ConfigurationParameters.numericTrue, - (s,cf,p,v) => { s.m_params[0].maxPersistantManifoldPoolSize = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, + ConfigurationParameters.numericFalse, + (s,cf,p,v) => { s.m_params[0].shouldDisableContactPoolDynamicAllocation = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, (s) => { return s.m_params[0].shouldDisableContactPoolDynamicAllocation; }, (s,p,l,v) => { s.m_params[0].shouldDisableContactPoolDynamicAllocation = v; } ), new ParameterDefn("ShouldForceUpdateAllAabbs", "Enable to recomputer AABBs every simulator step", diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index 4e05df6..86fc9d2 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs @@ -158,6 +158,7 @@ public struct ConfigurationParameters public float avatarContactProcessingThreshold; public float maxPersistantManifoldPoolSize; + public float maxCollisionAlgorithmPoolSize; public float shouldDisableContactPoolDynamicAllocation; public float shouldForceUpdateAllAabbs; public float shouldRandomizeSolverOrder; -- cgit v1.1