-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bugfix] - raycast buffer distance #2466
Conversation
@@ -505,7 +508,13 @@ RaycastResults BulletPhysicsManager::castRay(const esp::geo::Ray& ray, | |||
hit.normal = Magnum::Vector3{allResults.m_hitNormalWorld[i]}; | |||
hit.point = Magnum::Vector3{allResults.m_hitPointWorld[i]}; | |||
hit.rayDistance = | |||
(static_cast<double>(allResults.m_hitFractions[i]) * maxDistance); | |||
(static_cast<double>((allResults.m_hitFractions[i])) - scaledBuffer) * | |||
totalLength / rayLength; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe cache totalLength / rayLength before the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, could do. I feel like the math could be more elegant here, honestly, but I didn't come up with a better version so moving on for now. 😖
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall. I would consider lowering the buffer distance.
@@ -296,6 +296,7 @@ void initSimBindings(py::module& m) { | |||
R"(Perform discrete collision detection for the scene. Physics must be enabled. Warning: may break simulation determinism.)") | |||
.def( | |||
"cast_ray", &Simulator::castRay, "ray"_a, "max_distance"_a = 100.0, | |||
"buffer_distance"_a = 0.08, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: 8cm is a pretty big distance for a buffer. Have you explored setting a lower value? (<=0.01 would be good).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value must be greater than the maximum expected collision margin (default is 4cm). I think 0.08 (8 cm) therefore is fine as we are ditching any hits within that distance anyway. FYI, the minimum I'd want to use is 4cm, so I doubled that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Motivation and Context
This PR fixes a long-standing raycasting bug related to the behavior of Bullet physics raycasting within the collision margin of a convex shape.
TL;DR: we add a hidden "buffer distance" to the raycast to avoid missing an object from within its margin.
Context:
Solution:
How Has This Been Tested
CI raycast tests still pass as before with expected global hit points and distances, despite the buffer.
Added new unit tests to specifically target this bug and demonstrate the solution.
Types of changes
Checklist