add a small amount of debug data to manifolds

refine edge contact rule
This commit is contained in:
Erin Catto 2026-11-03 17:40:11 -08:00
commit 590ab5a7d9
13 changed files with 1668 additions and 33 deletions

View file

@ -581,6 +581,8 @@ static bool b3ComputeConvexManifold( b3World* world, int workerIndex, b3Contact*
target->separation = source->separation;
target->featureId = b3MakeFeatureId( source->pair );
target->triangleIndex = B3_NULL_INDEX;
target->triangleFeature = b3_featureNone;
target->meshFlags = 0;
target->normalVelocity = 0.0f;
}

View file

@ -1075,10 +1075,11 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape
bool blockSource = false;
b3TriangleFeature nearFeature = manifold->feature;
b3NeighborResult result = b3_neighborAdmit;
uint8_t meshFlags = manifold->feature == b3_featureHullFace ? b3_meshContactHullFace : 0;
if ( validateNeighbors && manifold->pointCount > 0 &&
manifold->feature != b3_featureTriangleFace )
{
b3NeighborResult result;
if ( manifold->feature == b3_featureHullFace )
{
result = b3TestHullFaceNeighbors( shapeA, triangleIndex, vertices,
@ -1115,6 +1116,15 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape
result = shapeB->type == b3_sphereShape ? b3_neighborUnknown : b3_neighborSnap;
}
if ( result == b3_neighborUnknown )
{
meshFlags |= b3_meshContactUnverified;
}
else if ( result == b3_neighborSnap )
{
meshFlags = b3_meshContactSnapped;
}
b3LocalManifold deepManifold = { 0 };
b3LocalManifoldPoint deepPoints[B3_MAX_CLIP_POINTS];
bool keepDeep = deep && result == b3_neighborSnap && shapeB->type == b3_hullShape;
@ -1152,6 +1162,11 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape
// The kept manifold failed the neighbor test, so it is unverified like a boundary contact.
blockSource = true;
meshFlags = b3_meshContactDeep | b3_meshContactUnverified;
if ( manifold->feature == b3_featureHullFace )
{
meshFlags |= b3_meshContactHullFace;
}
}
}
}
@ -1162,6 +1177,22 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape
{
B3_ASSERT( manifold->feature != b3_featureNone );
b3TriangleFeature pointFeature = manifold->feature;
if ( pointFeature == b3_featureHullFace && nearFeature != b3_featureHullFace && nearFeature != b3_featureNone )
{
pointFeature = nearFeature;
}
else if ( pointFeature == b3_featureHullFace && nearFeature == b3_featureNone && result == b3_neighborAdmit )
{
pointFeature = b3_featureTriangleFace;
}
for ( int i = 0; i < manifoldPointCount; ++i )
{
manifold->points[i].triangleFeature = (uint8_t)pointFeature;
manifold->points[i].meshFlags = meshFlags;
}
manifold->triangleIndex = triangleIndex;
manifold->triangleNormal =
b3MakeNormalFromPoints( vertices[0], vertices[1], vertices[2] );
@ -1265,6 +1296,11 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape
manifold->normal = blockerNormal;
manifold->triangleNormal = blockerNormal;
manifold->feature = b3_featureTriangleFace;
for ( int j = 0; j < manifold->pointCount; ++j )
{
manifold->points[j].triangleFeature = b3_featureTriangleFace;
manifold->points[j].meshFlags |= b3_meshContactBlocked;
}
}
}
}
@ -1426,6 +1462,8 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape
cp->point = ap->point;
cp->separation = ap->separation;
cp->pair = ap->pair;
cp->triangleFeature = ap->triangleFeature;
cp->meshFlags = ap->meshFlags;
cm->pointCount += 1;
}
}
@ -1563,6 +1601,8 @@ bool b3ComputeMeshManifolds( b3World* world, int workerIndex, b3Contact* contact
target->separation = source->separation - restOffset;
target->featureId = b3MakeFeatureId( source->pair );
target->triangleIndex = source->triangleIndex;
target->triangleFeature = source->triangleFeature;
target->meshFlags = source->meshFlags;
// Preserve normal impulse if possible
if ( matchedManifold != NULL )
@ -1762,6 +1802,8 @@ int b3CollideMeshAndHull( b3Manifold* manifolds, int capacity, const b3Mesh* mes
target->separation = source->separation - restOffset;
target->featureId = b3MakeFeatureId( source->pair );
target->triangleIndex = source->triangleIndex;
target->triangleFeature = source->triangleFeature;
target->meshFlags = source->meshFlags;
}
}

View file

@ -13,6 +13,10 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
// cosine of hull normal versus edge axis tolerance.
#define B3_CROSSING_TOLERANCE 0.1f
typedef struct b3TriangleData
{
@ -1311,14 +1315,29 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v
// If a face axis has positive separation there may be no points.
float maxFaceSeparation = b3MaxFloat( faceQueryA.separation, faceQueryB.separation );
// The edge axis can win if the hull face axis is significantly aligned with the edge axis.
bool crossesEdge = false;
if ( manifold->pointCount >= 1 && manifold->feature == b3_featureHullFace && edgeQuery.separation > clipSeparation )
{
b3Vec3 edgeAxis = b3Normalize( triangleEdges[edgeQuery.indexA] );
// Is the angle less than ~84 degrees?
crossesEdge = b3AbsFloat( b3Dot( faceQueryB.normal, edgeAxis ) ) > B3_CROSSING_TOLERANCE;
}
if ( ( manifold->pointCount == 0 && edgeQuery.separation > maxFaceSeparation ) ||
( manifold->pointCount == 1 && edgeQuery.separation > clipSeparation + linearSlop ) )
( manifold->pointCount == 1 && edgeQuery.separation > clipSeparation + linearSlop ) || crossesEdge )
{
B3_ASSERT( 0 <= edgeQuery.indexA && edgeQuery.indexA < 3 );
b3Vec3 trianglePoint = trianglePoints[edgeQuery.indexA];
b3Vec3 triangleEdge = triangleEdges[edgeQuery.indexA];
manifold->pointCount = 0;
b3CollideTriangleAndHullEdges( manifold, capacity, trianglePoint, triangleEdge, hullB, edgeQuery, cache );
if ( crossesEdge && manifold->pointCount == 0 )
{
b3CollideHullFace( manifold, capacity, &triangle, hullB, faceQueryB, cache, enableSpeculative );
}
}
}