Skip the heightfield triangles and segments a shape-cast can't reach - #453
Closed
illusion-pasture-program wants to merge 1 commit into
Closed
illusion-pasture-program wants to merge 1 commit into
illusion-pasture-program wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Shape-casting against a
HeightFieldshape-casts every triangle (every segment in 2D) of the cells it walks through, including the ones the moving shape can't reach. This resolves theTODO: 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-castcast_shapes_heightfield_shapealready 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: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_impactonly, 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.