From 45f37e11ad6e9a9917a6ea07ec52dec9058393f0 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 13 May 2013 08:40:24 -0700 Subject: [PATCH 1/3] BulletSim: use heightmap terrain when using BulletXNA. Output messages on features disabled when using BulletXNA. --- OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 2 +- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 3ca7e160ce..55044785ef 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -90,7 +90,7 @@ public static class BSParam public static bool ShouldUseBulletHACD { get; set; } public static bool ShouldUseSingleConvexHullForPrims { get; set; } - public static float TerrainImplementation { get; private set; } + public static float TerrainImplementation { get; set; } public static int TerrainMeshMagnification { get; private set; } public static float TerrainFriction { get; private set; } public static float TerrainHitFraction { get; private set; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index a4a87943a3..3f407ce71a 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -318,8 +318,12 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters ret = new BSAPIXNA(engineName, this); // Disable some features that are not implemented in BulletXNA m_log.InfoFormat("{0} Disabling some physics features not implemented by BulletXNA", LogHeader); + m_log.InfoFormat("{0} Disabling ShouldUseBulletHACD", LogHeader); BSParam.ShouldUseBulletHACD = false; + m_log.InfoFormat("{0} Disabling ShouldUseSingleConvexHullForPrims", LogHeader); BSParam.ShouldUseSingleConvexHullForPrims = false; + m_log.InfoFormat("{0} Setting terrain implimentation to Heightmap", LogHeader); + BSParam.TerrainImplementation = (float)BSTerrainPhys.TerrainImplementation.Heightmap; break; } From 15360cbb6ba83e40f474cca84082c908af49c58e Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 13 May 2013 13:03:13 -0700 Subject: [PATCH 2/3] BulletSim: add adjustment for avatar capsule height scaling. Makes avatar standing on ground view better and enables tuning. --- .../Physics/BulletSPlugin/BSCharacter.cs | 27 ++++++++++++++++--- .../Region/Physics/BulletSPlugin/BSParam.cs | 9 +++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 542f732365..3671fc2f28 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) Contributors, http://opensimulator.org/ * See CONTRIBUTORS.TXT for a full list of copyright holders. * @@ -649,12 +649,12 @@ public sealed class BSCharacter : BSPhysObject OMV.Vector3 newScale; // Bullet's capsule total height is the "passed height + radius * 2"; - // The base capsule is 1 diameter and 2 height (passed radius=0.5, passed height = 1) + // The base capsule is 1 unit in diameter and 2 units in height (passed radius=0.5, passed height = 1) // The number we pass in for 'scaling' is the multiplier to get that base // shape to be the size desired. // So, when creating the scale for the avatar height, we take the passed height // (size.Z) and remove the caps. - // Another oddity of the Bullet capsule implementation is that it presumes the Y + // An oddity of the Bullet capsule implementation is that it presumes the Y // dimension is the radius of the capsule. Even though some of the code allows // for a asymmetrical capsule, other parts of the code presume it is cylindrical. @@ -662,8 +662,27 @@ public sealed class BSCharacter : BSPhysObject newScale.X = size.X / 2f; newScale.Y = size.Y / 2f; + float heightAdjust = BSParam.AvatarHeightMidFudge; + if (BSParam.AvatarHeightLowFudge != 0f || BSParam.AvatarHeightHighFudge != 0f) + { + // An avatar is between 1.61 and 2.12 meters. Midpoint is 1.87m. + // The "times 4" relies on the fact that the difference from the midpoint to the extremes is exactly 0.25 + float midHeightOffset = size.Z - 1.87f; + if (midHeightOffset < 0f) + { + // Small avatar. Add the adjustment based on the distance from midheight + heightAdjust += -1f * midHeightOffset * 4f * BSParam.AvatarHeightLowFudge; + } + else + { + // Large avatar. Add the adjustment based on the distance from midheight + heightAdjust += midHeightOffset * 4f * BSParam.AvatarHeightHighFudge; + } + } // The total scale height is the central cylindar plus the caps on the two ends. - newScale.Z = (size.Z + (Math.Min(size.X, size.Y) * 2)) / 2f; + newScale.Z = (size.Z + (Math.Min(size.X, size.Y) * 2) + heightAdjust) / 2f; + // m_log.DebugFormat("{0} ComputeAvatarScale: size={1},adj={2},scale={3}", LogHeader, size, heightAdjust, newScale); + // If smaller than the endcaps, just fake like we're almost that small if (newScale.Z < 0) newScale.Z = 0.1f; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 55044785ef..d33292fe50 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -125,6 +125,9 @@ public static class BSParam public static float AvatarCapsuleWidth { get; private set; } public static float AvatarCapsuleDepth { get; private set; } public static float AvatarCapsuleHeight { get; private set; } + public static float AvatarHeightLowFudge { get; private set; } + public static float AvatarHeightMidFudge { get; private set; } + public static float AvatarHeightHighFudge { get; private set; } public static float AvatarContactProcessingThreshold { get; private set; } public static float AvatarBelowGroundUpCorrectionMeters { get; private set; } public static float AvatarStepHeight { get; private set; } @@ -539,6 +542,12 @@ public static class BSParam 0.45f ), new ParameterDefn("AvatarCapsuleHeight", "Default height of space around avatar", 1.5f ), + new ParameterDefn("AvatarHeightLowFudge", "A fudge factor to make small avatars stand on the ground", + -0.2f ), + new ParameterDefn("AvatarHeightMidFudge", "A fudge distance to adjust average sized avatars to be standing on ground", + 0.1f ), + new ParameterDefn("AvatarHeightHighFudge", "A fudge factor to make tall avatars stand on the ground", + 0.1f ), new ParameterDefn("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions", 0.1f ), new ParameterDefn("AvatarBelowGroundUpCorrectionMeters", "Meters to move avatar up if it seems to be below ground", From c86e828dbfed8b9cf72c7e7e8d1dad0c0e9f8940 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 13 May 2013 13:05:27 -0700 Subject: [PATCH 3/3] BulletSim: add a lock to try and catch a native shape creation/destruction race condition. --- OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs index 262d734916..72d039bc25 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs @@ -283,8 +283,13 @@ public class BSShapeNative : BSShape public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) { // Native shapes are not shared so we return a new shape. - return new BSShapeNative(CreatePhysicalNativeShape(pPhysicsScene, pPrim, - physShapeInfo.shapeType, (FixedShapeKey)physShapeInfo.shapeKey) ); + BSShape ret = null; + lock (physShapeInfo) + { + ret = new BSShapeNative(CreatePhysicalNativeShape(pPhysicsScene, pPrim, + physShapeInfo.shapeType, (FixedShapeKey)physShapeInfo.shapeKey)); + } + return ret; } // Make this reference to the physical shape go away since native shapes are not shared.