Tree perf (#179)
- Optimizations for falling trees. - Increased B3_MAX_MESH_CONTACT_TRIANGLES from 256 to 512.
This commit is contained in:
parent
e77352cd60
commit
16f7f4cf4c
36 changed files with 1926 additions and 1110 deletions
153
src/mesh.c
153
src/mesh.c
|
|
@ -2234,50 +2234,6 @@ b3CastOutput b3ShapeCastMesh( const b3Mesh* mesh, const b3ShapeCastInput* input
|
|||
return bestOutput;
|
||||
}
|
||||
|
||||
b3Triangle b3GetMeshTriangle( const b3Mesh* mesh, int triangleIndex )
|
||||
{
|
||||
B3_ASSERT( 0 <= triangleIndex && triangleIndex < mesh->data->triangleCount );
|
||||
|
||||
const b3MeshTriangle* triangles = b3GetMeshTriangles( mesh->data );
|
||||
const uint8_t* flags = b3GetMeshFlags( mesh->data );
|
||||
const b3Vec3* vertices = b3GetMeshVertices( mesh->data );
|
||||
|
||||
b3Triangle result;
|
||||
b3MeshTriangle triangle = triangles[triangleIndex];
|
||||
uint8_t triangleFlags = flags[triangleIndex];
|
||||
|
||||
b3Vec3 scale = mesh->scale;
|
||||
|
||||
result.vertices[0] = b3Mul( scale, vertices[triangle.index1] );
|
||||
result.i1 = triangle.index1;
|
||||
|
||||
if ( scale.x * scale.y * scale.z < 0.0f )
|
||||
{
|
||||
result.vertices[1] = b3Mul( scale, vertices[triangle.index3] );
|
||||
result.vertices[2] = b3Mul( scale, vertices[triangle.index2] );
|
||||
|
||||
result.i2 = triangle.index3;
|
||||
result.i3 = triangle.index2;
|
||||
|
||||
// mesh is inverted, so concave edges are now convex
|
||||
result.flags = 0;
|
||||
result.flags |= ( triangleFlags & b3_inverseConcaveEdge1 ) ? b3_concaveEdge1 : 0;
|
||||
result.flags |= ( triangleFlags & b3_inverseConcaveEdge2 ) ? b3_concaveEdge2 : 0;
|
||||
result.flags |= ( triangleFlags & b3_inverseConcaveEdge3 ) ? b3_concaveEdge3 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.vertices[1] = b3Mul( scale, vertices[triangle.index2] );
|
||||
result.vertices[2] = b3Mul( scale, vertices[triangle.index3] );
|
||||
|
||||
result.i2 = triangle.index2;
|
||||
result.i3 = triangle.index3;
|
||||
result.flags = triangleFlags;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int b3CollideMoverAndMesh( b3PlaneResult* planes, int capacity, const b3Mesh* shape, const b3Capsule* mover )
|
||||
{
|
||||
if ( capacity == 0 )
|
||||
|
|
@ -2436,63 +2392,82 @@ void b3QueryMesh( const b3Mesh* mesh, b3AABB bounds, b3MeshQueryFcn* fcn, void*
|
|||
const b3MeshTriangle* triangles = b3GetMeshTriangles( data );
|
||||
const b3Vec3* vertices = b3GetMeshVertices( data );
|
||||
|
||||
// Test node overlap in unscaled space
|
||||
if ( b3TestBoundsOverlap( b3LoadV( &node->lowerBound.x ), b3LoadV( &node->upperBound.x ), invScaledBoundsMin,
|
||||
invScaledBoundsMax ) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while ( true )
|
||||
{
|
||||
// Test node overlap in unscaled space
|
||||
b3V32 nodeMin = b3LoadV( &node->lowerBound.x );
|
||||
b3V32 nodeMax = b3LoadV( &node->upperBound.x );
|
||||
|
||||
if ( b3TestBoundsOverlap( nodeMin, nodeMax, invScaledBoundsMin, invScaledBoundsMax ) )
|
||||
if ( b3IsLeaf( node ) )
|
||||
{
|
||||
if ( b3IsLeaf( node ) )
|
||||
int triangleCount = node->data.asLeaf.triangleCount;
|
||||
int triangleOffset = node->triangleOffset;
|
||||
|
||||
for ( int index = 0; index < triangleCount; ++index )
|
||||
{
|
||||
int triangleCount = node->data.asLeaf.triangleCount;
|
||||
int triangleOffset = node->triangleOffset;
|
||||
int triangleIndex = triangleOffset + index;
|
||||
b3MeshTriangle triangle = triangles[triangleIndex];
|
||||
|
||||
for ( int index = 0; index < triangleCount; ++index )
|
||||
b3Vec3 vertex1 = vertices[triangle.index1];
|
||||
b3Vec3 vertex2 = vertices[triangle.index2];
|
||||
b3Vec3 vertex3 = vertices[triangle.index3];
|
||||
b3V32 v1 = b3LoadV( &vertex1.x );
|
||||
b3V32 v2 = b3LoadV( &vertex2.x );
|
||||
b3V32 v3 = b3LoadV( &vertex3.x );
|
||||
|
||||
// Perform triangle overlap test in unscaled space.
|
||||
// todo it is possible that some margins are getting scaled
|
||||
if ( b3TestBoundsTriangleOverlap( invScaledBoundsCenter, invScaledBoundsExtent, v1, v2, v3 ) )
|
||||
{
|
||||
int triangleIndex = triangleOffset + index;
|
||||
b3MeshTriangle triangle = triangles[triangleIndex];
|
||||
|
||||
b3Vec3 vertex1 = vertices[triangle.index1];
|
||||
b3Vec3 vertex2 = vertices[triangle.index2];
|
||||
b3Vec3 vertex3 = vertices[triangle.index3];
|
||||
b3V32 v1 = b3LoadV( &vertex1.x );
|
||||
b3V32 v2 = b3LoadV( &vertex2.x );
|
||||
b3V32 v3 = b3LoadV( &vertex3.x );
|
||||
|
||||
// Perform triangle overlap test in unscaled space.
|
||||
// todo it is possible that some margins are getting scaled
|
||||
if ( b3TestBoundsTriangleOverlap( invScaledBoundsCenter, invScaledBoundsExtent, v1, v2, v3 ) )
|
||||
b3Vec3 a = b3Mul( meshScale, vertex1 );
|
||||
b3Vec3 b, c;
|
||||
if ( ccw )
|
||||
{
|
||||
b3Vec3 a = b3Mul( meshScale, vertex1 );
|
||||
b3Vec3 b, c;
|
||||
if ( ccw )
|
||||
{
|
||||
b = b3Mul( meshScale, vertex2 );
|
||||
c = b3Mul( meshScale, vertex3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
b = b3Mul( meshScale, vertex3 );
|
||||
c = b3Mul( meshScale, vertex2 );
|
||||
}
|
||||
b = b3Mul( meshScale, vertex2 );
|
||||
c = b3Mul( meshScale, vertex3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
b = b3Mul( meshScale, vertex3 );
|
||||
c = b3Mul( meshScale, vertex2 );
|
||||
}
|
||||
|
||||
bool result = fcn( a, b, c, triangleIndex, context );
|
||||
if ( result == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool result = fcn( a, b, c, triangleIndex, context );
|
||||
if ( result == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Recurse
|
||||
B3_ASSERT( count <= B3_MESH_STACK_SIZE - 1 );
|
||||
stack[count++] = b3GetRightChild( node );
|
||||
node = b3GetLeftChild( node );
|
||||
}
|
||||
else
|
||||
{
|
||||
const b3MeshNode* leftChild = b3GetLeftChild( node );
|
||||
const b3MeshNode* rightChild = b3GetRightChild( node );
|
||||
|
||||
bool overlapLeft = b3TestBoundsOverlap( b3LoadV( &leftChild->lowerBound.x ), b3LoadV( &leftChild->upperBound.x ),
|
||||
invScaledBoundsMin, invScaledBoundsMax );
|
||||
bool overlapRight = b3TestBoundsOverlap( b3LoadV( &rightChild->lowerBound.x ),
|
||||
b3LoadV( &rightChild->upperBound.x ), invScaledBoundsMin, invScaledBoundsMax );
|
||||
|
||||
if ( overlapLeft )
|
||||
{
|
||||
if ( overlapRight )
|
||||
{
|
||||
B3_ASSERT( count <= B3_MESH_STACK_SIZE - 1 );
|
||||
stack[count++] = rightChild;
|
||||
}
|
||||
|
||||
node = leftChild;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( overlapRight )
|
||||
{
|
||||
node = rightChild;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue