BulletSim: add Bullet HACD library invocation. Turned off by default as not

totally debugged. Updated DLLs and SOs with more debugged HACD library code.
user_profiles
Robert Adams 2013-04-09 16:32:54 -07:00
parent 17fd075f39
commit 59135c9a31
7 changed files with 190 additions and 101 deletions

View File

@ -86,6 +86,7 @@ public static class BSParam
public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes
public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects 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 ShouldRemoveZeroWidthTriangles { get; private set; }
public static bool ShouldUseBulletHACD { get; set; }
public static float TerrainImplementation { get; private set; } public static float TerrainImplementation { get; private set; }
public static int TerrainMeshMagnification { get; private set; } public static int TerrainMeshMagnification { get; private set; }
@ -149,6 +150,15 @@ public static class BSParam
public static float CSHullVolumeConservationThresholdPercent { get; private set; } public static float CSHullVolumeConservationThresholdPercent { get; private set; }
public static int CSHullMaxVertices { get; private set; } public static int CSHullMaxVertices { get; private set; }
public static float CSHullMaxSkinWidth { get; private set; } public static float CSHullMaxSkinWidth { get; private set; }
public static float BHullMaxVerticesPerHull { get; private set; } // 100
public static float BHullMinClusters { get; private set; } // 2
public static float BHullCompacityWeight { get; private set; } // 0.1
public static float BHullVolumeWeight { get; private set; } // 0.0
public static float BHullConcavity { get; private set; } // 100
public static bool BHullAddExtraDistPoints { get; private set; } // false
public static bool BHullAddNeighboursDistPoints { get; private set; } // false
public static bool BHullAddFacesPoints { get; private set; } // false
public static bool BHullShouldAdjustCollisionMargin { get; private set; } // false
// Linkset implementation parameters // Linkset implementation parameters
public static float LinksetImplementation { get; private set; } public static float LinksetImplementation { get; private set; }
@ -325,6 +335,10 @@ public static class BSParam
true, true,
(s) => { return ShouldRemoveZeroWidthTriangles; }, (s) => { return ShouldRemoveZeroWidthTriangles; },
(s,v) => { ShouldRemoveZeroWidthTriangles = v; } ), (s,v) => { ShouldRemoveZeroWidthTriangles = v; } ),
new ParameterDefn<bool>("ShouldUseBulletHACD", "If true, use the Bullet version of HACD",
false,
(s) => { return ShouldUseBulletHACD; },
(s,v) => { ShouldUseBulletHACD = v; } ),
new ParameterDefn<int>("CrossingFailuresBeforeOutOfBounds", "How forgiving we are about getting into adjactent regions", new ParameterDefn<int>("CrossingFailuresBeforeOutOfBounds", "How forgiving we are about getting into adjactent regions",
5, 5,
@ -663,10 +677,47 @@ public static class BSParam
(s) => { return CSHullMaxVertices; }, (s) => { return CSHullMaxVertices; },
(s,v) => { CSHullMaxVertices = v; } ), (s,v) => { CSHullMaxVertices = v; } ),
new ParameterDefn<float>("CSHullMaxSkinWidth", "CS impl: skin width to apply to output hulls.", new ParameterDefn<float>("CSHullMaxSkinWidth", "CS impl: skin width to apply to output hulls.",
0, 0f,
(s) => { return CSHullMaxSkinWidth; }, (s) => { return CSHullMaxSkinWidth; },
(s,v) => { CSHullMaxSkinWidth = v; } ), (s,v) => { CSHullMaxSkinWidth = v; } ),
new ParameterDefn<float>("BHullMaxVerticesPerHull", "Bullet impl: max number of vertices per created hull",
100f,
(s) => { return BHullMaxVerticesPerHull; },
(s,v) => { BHullMaxVerticesPerHull = v; } ),
new ParameterDefn<float>("BHullMinClusters", "Bullet impl: minimum number of hulls to create per mesh",
2f,
(s) => { return BHullMinClusters; },
(s,v) => { BHullMinClusters = v; } ),
new ParameterDefn<float>("BHullCompacityWeight", "Bullet impl: weight factor for how compact to make hulls",
2f,
(s) => { return BHullCompacityWeight; },
(s,v) => { BHullCompacityWeight = v; } ),
new ParameterDefn<float>("BHullVolumeWeight", "Bullet impl: weight factor for volume in created hull",
0.1f,
(s) => { return BHullVolumeWeight; },
(s,v) => { BHullVolumeWeight = v; } ),
new ParameterDefn<float>("BHullConcavity", "Bullet impl: weight factor for how convex a created hull can be",
100f,
(s) => { return BHullConcavity; },
(s,v) => { BHullConcavity = v; } ),
new ParameterDefn<bool>("BHullAddExtraDistPoints", "Bullet impl: whether to add extra vertices for long distance vectors",
false,
(s) => { return BHullAddExtraDistPoints; },
(s,v) => { BHullAddExtraDistPoints = v; } ),
new ParameterDefn<bool>("BHullAddNeighboursDistPoints", "Bullet impl: whether to add extra vertices between neighbor hulls",
false,
(s) => { return BHullAddNeighboursDistPoints; },
(s,v) => { BHullAddNeighboursDistPoints = v; } ),
new ParameterDefn<bool>("BHullAddFacesPoints", "Bullet impl: whether to add extra vertices to break up hull faces",
false,
(s) => { return BHullAddFacesPoints; },
(s,v) => { BHullAddFacesPoints = v; } ),
new ParameterDefn<bool>("BHullShouldAdjustCollisionMargin", "Bullet impl: whether to shrink resulting hulls to account for collision margin",
false,
(s) => { return BHullShouldAdjustCollisionMargin; },
(s,v) => { BHullShouldAdjustCollisionMargin = v; } ),
new ParameterDefn<float>("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)", new ParameterDefn<float>("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)",
(float)BSLinkset.LinksetImplementation.Compound, (float)BSLinkset.LinksetImplementation.Compound,
(s) => { return LinksetImplementation; }, (s) => { return LinksetImplementation; },

View File

@ -316,6 +316,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
break; break;
case "bulletxna": case "bulletxna":
ret = new BSAPIXNA(engineName, this); ret = new BSAPIXNA(engineName, this);
BSParam.ShouldUseBulletHACD = false;
break; break;
} }

View File

@ -720,7 +720,7 @@ public sealed class BSShapeCollection : IDisposable
// Remove usage of the previous shape. // Remove usage of the previous shape.
DereferenceShape(prim.PhysShape, shapeCallback); DereferenceShape(prim.PhysShape, shapeCallback);
newShape = CreatePhysicalHull(prim.PhysObjectName, newHullKey, prim.BaseShape, prim.Size, lod); newShape = CreatePhysicalHull(prim, newHullKey, prim.BaseShape, prim.Size, lod);
// It might not have been created if we're waiting for an asset. // It might not have been created if we're waiting for an asset.
newShape = VerifyMeshCreated(newShape, prim); newShape = VerifyMeshCreated(newShape, prim);
@ -731,7 +731,7 @@ public sealed class BSShapeCollection : IDisposable
} }
List<ConvexResult> m_hulls; List<ConvexResult> m_hulls;
private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) private BulletShape CreatePhysicalHull(BSPhysObject prim, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
{ {
BulletShape newShape = new BulletShape(); BulletShape newShape = new BulletShape();
@ -744,13 +744,50 @@ public sealed class BSShapeCollection : IDisposable
newShape = hullDesc.shape.Clone(); newShape = hullDesc.shape.Clone();
} }
else else
{
if (BSParam.ShouldUseBulletHACD)
{
DetailLog("{0},BSShapeCollection.CreatePhysicalHull,shouldUseBulletHACD,entry", prim.LocalID);
MeshDesc meshDesc;
if (!Meshes.TryGetValue(newHullKey, out meshDesc))
{
// That's odd because the mesh should have been created before the hull
// but, since it doesn't exist, create it.
newShape = CreatePhysicalMesh(prim, newHullKey, prim.BaseShape, prim.Size, lod);
DetailLog("{0},BSShapeCollection.CreatePhysicalHull,noMeshBuiltNew,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape);
if (newShape.HasPhysicalShape)
{
ReferenceShape(newShape);
Meshes.TryGetValue(newHullKey, out meshDesc);
}
}
if (meshDesc.shape.HasPhysicalShape)
{
HACDParams parms;
parms.maxVerticesPerHull = BSParam.BHullMaxVerticesPerHull;
parms.minClusters = BSParam.BHullMinClusters;
parms.compacityWeight = BSParam.BHullCompacityWeight;
parms.volumeWeight = BSParam.BHullVolumeWeight;
parms.concavity = BSParam.BHullConcavity;
parms.addExtraDistPoints = BSParam.NumericBool(BSParam.BHullAddExtraDistPoints);
parms.addNeighboursDistPoints = BSParam.NumericBool(BSParam.BHullAddNeighboursDistPoints);
parms.addFacesPoints = BSParam.NumericBool(BSParam.BHullAddFacesPoints);
parms.shouldAdjustCollisionMargin = BSParam.NumericBool(BSParam.BHullShouldAdjustCollisionMargin);
DetailLog("{0},BSShapeCollection.CreatePhysicalHull,hullFromMesh,beforeCall", prim.LocalID, newShape.HasPhysicalShape);
newShape = PhysicsScene.PE.BuildHullShapeFromMesh(PhysicsScene.World, meshDesc.shape, parms);
DetailLog("{0},BSShapeCollection.CreatePhysicalHull,hullFromMesh,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape);
}
DetailLog("{0},BSShapeCollection.CreatePhysicalHull,shouldUseBulletHACD,exit,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape);
}
if (!newShape.HasPhysicalShape)
{ {
// Build a new hull in the physical world. // Build a new hull in the physical world.
// Pass true for physicalness as this prevents the creation of bounding box which is not needed // Pass true for physicalness as this prevents the creation of bounding box which is not needed
IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true /* isPhysical */, false /* shouldCache */); IMesh meshData = PhysicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, true /* isPhysical */, false /* shouldCache */);
if (meshData != null) if (meshData != null)
{ {
int[] indices = meshData.getIndexListAsInt(); int[] indices = meshData.getIndexListAsInt();
List<OMV.Vector3> vertices = meshData.getVertexList(); List<OMV.Vector3> vertices = meshData.getVertexList();
@ -852,8 +889,8 @@ public sealed class BSShapeCollection : IDisposable
newShape = PhysicsScene.PE.CreateHullShape(PhysicsScene.World, hullCount, convHulls); newShape = PhysicsScene.PE.CreateHullShape(PhysicsScene.World, hullCount, convHulls);
} }
} }
newShape.shapeKey = newHullKey; newShape.shapeKey = newHullKey;
}
return newShape; return newShape;
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.