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
38
src/shape.c
38
src/shape.c
|
|
@ -831,6 +831,24 @@ b3ShapeExtent b3ComputeShapeExtent( const b3Shape* shape, b3Vec3 localCenter )
|
|||
return extent;
|
||||
}
|
||||
|
||||
float b3ComputeShapeMinExtent( const b3Shape* shape, b3Vec3 localCenter )
|
||||
{
|
||||
switch ( shape->type )
|
||||
{
|
||||
case b3_capsuleShape:
|
||||
return shape->capsule.radius;
|
||||
|
||||
case b3_sphereShape:
|
||||
return shape->sphere.radius;
|
||||
|
||||
case b3_hullShape:
|
||||
return shape->hull->innerRadius;
|
||||
|
||||
default:
|
||||
return b3ComputeShapeExtent( shape, localCenter ).minExtent;
|
||||
}
|
||||
}
|
||||
|
||||
b3CastOutput b3RayCastShape( const b3Shape* shape, b3Transform transform, const b3RayCastInput* input )
|
||||
{
|
||||
b3RayCastInput localInput = *input;
|
||||
|
|
@ -2079,8 +2097,6 @@ typedef struct b3MeshImpactContext
|
|||
b3Vec3 meshLocalCentroidB1, meshLocalCentroidB2;
|
||||
float fallbackRadius;
|
||||
bool isSensor;
|
||||
|
||||
int visitCount;
|
||||
} b3MeshImpactContext;
|
||||
|
||||
static bool b3MeshTimeOfImpactFcn( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleIndex, void* context )
|
||||
|
|
@ -2089,8 +2105,6 @@ static bool b3MeshTimeOfImpactFcn( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleInd
|
|||
|
||||
b3MeshImpactContext* toiContext = context;
|
||||
|
||||
toiContext->visitCount += 1;
|
||||
|
||||
// Early out for parallel movement
|
||||
b3Vec3 c1 = toiContext->meshLocalCentroidB1;
|
||||
b3Vec3 c2 = toiContext->meshLocalCentroidB2;
|
||||
|
|
@ -2270,8 +2284,8 @@ b3TOIOutput b3ShapeTimeOfImpact( b3Shape* shapeA, b3Shape* shapeB, b3Sweep* swee
|
|||
b3Vec3 localCentroidB = b3GetShapeCentroid( shapeB );
|
||||
context.localCentroidB = localCentroidB;
|
||||
|
||||
b3ShapeExtent extents = b3ComputeShapeExtent( shapeB, context.localCentroidB );
|
||||
context.fallbackRadius = b3MaxFloat( 0.75f * extents.minExtent, B3_SPECULATIVE_DISTANCE );
|
||||
float minExtent = b3ComputeShapeMinExtent( shapeB, context.localCentroidB );
|
||||
context.fallbackRadius = b3MaxFloat( 0.75f * minExtent, B3_SPECULATIVE_DISTANCE );
|
||||
|
||||
// Swept bounds of shapeB
|
||||
b3AABB bounds = b3ComputeSweptShapeAABB( shapeB, sweepB, maxFraction );
|
||||
|
|
@ -2290,8 +2304,6 @@ b3TOIOutput b3ShapeTimeOfImpact( b3Shape* shapeA, b3Shape* shapeB, b3Sweep* swee
|
|||
// todo implement b3MeshTimeOfImpact and b3HeightFieldTimeOfImpact
|
||||
// Note: assuming mesh is static
|
||||
|
||||
uint64_t ticks = b3GetTicks();
|
||||
|
||||
b3MeshImpactContext context = { 0 };
|
||||
context.toiInput.sweepA = *sweepA;
|
||||
context.toiInput.proxyA.count = 3;
|
||||
|
|
@ -2322,8 +2334,8 @@ b3TOIOutput b3ShapeTimeOfImpact( b3Shape* shapeA, b3Shape* shapeB, b3Sweep* swee
|
|||
context.meshLocalCentroidB1 = b3InvTransformPoint( xfA, b3TransformPoint( xfB1, localCentroidB ) );
|
||||
context.meshLocalCentroidB2 = b3InvTransformPoint( xfA, b3TransformPoint( xfB2, localCentroidB ) );
|
||||
|
||||
b3ShapeExtent extents = b3ComputeShapeExtent( shapeB, context.localCentroidB );
|
||||
context.fallbackRadius = b3MaxFloat( 0.5f * extents.minExtent, B3_LINEAR_SLOP );
|
||||
float minExtent = b3ComputeShapeMinExtent( shapeB, context.localCentroidB );
|
||||
context.fallbackRadius = b3MaxFloat( 0.5f * minExtent, B3_LINEAR_SLOP );
|
||||
|
||||
// Swept bounds of shapeB
|
||||
// todo pass in xfA to get local bounds directly
|
||||
|
|
@ -2341,12 +2353,6 @@ b3TOIOutput b3ShapeTimeOfImpact( b3Shape* shapeA, b3Shape* shapeB, b3Sweep* swee
|
|||
b3QueryHeightField( shapeA->heightField, localBounds, b3MeshTimeOfImpactFcn, &context );
|
||||
}
|
||||
|
||||
float ms = b3GetMilliseconds( ticks );
|
||||
if ( ms > 1000.0f * b3GetStallThreshold() )
|
||||
{
|
||||
b3Log( "CCD stall: visited %d triangles", context.visitCount );
|
||||
}
|
||||
|
||||
return context.toiOutput;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue