BulletSim: prims with no cuts created with single convex hull shape.

Parameter added to enable/disable this feature.
user_profiles
Robert Adams 2013-05-02 12:27:30 -07:00
parent d9c3947824
commit 4042c82a72
4 changed files with 99 additions and 2 deletions

View File

@ -87,6 +87,7 @@ public static class BSParam
public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects
public static bool ShouldRemoveZeroWidthTriangles { get; private set; }
public static bool ShouldUseBulletHACD { get; set; }
public static bool ShouldUseSingleConvexHullForPrims { get; set; }
public static float TerrainImplementation { get; private set; }
public static int TerrainMeshMagnification { get; private set; }
@ -342,6 +343,10 @@ public static class BSParam
false,
(s) => { return ShouldUseBulletHACD; },
(s,v) => { ShouldUseBulletHACD = v; } ),
new ParameterDefn<bool>("ShouldUseSingleConvexHullForPrims", "If true, use a single convex hull shape for physical prims",
true,
(s) => { return ShouldUseSingleConvexHullForPrims; },
(s,v) => { ShouldUseSingleConvexHullForPrims = v; } ),
new ParameterDefn<int>("CrossingFailuresBeforeOutOfBounds", "How forgiving we are about getting into adjactent regions",
5,

View File

@ -316,7 +316,10 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
break;
case "bulletxna":
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);
BSParam.ShouldUseBulletHACD = false;
BSParam.ShouldUseSingleConvexHullForPrims = false;
break;
}

View File

@ -226,8 +226,23 @@ public sealed class BSShapeCollection : IDisposable
// made. Native shapes work in either case.
if (prim.IsPhysical && BSParam.ShouldUseHullsForPhysicalObjects)
{
// Update prim.BSShape to reference a hull of this shape.
BSShape potentialHull = BSShapeHull.GetReference(m_physicsScene, false /*forceRebuild*/, prim);
// Use a simple, single mesh convex hull shape if the object is simple enough
BSShape potentialHull = null;
PrimitiveBaseShape pbs = prim.BaseShape;
if (BSParam.ShouldUseSingleConvexHullForPrims
&& pbs != null
&& !pbs.SculptEntry
&& PrimHasNoCuts(pbs)
)
{
potentialHull = BSShapeConvexHull.GetReference(m_physicsScene, false /* forceRebuild */, prim);
}
else
{
potentialHull = BSShapeHull.GetReference(m_physicsScene, false /*forceRebuild*/, prim);
}
// If the current shape is not what is on the prim at the moment, time to change.
if (!prim.PhysShape.HasPhysicalShape
|| potentialHull.ShapeType != prim.PhysShape.ShapeType

View File

@ -831,6 +831,80 @@ public class BSShapeCompound : BSShape
}
}
// ============================================================================================================
public class BSShapeConvexHull : BSShape
{
private static string LogHeader = "[BULLETSIM SHAPE CONVEX HULL]";
public static Dictionary<System.UInt64, BSShapeConvexHull> ConvexHulls = new Dictionary<System.UInt64, BSShapeConvexHull>();
public BSShapeConvexHull(BulletShape pShape) : base(pShape)
{
}
public static BSShape GetReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
{
float lod;
System.UInt64 newMeshKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod);
physicsScene.DetailLog("{0},BSShapeMesh,getReference,newKey={1},size={2},lod={3}",
prim.LocalID, newMeshKey.ToString("X"), prim.Size, lod);
BSShapeConvexHull retConvexHull = null;
lock (ConvexHulls)
{
if (ConvexHulls.TryGetValue(newMeshKey, out retConvexHull))
{
// The mesh has already been created. Return a new reference to same.
retConvexHull.IncrementReference();
}
else
{
retConvexHull = new BSShapeConvexHull(new BulletShape());
BulletShape convexShape = null;
// Get a handle to a mesh to build the hull from
BSShape baseMesh = BSShapeMesh.GetReference(physicsScene, false /* forceRebuild */, prim);
if (baseMesh.physShapeInfo.isNativeShape)
{
// We get here if the mesh was not creatable. Could be waiting for an asset from the disk.
// In the short term, we return the native shape and a later ForceBodyShapeRebuild should
// get back to this code with a buildable mesh.
// TODO: not sure the temp native shape is freed when the mesh is rebuilt. When does this get freed?
convexShape = baseMesh.physShapeInfo;
}
else
{
convexShape = physicsScene.PE.BuildConvexHullShapeFromMesh(physicsScene.World, baseMesh.physShapeInfo);
convexShape.shapeKey = newMeshKey;
ConvexHulls.Add(convexShape.shapeKey, retConvexHull);
}
// Done with the base mesh
baseMesh.Dereference(physicsScene);
retConvexHull.physShapeInfo = convexShape;
}
}
return retConvexHull;
}
public override BSShape GetReference(BSScene physicsScene, BSPhysObject prim)
{
// Calling this reference means we want another handle to an existing shape
// (usually linksets) so return this copy.
IncrementReference();
return this;
}
// Dereferencing a compound shape releases the hold on all the child shapes.
public override void Dereference(BSScene physicsScene)
{
lock (ConvexHulls)
{
this.DecrementReference();
physicsScene.DetailLog("{0},BSShapeConvexHull.Dereference,shape={1}", BSScene.DetailLogZero, this);
// TODO: schedule aging and destruction of unused meshes.
}
}
}
// ============================================================================================================
public class BSShapeAvatar : BSShape
{