BulletSim: add terrain contact processing threshold parameter. Initialize contact processing threshold for static object as well as mesh terrain.

user_profiles
Robert Adams 2013-03-17 18:44:09 -07:00
parent 397379cd3f
commit 8510f57ad4
4 changed files with 23 additions and 1 deletions

View File

@ -39,6 +39,20 @@ public static class BSParam
{ {
private static string LogHeader = "[BULLETSIM PARAMETERS]"; private static string LogHeader = "[BULLETSIM PARAMETERS]";
// Tuning notes:
// From: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=6575
// Contact points can be added even if the distance is positive. The constraint solver can deal with
// contacts with positive distances as well as negative (penetration). Contact points are discarded
// if the distance exceeds a certain threshold.
// Bullet has a contact processing threshold and a contact breaking threshold.
// If the distance is larger than the contact breaking threshold, it will be removed after one frame.
// If the distance is larger than the contact processing threshold, the constraint solver will ignore it.
// This is separate/independent from the collision margin. The collision margin increases the object a bit
// to improve collision detection performance and accuracy.
// ===================
// From:
// Level of Detail values kept as float because that's what the Meshmerizer wants // Level of Detail values kept as float because that's what the Meshmerizer wants
public static float MeshLOD { get; private set; } public static float MeshLOD { get; private set; }
public static float MeshCircularLOD { get; private set; } public static float MeshCircularLOD { get; private set; }
@ -77,6 +91,7 @@ public static class BSParam
public static float TerrainFriction { get; private set; } public static float TerrainFriction { get; private set; }
public static float TerrainHitFraction { get; private set; } public static float TerrainHitFraction { get; private set; }
public static float TerrainRestitution { get; private set; } public static float TerrainRestitution { get; private set; }
public static float TerrainContactProcessingThreshold { get; private set; }
public static float TerrainCollisionMargin { get; private set; } public static float TerrainCollisionMargin { get; private set; }
public static float DefaultFriction { get; private set; } public static float DefaultFriction { get; private set; }
@ -458,6 +473,10 @@ public static class BSParam
0f, 0f,
(s) => { return TerrainRestitution; }, (s) => { return TerrainRestitution; },
(s,v) => { TerrainRestitution = v; /* TODO: set on real terrain */ } ), (s,v) => { TerrainRestitution = v; /* TODO: set on real terrain */ } ),
new ParameterDefn<float>("TerrainContactProcessingThreshold", "Distance from terrain to stop processing collisions" ,
0.0f,
(s) => { return TerrainContactProcessingThreshold; },
(s,v) => { TerrainContactProcessingThreshold = v; /* TODO: set on real terrain */ } ),
new ParameterDefn<float>("TerrainCollisionMargin", "Margin where collision checking starts" , new ParameterDefn<float>("TerrainCollisionMargin", "Margin where collision checking starts" ,
0.08f, 0.08f,
(s) => { return TerrainCollisionMargin; }, (s) => { return TerrainCollisionMargin; },

View File

@ -947,9 +947,9 @@ public class BSPrim : BSPhysObject
ZeroMotion(true); ZeroMotion(true);
// Set various physical properties so other object interact properly // Set various physical properties so other object interact properly
MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false);
PhysicsScene.PE.SetFriction(PhysBody, Friction); PhysicsScene.PE.SetFriction(PhysBody, Friction);
PhysicsScene.PE.SetRestitution(PhysBody, Restitution); PhysicsScene.PE.SetRestitution(PhysBody, Restitution);
PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold);
// Mass is zero which disables a bunch of physics stuff in Bullet // Mass is zero which disables a bunch of physics stuff in Bullet
UpdatePhysicalMassProperties(0f, false); UpdatePhysicalMassProperties(0f, false);

View File

@ -263,6 +263,7 @@ public sealed class BSTerrainManager : IDisposable
if (MegaRegionParentPhysicsScene == null) if (MegaRegionParentPhysicsScene == null)
{ {
// This terrain is not part of the mega-region scheme. Create vanilla terrain.
BSTerrainPhys newTerrainPhys = BuildPhysicalTerrain(terrainRegionBase, id, heightMap, minCoords, maxCoords); BSTerrainPhys newTerrainPhys = BuildPhysicalTerrain(terrainRegionBase, id, heightMap, minCoords, maxCoords);
m_terrains.Add(terrainRegionBase, newTerrainPhys); m_terrains.Add(terrainRegionBase, newTerrainPhys);

View File

@ -112,11 +112,13 @@ public sealed class BSTerrainMesh : BSTerrainPhys
// Something is very messed up and a crash is in our future. // Something is very messed up and a crash is in our future.
return; return;
} }
physicsScene.PE.SetShapeCollisionMargin(m_terrainShape, BSParam.TerrainCollisionMargin);
// Set current terrain attributes // Set current terrain attributes
PhysicsScene.PE.SetFriction(m_terrainBody, BSParam.TerrainFriction); PhysicsScene.PE.SetFriction(m_terrainBody, BSParam.TerrainFriction);
PhysicsScene.PE.SetHitFraction(m_terrainBody, BSParam.TerrainHitFraction); PhysicsScene.PE.SetHitFraction(m_terrainBody, BSParam.TerrainHitFraction);
PhysicsScene.PE.SetRestitution(m_terrainBody, BSParam.TerrainRestitution); PhysicsScene.PE.SetRestitution(m_terrainBody, BSParam.TerrainRestitution);
PhysicsScene.PE.SetContactProcessingThreshold(m_terrainBody, BSParam.TerrainContactProcessingThreshold);
PhysicsScene.PE.SetCollisionFlags(m_terrainBody, CollisionFlags.CF_STATIC_OBJECT); PhysicsScene.PE.SetCollisionFlags(m_terrainBody, CollisionFlags.CF_STATIC_OBJECT);
// Static objects are not very massive. // Static objects are not very massive.