optimize culling for large point count
This commit is contained in:
parent
938681a52e
commit
5986b5b565
7 changed files with 189 additions and 112 deletions
|
|
@ -23,6 +23,8 @@ static const char* s_bodyKeys[e_ghostBodyCount] = { "box", "capsule", "upright",
|
|||
|
||||
#define MAX_CONFIGS 256
|
||||
|
||||
static bool s_recycling = true;
|
||||
|
||||
typedef struct Config
|
||||
{
|
||||
GhostScene scene;
|
||||
|
|
@ -97,6 +99,11 @@ static void RunConfig( Config* config, GhostSettings settings, int stepCount, bo
|
|||
|
||||
b3WorldDef worldDef = b3DefaultWorldDef();
|
||||
b3WorldId worldId = b3CreateWorld( &worldDef );
|
||||
if ( s_recycling == false )
|
||||
{
|
||||
b3World_SetContactRecycleDistance( worldId, 0.0f );
|
||||
}
|
||||
|
||||
GhostCollisionsData data = CreateGhostCollisions( worldId, settings );
|
||||
|
||||
for ( int step = 0; step < stepCount; ++step )
|
||||
|
|
@ -355,6 +362,10 @@ int main( int argc, char** argv )
|
|||
{
|
||||
settings.speculative = false;
|
||||
}
|
||||
else if ( strcmp( arg, "--no-recycling" ) == 0 )
|
||||
{
|
||||
s_recycling = false;
|
||||
}
|
||||
else if ( strcmp( arg, "--height-field" ) == 0 )
|
||||
{
|
||||
settings.heightField = true;
|
||||
|
|
@ -382,6 +393,7 @@ int main( int argc, char** argv )
|
|||
" -c, --compare=<file> compare with a written csv, fail if any count grew or has no row\n"
|
||||
" --speed=, --yaw=, --friction=, --cell=, --fixed-rotation, --no-speculative\n"
|
||||
" --height-field height field ground, one static body per height field\n"
|
||||
" --no-recycling disable contact recycling\n"
|
||||
" -v, --verbose print every ghost\n"
|
||||
"Exit code is 1 when a compared count grew or has no row, 0 otherwise.\n" );
|
||||
return 2;
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ typedef struct Soak
|
|||
int shapeFilter;
|
||||
|
||||
bool fixedSeed;
|
||||
bool recycling;
|
||||
|
||||
int completedCount;
|
||||
int failureCount;
|
||||
|
|
@ -109,6 +110,11 @@ static int RunGeneration( Soak* soak, int generation, uint32_t seed, MeshDropSha
|
|||
b3WorldId worldId = b3CreateWorld( &worldDef );
|
||||
b3UnlockMutex( soak->mutex );
|
||||
|
||||
if ( soak->recycling == false )
|
||||
{
|
||||
b3World_SetContactRecycleDistance( worldId, 0.0f );
|
||||
}
|
||||
|
||||
CreateMeshDropGround( worldId, soak->groundMesh );
|
||||
|
||||
MeshDropSettings settings = soak->settings;
|
||||
|
|
@ -467,6 +473,7 @@ int main( int argc, char** argv )
|
|||
int shapeFilter = e_meshDropBox;
|
||||
uint32_t seed = (uint32_t)b3GetTicks();
|
||||
bool fixedSeed = false;
|
||||
bool recycling = true;
|
||||
const char* writePath = NULL;
|
||||
const char* comparePath = NULL;
|
||||
MeshDropSettings settings = GetDefaultMeshDropSettings();
|
||||
|
|
@ -527,6 +534,10 @@ int main( int argc, char** argv )
|
|||
{
|
||||
comparePath = value;
|
||||
}
|
||||
else if ( strcmp( arg, "--no-recycling" ) == 0 )
|
||||
{
|
||||
recycling = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "Usage: mesh_soak [options]\n"
|
||||
|
|
@ -541,6 +552,7 @@ int main( int argc, char** argv )
|
|||
" -a, --amplitude=<float> wave amplitude (default 0.5)\n"
|
||||
" -w, --write=<csv> write the counts as a baseline, replacing only the rows of this run\n"
|
||||
" -c, --compare=<csv> compare the counts with the baseline rows from the same -s, -b and -g\n"
|
||||
" --no-recycling disable contact recycling\n"
|
||||
"Exit code is 0 when every generation passes and no count grew past noise, 1 otherwise,\n"
|
||||
"2 for bad arguments or a baseline from a different run.\n",
|
||||
MESH_DROP_BODY_COUNT );
|
||||
|
|
@ -557,6 +569,7 @@ int main( int argc, char** argv )
|
|||
Soak soak = { 0 };
|
||||
soak.mutex = b3CreateMutex();
|
||||
soak.settings = settings;
|
||||
soak.recycling = recycling;
|
||||
soak.groundMesh = CreateMeshDropMesh( settings.amplitude );
|
||||
soak.cylinder = CreateMeshDropCylinder();
|
||||
soak.baseSeed = seed;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
filter,base,generations,shape,tunnels,awake,depth4,depth8,depth16,depth32
|
||||
all,12345,1000,box,0,0,1544,220,4,0
|
||||
all,12345,1000,capsule,0,0,14505,3487,28,0
|
||||
all,12345,1000,cylinder,0,0,11228,2355,37,0
|
||||
all,12345,1000,box,0,0,1539,220,4,0
|
||||
all,12345,1000,capsule,0,0,14507,3488,28,0
|
||||
all,12345,1000,cylinder,0,0,11211,2354,37,0
|
||||
all,12345,1000,sphere,0,0,56,0,0,0
|
||||
all,12345,16000,box,0,0,23648,3205,46,0
|
||||
all,12345,16000,capsule,0,0,231483,54547,515,0
|
||||
all,12345,16000,cylinder,0,0,179103,37448,485,0
|
||||
all,12345,16000,box,0,0,23679,3193,45,0
|
||||
all,12345,16000,capsule,0,0,231497,54551,515,0
|
||||
all,12345,16000,cylinder,0,0,178988,37442,480,0
|
||||
all,12345,16000,sphere,0,0,987,0,0,0
|
||||
|
|
|
|||
|
67
src/hull.c
67
src/hull.c
|
|
@ -399,7 +399,8 @@ static void b3FindFarthestPointsAlongCardinalAxes( int* index1Out, int* index2Ou
|
|||
}
|
||||
}
|
||||
|
||||
static int b3FindFarthestPointFromLine( int index1, int index2, float tolerance, int vertexCount, const b3Vec3* vertexBase )
|
||||
static int b3FindFarthestPointFromLine( int index1, int index2, float tolerance, int vertexCount,
|
||||
const b3Vec3* vertexBase )
|
||||
{
|
||||
b3Vec3 a = vertexBase[index1];
|
||||
b3Vec3 b = vertexBase[index2];
|
||||
|
|
@ -765,7 +766,8 @@ static void b3HullBuilder_RecacheConflicts( b3QHFace* face, float minOutside )
|
|||
b3QHVertex* maxVertex = NULL;
|
||||
float maxDistance = minOutside;
|
||||
|
||||
for ( b3QHListNode* node = face->conflictListHead.link.next; node != &face->conflictListHead.link; node = node->next )
|
||||
for ( b3QHListNode* node = face->conflictListHead.link.next; node != &face->conflictListHead.link;
|
||||
node = node->next )
|
||||
{
|
||||
b3QHVertex* vertex = (b3QHVertex*)node;
|
||||
float distance = b3PlaneSeparation( face->plane, vertex->position );
|
||||
|
|
@ -785,7 +787,8 @@ static b3QHVertex* b3HullBuilder_NextConflictVertex( const b3HullBuilder* b )
|
|||
b3QHVertex* maxVertex = NULL;
|
||||
float maxDistance = b->minOutside;
|
||||
|
||||
for ( const b3QHListNode* faceNode = b->faceList.link.next; faceNode != &b->faceList.link; faceNode = faceNode->next )
|
||||
for ( const b3QHListNode* faceNode = b->faceList.link.next; faceNode != &b->faceList.link;
|
||||
faceNode = faceNode->next )
|
||||
{
|
||||
const b3QHFace* face = (const b3QHFace*)faceNode;
|
||||
if ( face->maxConflict != NULL && face->maxConflictDistance > maxDistance )
|
||||
|
|
@ -818,7 +821,8 @@ static void b3HullBuilder_DrainConflictList( b3HullBuilder* b, b3QHFace* face )
|
|||
// `entryEdge` is the half-edge in `face` whose twin lies in the just-deleted parent face, or
|
||||
// NULL for the seed. The frame skips `entryEdge` on recursive entries (it would be ignored
|
||||
// anyway since the parent's mark is now DELETE, but skipping saves one iteration).
|
||||
static void b3HullBuilder_EnterHorizonFace( b3HullBuilder* b, b3QHFace* face, b3QHHalfEdge* entryEdge, b3HorizonFrame* frameOut )
|
||||
static void b3HullBuilder_EnterHorizonFace( b3HullBuilder* b, b3QHFace* face, b3QHHalfEdge* entryEdge,
|
||||
b3HorizonFrame* frameOut )
|
||||
{
|
||||
face->mark = B3_MARK_DELETE;
|
||||
b3HullBuilder_DrainConflictList( b, face );
|
||||
|
|
@ -1358,7 +1362,8 @@ static bool b3HullBuilder_IsConsistent( const b3HullBuilder* b )
|
|||
return false;
|
||||
}
|
||||
|
||||
for ( const b3QHListNode* faceNode = b->faceList.link.next; faceNode != &b->faceList.link; faceNode = faceNode->next )
|
||||
for ( const b3QHListNode* faceNode = b->faceList.link.next; faceNode != &b->faceList.link;
|
||||
faceNode = faceNode->next )
|
||||
{
|
||||
const b3QHFace* face = (const b3QHFace*)faceNode;
|
||||
if ( face->edge->face != face )
|
||||
|
|
@ -1428,8 +1433,8 @@ static bool b3HullBuilder_HasHull( const b3HullBuilder* b )
|
|||
}
|
||||
|
||||
// Build the entire hull. Returns true iff the result satisfies Euler's identity.
|
||||
static bool b3HullBuilder_Construct( b3HullBuilder* b, const b3Vec3* points, int pointCount, int maxVertexCount, b3Vec3 origin,
|
||||
b3Vec3* shiftedPoints )
|
||||
static bool b3HullBuilder_Construct( b3HullBuilder* b, const b3Vec3* points, int pointCount, int maxVertexCount,
|
||||
b3Vec3 origin, b3Vec3* shiftedPoints )
|
||||
{
|
||||
if ( pointCount < 4 )
|
||||
{
|
||||
|
|
@ -2196,7 +2201,8 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou
|
|||
int faceCount = 0;
|
||||
int edgeCount = 0;
|
||||
|
||||
for ( b3QHListNode* faceNode = builder.faceList.link.next; faceNode != &builder.faceList.link; faceNode = faceNode->next )
|
||||
for ( b3QHListNode* faceNode = builder.faceList.link.next; faceNode != &builder.faceList.link;
|
||||
faceNode = faceNode->next )
|
||||
{
|
||||
B3_ASSERT( faceCount < B3_HULL_MAX_COUNT );
|
||||
|
||||
|
|
@ -3099,7 +3105,7 @@ int b3SimplifyHull2D( b3Point2D* hull, int count1, int target )
|
|||
return count2;
|
||||
}
|
||||
|
||||
// todo comment
|
||||
// Comparator for sorting points for the 2D hull.
|
||||
static inline bool b3IsPoint2DLess( const b3Point2D* a, const b3Point2D* b )
|
||||
{
|
||||
if ( a->p.x != b->p.x )
|
||||
|
|
@ -3149,7 +3155,7 @@ static int b3Weld2D( b3Point2D* pts, int count1 )
|
|||
return count2;
|
||||
}
|
||||
|
||||
// todo comment
|
||||
// Only merge points that line up exactly.
|
||||
static int b3MergeExact2D( b3Point2D* pts, int count1 )
|
||||
{
|
||||
float separationTol = B3_LINEAR_SLOP;
|
||||
|
|
@ -3185,13 +3191,13 @@ int b3Hull2D( b3Point2D* pts, int count, b3Point2D* hull, int flags )
|
|||
}
|
||||
|
||||
#define LESS( i, j ) b3IsPoint2DLess( pts + (int)( i ), pts + (int)( j ) )
|
||||
#define SWAP( i, j ) \
|
||||
do \
|
||||
{ \
|
||||
b3Point2D swapPoint = pts[(int)( i )]; \
|
||||
pts[(int)( i )] = pts[(int)( j )]; \
|
||||
pts[(int)( j )] = swapPoint; \
|
||||
} \
|
||||
#define SWAP( i, j ) \
|
||||
do \
|
||||
{ \
|
||||
b3Point2D swapPoint = pts[(int)( i )]; \
|
||||
pts[(int)( i )] = pts[(int)( j )]; \
|
||||
pts[(int)( j )] = swapPoint; \
|
||||
} \
|
||||
while ( 0 )
|
||||
|
||||
QSORT( count, LESS, SWAP );
|
||||
|
|
@ -3199,7 +3205,16 @@ int b3Hull2D( b3Point2D* pts, int count, b3Point2D* hull, int flags )
|
|||
#undef LESS
|
||||
#undef SWAP
|
||||
|
||||
int count1 = ( flags & b3_hull2DExactMerge ) ? b3MergeExact2D( pts, count ) : b3Weld2D( pts, count );
|
||||
int count1;
|
||||
if ( flags & b3_hull2DExactMerge )
|
||||
{
|
||||
count1 = b3MergeExact2D( pts, count );
|
||||
}
|
||||
else
|
||||
{
|
||||
b3Weld2D( pts, count );
|
||||
}
|
||||
|
||||
bool keepCollinear = ( flags & b3_hull2DKeepCollinear ) != 0;
|
||||
|
||||
int count2 = 0;
|
||||
|
|
@ -3233,8 +3248,6 @@ int b3Hull2D( b3Point2D* pts, int count, b3Point2D* hull, int flags )
|
|||
}
|
||||
|
||||
int lowerCount = count2 + 1;
|
||||
|
||||
// todo comment
|
||||
int lowerIndex = count2 - 2;
|
||||
|
||||
for ( int i = count1 - 2; i >= 0; i-- )
|
||||
|
|
@ -3273,13 +3286,13 @@ int b3Hull2D( b3Point2D* pts, int count, b3Point2D* hull, int flags )
|
|||
if ( flags & b3_hull2DIndexOrder )
|
||||
{
|
||||
#define LESS( i, j ) ( hull[(int)( i )].originalIndex < hull[(int)( j )].originalIndex )
|
||||
#define SWAP( i, j ) \
|
||||
do \
|
||||
{ \
|
||||
b3Point2D swapPoint = hull[(int)( i )]; \
|
||||
hull[(int)( i )] = hull[(int)( j )]; \
|
||||
hull[(int)( j )] = swapPoint; \
|
||||
} \
|
||||
#define SWAP( i, j ) \
|
||||
do \
|
||||
{ \
|
||||
b3Point2D swapPoint = hull[(int)( i )]; \
|
||||
hull[(int)( i )] = hull[(int)( j )]; \
|
||||
hull[(int)( j )] = swapPoint; \
|
||||
} \
|
||||
while ( 0 )
|
||||
|
||||
QSORT( count2, LESS, SWAP );
|
||||
|
|
|
|||
24
src/mesh.c
24
src/mesh.c
|
|
@ -1231,11 +1231,11 @@ static b3VertexRingEntry b3EncodeRingEntry( b3Vec3 direction, b3Vec3 tangent1, b
|
|||
float yaw = b3Atan2( y, x );
|
||||
float tilt = b3Atan2( z, sqrtf( x * x + y * y ) );
|
||||
|
||||
// todo comment
|
||||
// Quantize yaw and tilt for compressed storage.
|
||||
return ( b3VertexRingEntry ){ b3QuantizeEdgeAngle( yaw ), b3QuantizeEdgeAngle( 2.0f * tilt ) };
|
||||
}
|
||||
|
||||
// todo comment
|
||||
// Decompress yaw and tilt and get the cosine and sine.
|
||||
static b3Vec3 b3DecodeRingEntry( b3VertexRingEntry entry )
|
||||
{
|
||||
b3CosSin yaw = b3GetQuantizedCosSin( 2 * entry.yaw );
|
||||
|
|
@ -1345,18 +1345,18 @@ bool b3IsInMeshVertexRing( const b3Mesh* mesh, int triangleIndex, int vertexInde
|
|||
|
||||
// todo comment
|
||||
b3Vec3 scale = mesh->scale;
|
||||
b3Vec3 edgeScale, wallScale;
|
||||
b3Vec3 edgeScale, boundaryScale;
|
||||
b3Vec3 absScale = b3Abs( scale );
|
||||
bool uniform = absScale.y == absScale.x && absScale.z == absScale.x;
|
||||
if ( uniform )
|
||||
{
|
||||
edgeScale = ( b3Vec3 ){ scale.x < 0.0f ? -1.0f : 1.0f, scale.y < 0.0f ? -1.0f : 1.0f, scale.z < 0.0f ? -1.0f : 1.0f };
|
||||
wallScale = edgeScale;
|
||||
boundaryScale = edgeScale;
|
||||
}
|
||||
else
|
||||
{
|
||||
edgeScale = scale;
|
||||
wallScale = ( b3Vec3 ){ 1.0f / scale.x, 1.0f / scale.y, 1.0f / scale.z };
|
||||
boundaryScale = ( b3Vec3 ){ 1.0f / scale.x, 1.0f / scale.y, 1.0f / scale.z };
|
||||
}
|
||||
|
||||
const int* starts = (const int*)( (intptr_t)data + data->vertexRingOffset );
|
||||
|
|
@ -1367,7 +1367,7 @@ bool b3IsInMeshVertexRing( const b3Mesh* mesh, int triangleIndex, int vertexInde
|
|||
const b3Vec3* vertices = b3GetMeshVertices( data );
|
||||
b3Vec3 faceNormal =
|
||||
b3MakeNormalFromPoints( vertices[triangle.index1], vertices[triangle.index2], vertices[triangle.index3] );
|
||||
faceNormal = b3Normalize( b3Mul( wallScale, faceNormal ) );
|
||||
faceNormal = b3Normalize( b3Mul( boundaryScale, faceNormal ) );
|
||||
float cosAngle = b3Dot( normal, faceNormal );
|
||||
return cosAngle > 0.0f && cosAngle * cosAngle >= 1.0f - tolerance * tolerance;
|
||||
}
|
||||
|
|
@ -1382,21 +1382,21 @@ bool b3IsInMeshVertexRing( const b3Mesh* mesh, int triangleIndex, int vertexInde
|
|||
b3MakeRingFrame( axis, &tangent1, &tangent2 );
|
||||
|
||||
b3Vec3 edgeNormal = b3Mul( edgeScale, normal );
|
||||
b3Vec3 wallNormal = b3Mul( wallScale, normal );
|
||||
b3Vec3 boundaryNormal = b3Mul( boundaryScale, normal );
|
||||
b3Vec3 localEdgeNormal = { b3Dot( edgeNormal, tangent1 ), b3Dot( edgeNormal, tangent2 ), b3Dot( edgeNormal, axis ) };
|
||||
b3Vec3 localWallNormal = { b3Dot( wallNormal, tangent1 ), b3Dot( wallNormal, tangent2 ), b3Dot( wallNormal, axis ) };
|
||||
b3Vec3 localBoundaryNormal = { b3Dot( boundaryNormal, tangent1 ), b3Dot( boundaryNormal, tangent2 ), b3Dot( boundaryNormal, axis ) };
|
||||
|
||||
for ( int i = 0; i < entryCount; ++i )
|
||||
{
|
||||
bool isWall = i >= edgeCount;
|
||||
bool isBoundary = i >= edgeCount;
|
||||
b3Vec3 direction = b3DecodeRingEntry( entries[i] );
|
||||
float lean = b3Dot( isWall ? localWallNormal : localEdgeNormal, direction );
|
||||
float lean = b3Dot( isBoundary ? localBoundaryNormal : localEdgeNormal, direction );
|
||||
|
||||
float limit = tolerance;
|
||||
if ( uniform == false )
|
||||
{
|
||||
b3Vec3 meshDirection = b3MulAdd( b3MulAdd( b3MulSV( direction.x, tangent1 ), direction.y, tangent2 ), direction.z, axis );
|
||||
limit *= b3Length( b3Mul( isWall ? wallScale : edgeScale, meshDirection ) );
|
||||
limit *= b3Length( b3Mul( isBoundary ? boundaryScale : edgeScale, meshDirection ) );
|
||||
}
|
||||
|
||||
if ( lean > limit )
|
||||
|
|
@ -1667,7 +1667,7 @@ static void b3IdentifyEdges( b3MeshData* mesh )
|
|||
B3_FREE( edges, b3MeshEdge, edgeCount );
|
||||
}
|
||||
|
||||
// todo comment
|
||||
// Build the ring of neighbor normal data at a vertex.
|
||||
static int b3BuildVertexRing( const b3MeshData* mesh, const int* fan, int fanCount, int vertex, int* stamps, int stamp,
|
||||
b3VertexRing* ring )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -169,7 +169,33 @@ static inline bool b3IsBetterCullCandidate( float score, float separation, float
|
|||
return separation < bestSeparation - separationTol;
|
||||
}
|
||||
|
||||
static int b3CullPoints( b3Point2D* points, int count )
|
||||
// todo comment
|
||||
static int b3FindFarthestCullPoint( const b3Point2D* points, int count, int index, float scoreTol, float separationTol )
|
||||
{
|
||||
b3Vec2 origin = points[index].p;
|
||||
float bestScore = 0.0f;
|
||||
float bestSeparation = FLT_MAX;
|
||||
int bestIndex = B3_NULL_INDEX;
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
if ( i == index )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float score = b3DistanceSquared2( origin, points[i].p );
|
||||
if ( b3IsBetterCullCandidate( score, points[i].separation, bestScore, bestSeparation, scoreTol, separationTol ) )
|
||||
{
|
||||
bestIndex = i;
|
||||
bestScore = score;
|
||||
bestSeparation = points[i].separation;
|
||||
}
|
||||
}
|
||||
|
||||
return bestIndex;
|
||||
}
|
||||
|
||||
static int b3CullPoints( b3Point2D* points, int count, bool sweep )
|
||||
{
|
||||
if ( count <= 1 )
|
||||
{
|
||||
|
|
@ -181,29 +207,55 @@ static int b3CullPoints( b3Point2D* points, int count )
|
|||
float separationTol = B3_LINEAR_SLOP;
|
||||
|
||||
b3Point2D finalPoints[4];
|
||||
int count1 = count;
|
||||
|
||||
// Step 1: the two points with the largest distance, ties broken by deepest combined separation
|
||||
float bestScore = 0.0f;
|
||||
float bestSeparation = FLT_MAX;
|
||||
int bestIndex1 = B3_NULL_INDEX;
|
||||
int bestIndex2 = B3_NULL_INDEX;
|
||||
|
||||
for ( int i = 0; i < count1; ++i )
|
||||
if ( sweep )
|
||||
{
|
||||
b3Vec2 p1 = points[i].p;
|
||||
for ( int j = i + 1; j < count1; ++j )
|
||||
// todo comment
|
||||
b3Vec2 axis = { 0.92106099f, 0.38941834f };
|
||||
int startIndex = 0;
|
||||
float startScore = b3Dot2( axis, points[0].p );
|
||||
float startSeparation = points[0].separation;
|
||||
for ( int i = 1; i < count; ++i )
|
||||
{
|
||||
float score = b3DistanceSquared2( p1, points[j].p );
|
||||
// Separation sum heuristic
|
||||
float separation = points[i].separation + points[j].separation;
|
||||
|
||||
if ( b3IsBetterCullCandidate( score, separation, bestScore, bestSeparation, tolSqr, separationTol ) )
|
||||
float score = b3Dot2( axis, points[i].p );
|
||||
if ( b3IsBetterCullCandidate( score, points[i].separation, startScore, startSeparation, tol, separationTol ) )
|
||||
{
|
||||
bestIndex1 = i;
|
||||
bestIndex2 = j;
|
||||
bestScore = score;
|
||||
bestSeparation = separation;
|
||||
startIndex = i;
|
||||
startScore = score;
|
||||
startSeparation = points[i].separation;
|
||||
}
|
||||
}
|
||||
|
||||
bestIndex1 = b3FindFarthestCullPoint( points, count, startIndex, tolSqr, separationTol );
|
||||
B3_ASSERT( bestIndex1 != B3_NULL_INDEX );
|
||||
bestIndex2 = b3FindFarthestCullPoint( points, count, bestIndex1, tolSqr, separationTol );
|
||||
B3_ASSERT( bestIndex2 != B3_NULL_INDEX );
|
||||
bestScore = b3DistanceSquared2( points[bestIndex1].p, points[bestIndex2].p );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Step 1: the two points with the largest distance, ties broken by deepest combined separation
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
b3Vec2 p1 = points[i].p;
|
||||
for ( int j = i + 1; j < count; ++j )
|
||||
{
|
||||
float score = b3DistanceSquared2( p1, points[j].p );
|
||||
// Separation sum heuristic
|
||||
float separation = points[i].separation + points[j].separation;
|
||||
|
||||
if ( b3IsBetterCullCandidate( score, separation, bestScore, bestSeparation, tolSqr, separationTol ) )
|
||||
{
|
||||
bestIndex1 = i;
|
||||
bestIndex2 = j;
|
||||
bestScore = score;
|
||||
bestSeparation = separation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -212,7 +264,7 @@ static int b3CullPoints( b3Point2D* points, int count )
|
|||
{
|
||||
// Choose deepest point
|
||||
int deepestIndex = 0;
|
||||
for ( int i = 1; i < count1; ++i )
|
||||
for ( int i = 1; i < count; ++i )
|
||||
{
|
||||
if ( points[i].separation < points[deepestIndex].separation )
|
||||
{
|
||||
|
|
@ -230,12 +282,7 @@ static int b3CullPoints( b3Point2D* points, int count )
|
|||
finalPoints[0] = points[bestIndex1];
|
||||
finalPoints[1] = points[bestIndex2];
|
||||
|
||||
// Cull
|
||||
points[bestIndex2] = points[count1 - 1];
|
||||
points[bestIndex1] = points[count1 - 2];
|
||||
count1 -= 2;
|
||||
|
||||
if ( count1 == 0 )
|
||||
if ( count == 2 )
|
||||
{
|
||||
points[0] = finalPoints[0];
|
||||
points[1] = finalPoints[1];
|
||||
|
|
@ -254,10 +301,16 @@ static int b3CullPoints( b3Point2D* points, int count )
|
|||
// Step 2: find the point with the maximum triangular area, ties broken by deepest separation
|
||||
bestScore = 0.0f;
|
||||
bestSeparation = FLT_MAX;
|
||||
int bestIndex = B3_NULL_INDEX;
|
||||
int bestIndex3 = B3_NULL_INDEX;
|
||||
float bestSignedArea = 0.0f;
|
||||
for ( int i = 0; i < count1; ++i )
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
// todo comment
|
||||
if ( i == bestIndex1 || i == bestIndex2 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
b3Vec2 p = points[i].p;
|
||||
float signedArea = b3Cross2( ba, b3Sub2( p, a ) );
|
||||
float score = b3AbsFloat( signedArea );
|
||||
|
|
@ -267,11 +320,11 @@ static int b3CullPoints( b3Point2D* points, int count )
|
|||
bestSignedArea = signedArea;
|
||||
bestScore = score;
|
||||
bestSeparation = points[i].separation;
|
||||
bestIndex = i;
|
||||
bestIndex3 = i;
|
||||
}
|
||||
}
|
||||
|
||||
if ( bestIndex == B3_NULL_INDEX )
|
||||
if ( bestIndex3 == B3_NULL_INDEX )
|
||||
{
|
||||
// All points collinear
|
||||
points[0] = finalPoints[0];
|
||||
|
|
@ -280,9 +333,9 @@ static int b3CullPoints( b3Point2D* points, int count )
|
|||
}
|
||||
|
||||
// Store best point
|
||||
finalPoints[2] = points[bestIndex];
|
||||
finalPoints[2] = points[bestIndex3];
|
||||
|
||||
if ( count1 == 1 )
|
||||
if ( count == 3 )
|
||||
{
|
||||
points[0] = finalPoints[0];
|
||||
points[1] = finalPoints[1];
|
||||
|
|
@ -290,10 +343,6 @@ static int b3CullPoints( b3Point2D* points, int count )
|
|||
return 3;
|
||||
}
|
||||
|
||||
// Cull
|
||||
points[bestIndex] = points[count1 - 1];
|
||||
count1 -= 1;
|
||||
|
||||
// Step 4: get the point that adds the most area outside the current triangle
|
||||
|
||||
// Third anchor
|
||||
|
|
@ -311,9 +360,14 @@ static int b3CullPoints( b3Point2D* points, int count )
|
|||
|
||||
bestScore = 0.0f;
|
||||
bestSeparation = FLT_MAX;
|
||||
bestIndex = B3_NULL_INDEX;
|
||||
for ( int i = 0; i < count1; ++i )
|
||||
int bestIndex4 = B3_NULL_INDEX;
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
if ( i == bestIndex1 || i == bestIndex2 || i == bestIndex3 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
b3Vec2 p = points[i].p;
|
||||
float u1 = b3Cross2( b3Sub2( p, a ), ba );
|
||||
float u2 = b3Cross2( b3Sub2( p, b ), cb );
|
||||
|
|
@ -325,11 +379,11 @@ static int b3CullPoints( b3Point2D* points, int count )
|
|||
{
|
||||
bestScore = score;
|
||||
bestSeparation = points[i].separation;
|
||||
bestIndex = i;
|
||||
bestIndex4 = i;
|
||||
}
|
||||
}
|
||||
|
||||
if ( bestIndex == B3_NULL_INDEX )
|
||||
if ( bestIndex4 == B3_NULL_INDEX )
|
||||
{
|
||||
// No additional area
|
||||
points[0] = finalPoints[0];
|
||||
|
|
@ -339,7 +393,7 @@ static int b3CullPoints( b3Point2D* points, int count )
|
|||
}
|
||||
|
||||
// Store best point
|
||||
finalPoints[3] = points[bestIndex];
|
||||
finalPoints[3] = points[bestIndex4];
|
||||
|
||||
// Full quad
|
||||
points[0] = finalPoints[0];
|
||||
|
|
@ -350,7 +404,10 @@ static int b3CullPoints( b3Point2D* points, int count )
|
|||
}
|
||||
|
||||
// todo comment
|
||||
#define B3_CULL_HULL_THRESHOLD 64
|
||||
#define B3_CULL_FILTER_THRESHOLD 64
|
||||
|
||||
// todo comment
|
||||
#define B3_CULL_SWEEP_THRESHOLD 256
|
||||
|
||||
// todo comment
|
||||
static int b3DropInteriorPoints( b3Point2D* points, int count, float margin )
|
||||
|
|
@ -456,33 +513,15 @@ static int b3ReduceCluster( b3LocalManifoldPoint* points, int count1, b3Vec3 nor
|
|||
#if B3_MAX_MANIFOLD_POINTS == 4
|
||||
b3Point2D* hull = pts;
|
||||
int count2;
|
||||
if ( count1 <= B3_CULL_HULL_THRESHOLD )
|
||||
if ( count1 <= B3_CULL_FILTER_THRESHOLD )
|
||||
{
|
||||
count2 = b3CullPoints( pts, count1 );
|
||||
count2 = b3CullPoints( pts, count1, false );
|
||||
}
|
||||
else
|
||||
{
|
||||
// todo comment
|
||||
b3Point2D deepest = pts[0];
|
||||
for ( int i = 1; i < count1; ++i )
|
||||
{
|
||||
if ( pts[i].separation < deepest.separation )
|
||||
{
|
||||
deepest = pts[i];
|
||||
}
|
||||
}
|
||||
|
||||
int keptCount = b3DropInteriorPoints( pts, count1, 0.25f * B3_LINEAR_SLOP );
|
||||
hull = b3Bump( &arena, 2 * keptCount * sizeof( b3Point2D ) );
|
||||
int flags = b3_hull2DKeepCollinear | b3_hull2DExactMerge | b3_hull2DIndexOrder;
|
||||
int hullCount = b3Hull2D( pts, keptCount, hull, flags );
|
||||
count2 = b3CullPoints( hull, hullCount );
|
||||
|
||||
// todo comment
|
||||
if ( count2 == 1 )
|
||||
{
|
||||
hull[0] = deepest;
|
||||
}
|
||||
count2 = b3CullPoints( pts, keptCount, keptCount > B3_CULL_SWEEP_THRESHOLD );
|
||||
}
|
||||
#else
|
||||
b3Point2D* hull = b3Bump( &arena, 2 * count1 * sizeof( b3Point2D ) );
|
||||
|
|
|
|||
|
|
@ -19,27 +19,27 @@
|
|||
// Double precision accumulates body positions in double, so the settle/sleep step and the
|
||||
// state hash differ from the float build. Both modes are internally deterministic.
|
||||
#if defined( BOX3D_DOUBLE_PRECISION )
|
||||
#define RAGDOLL_SLEEP_STEP 281
|
||||
#define RAGDOLL_HASH 0x176A6CCA
|
||||
#define WAVE_PILE_SLEEP_STEP 295
|
||||
#define WAVE_PILE_HASH 0x84C803D4
|
||||
#define RAGDOLL_SLEEP_STEP 282
|
||||
#define RAGDOLL_HASH 0x6E4B13AD
|
||||
#define WAVE_PILE_SLEEP_STEP 291
|
||||
#define WAVE_PILE_HASH 0x1D5475C3
|
||||
#define QUERY_SPAWN_SLEEP_STEP 242
|
||||
#define QUERY_SPAWN_HASH 0x489585E6
|
||||
#define QUERY_SPAWN_HIT_COUNT 59
|
||||
#define QUERY_SPAWN_QUERY_HASH 0x5B4429DC
|
||||
#define MESH_DROP_SLEEP_STEP 197
|
||||
#define MESH_DROP_HASH 0xBE011939
|
||||
#define MESH_DROP_HASH 0xE9BD8B61
|
||||
#else
|
||||
#define RAGDOLL_SLEEP_STEP 289
|
||||
#define RAGDOLL_HASH 0xF290ED4B
|
||||
#define RAGDOLL_SLEEP_STEP 277
|
||||
#define RAGDOLL_HASH 0x45E77CAA
|
||||
#define WAVE_PILE_SLEEP_STEP 290
|
||||
#define WAVE_PILE_HASH 0x77C54A88
|
||||
#define WAVE_PILE_HASH 0x9E66034A
|
||||
#define QUERY_SPAWN_SLEEP_STEP 242
|
||||
#define QUERY_SPAWN_HASH 0xF3AD9BA6
|
||||
#define QUERY_SPAWN_HIT_COUNT 59
|
||||
#define QUERY_SPAWN_QUERY_HASH 0xE3271F3D
|
||||
#define MESH_DROP_SLEEP_STEP 197
|
||||
#define MESH_DROP_HASH 0x8D5604D3
|
||||
#define MESH_DROP_HASH 0xBF720313
|
||||
#endif
|
||||
|
||||
// The goldens above pin exact values for the default four point manifold. A build that
|
||||
|
|
|
|||
Loading…
Reference in a new issue