Reduce ghosts (#212)

Full ghost collision handling for sphere, capsule, and hull versus a
single mesh or heightfield. This requires mesh to be built with edge
identification.

Optimized mesh builder.

Removed B3_MAX_MESH_CONTACT_TRIANGLES. You will still hit performance
problems for dense meshes. Fixes #184
This commit is contained in:
Erin Catto 2026-11-10 21:53:10 -08:00 • committed by GitHub
commit 38f2ae1e19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
61 changed files with 17756 additions and 1492 deletions

View file

@ -2900,6 +2900,7 @@ public:
e_random = 0,
e_circle = 1,
e_sliver = 2,
e_grid = 3,
};
static Sample* Create( SampleContext* context )
@ -2923,6 +2924,7 @@ public:
m_pointCount = 20;
m_drawScale = 1.0f;
m_drawLabels = true;
m_hullFlags = 0;
Generate();
}
@ -2961,6 +2963,20 @@ public:
m_inputPoints[i].originalIndex = i;
}
}
else if ( m_sourceMode == e_grid )
{
// Every border point is collinear with its neighbors, so the hull keeps them only with
// the collinear flag
m_drawScale = 1.0f;
m_inputCount = 36;
for ( int i = 0; i < m_inputCount; ++i )
{
m_inputPoints[i].p = { -5.0f + 2.0f * (float)( i % 6 ), -5.0f + 2.0f * (float)( i / 6 ) };
m_inputPoints[i].separation = 0.0f;
m_inputPoints[i].originalIndex = i;
}
}
else
{
// A near degenerate sliver with a duplicate pair. Welding and collinear removal have
@ -2998,7 +3014,7 @@ public:
scratch[i] = m_inputPoints[i];
}
m_hullCount = b3Hull2D( scratch, m_inputCount, m_hullPoints );
m_hullCount = b3Hull2D( scratch, m_inputCount, m_hullPoints, m_hullFlags );
for ( int i = 0; i < m_hullCount; ++i )
{
@ -3010,13 +3026,13 @@ public:
bool DrawControls() override
{
const char* modes[] = { "Random", "Circle", "Sliver" };
const char* modes[] = { "Random", "Circle", "Sliver", "Grid" };
if ( ImGui::Combo( "Source", &m_sourceMode, modes, IM_ARRAYSIZE( modes ) ) )
{
Generate();
}
if ( m_sourceMode != e_sliver )
if ( m_sourceMode == e_random || m_sourceMode == e_circle )
{
if ( ImGui::SliderInt( "Point Count", &m_pointCount, 4, m_pointCapacity ) )
{
@ -3033,6 +3049,8 @@ public:
}
ImGui::SliderInt( "Target Count", &m_targetCount, 3, m_inputCount );
ImGui::CheckboxFlags( "Keep Collinear", &m_hullFlags, b3_hull2DKeepCollinear );
ImGui::CheckboxFlags( "Exact Merge", &m_hullFlags, b3_hull2DExactMerge );
ImGui::Checkbox( "Draw Labels", &m_drawLabels );
return true;
@ -3110,6 +3128,7 @@ public:
int m_simplifiedCount;
int m_targetCount;
int m_pointCount;
int m_hullFlags;
bool m_drawLabels;
};