Skip to content

Skip the heightfield triangles and segments a shape-cast can't reach - #453

Closed
illusion-pasture-program wants to merge 1 commit into
dimforge:masterfrom
illusion-pasture-program:heightfield-shape-cast-precheck
Closed

illusion-pasture-program wants to merge 1 commit into
dimforge:masterfrom
illusion-pasture-program:heightfield-shape-cast-precheck

Conversation

@illusion-pasture-program

Copy link
Copy Markdown

Shape-casting against a HeightField shape-casts every triangle (every segment in 2D) of the cells it walks through, including the ones the moving shape can't reach. This resolves the TODO: pre-check using a ray-cast on the Aabbs first? comments: before shape-casting a triangle or segment, cast the moving shape's Aabb against its Aabb, with the same Minkowski-sum ray-cast cast_shapes_heightfield_shape already does against the whole heightfield (and composite shape-casts do on BVH nodes).

I ran into this with CCD on a car chassis over terrain with 12.5 cm cells. Because the terrain's Aabb contains the chassis, every triangle under it (about a thousand) went through GJK every step, and nearly all of them missed.

Speed. New ignored benchmark, heightfield_shape_cast_perf (cargo test --release -p parry3d --test heightfield_shape_cast -- --ignored --nocapture), three runs each:

before after
car-sized box riding 20 cm over rolling terrain, one 60 Hz step at 30 m/s 712 µs/cast 59.5 µs/cast
balls falling onto that terrain (nothing can be skipped) 118.1 µs/cast 119.2 µs/cast

Same results. I hashed every result (time of impact, witnesses, normals, status) of 200k random casts in 2D and in 3D, over random heightfields from flat to rough, before and after: identical. The pre-check is bounded by max_time_of_impact only, not by the best hit so far. With the tighter bound, 16 of the 200k casts on flat heightfields picked a different triangle among near-ties, because GJK's time of impact can be a hair earlier than the exact Aabb one.

The new tests compare single-cell (2D: single-segment) heightfields against shape-casting their triangles one by one, and fail if the pre-check is made 10% too tight. They use single cells because larger heightfields don't match brute force even before this change: the traversal sometimes misses triangles. I'll open a separate issue for that.

…reach

Before shape-casting a heightfield triangle (segment in 2D), ray-cast the
moving shape's Aabb against its Aabb, as already done against the whole
heightfield, resolving the "pre-check using a ray-cast on the Aabbs" TODOs.
Bounded by max_time_of_impact only, so results are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant