Skip to content

Add collisionShapeId to RayIntersectionT for raycast hit entity ident…#879

Open
khalidbourr wants to merge 5 commits intogazebosim:mainfrom
khalidbourr:feature/raycast-entity
Open

Add collisionShapeId to RayIntersectionT for raycast hit entity ident…#879
khalidbourr wants to merge 5 commits intogazebosim:mainfrom
khalidbourr:feature/raycast-entity

Conversation

@khalidbourr
Copy link

@khalidbourr khalidbourr commented Feb 18, 2026

🎉 New feature

Closes #3314

Summary

DART's RayHit already contains mCollisionObject but it was being dropped in GetRayIntersectionFromLastStep(). This PR adds a collisionShapeId field to RayIntersectionT and populates it using the same CollisionObject → getShapeFrame() → asShapeNode() → shapes.IdentityOf() mapping that convertContact() already uses.

Changes

  • include/gz/physics/GetRayIntersection.hh
  • include/gz/physics/detail/GetRayIntersection.hh
  • dartsim/src/SimulationFeatures.cc

Checklist

  • Signed all commits for DCO
  • Added a screen capture or video to the PR description that demonstrates the feature
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • Updated Bazel files (if adding new files). Created an issue otherwise.
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers
  • Was GenAI used to generate this PR? If so, make sure to add "Generated-by" to your commits. (See this policy for more info.)

Note

Companion PR for gz-sim: gazebosim/gz-sim#3336

…ification

Signed-off-by: khalid <khalid.bourr@unicam.it>

/// \brief The identity of the collision shape that was hit.
/// Set to 0 if no shape was hit or not supported by the physics engine.
std::size_t collisionShapeId{0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would break ABI and would not be backward portable. Alternatively, we can add an optional data to RayIntersection similar to how force, normal, and depth are added to contact data in

public: using Contact = SpecifyData<
RequireData<ContactPoint>,
ExpectData<ExtraContactData> >;

and

// Add normal, depth and wrench to extraData.
auto& extraContactData =
extraData.Get<SimulationFeatures::ExtraContactData>();
extraContactData.force = _contact.force;
extraContactData.normal = _contact.normal;
extraContactData.depth = _contact.penetrationDepth;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it, I will do that asap

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve refactored the code to follow the same CompositeData / ExpectData pattern used in GetContacts.
collisionShapeId is now passed as optional extra data through ExtraRayIntersectionDataT, so RayIntersectionT stays unchanged.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azeey Just a gentle ping, in case further modifications are needed, I'm available. Happy to iterate whenever you get the chance to review.

…ation

Signed-off-by: khalid <khalid.bourr@unicam.it>
@khalidbourr khalidbourr force-pushed the feature/raycast-entity branch from 922f807 to b582816 Compare February 24, 2026 11:03
@khalidbourr khalidbourr requested a review from azeey February 25, 2026 13:41
Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor comment, otherwise, LGTM! Thanks for the contribution!!

Comment on lines +39 to +42
RayIntersection intersection{
result.intersection.point,
result.intersection.fraction,
result.intersection.normal};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: weird indentation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-project-automation github-project-automation bot moved this from Inbox to In review in Core development Mar 12, 2026
azeey added 2 commits March 11, 2026 23:01
Signed-off-by: Addisu Z. Taddese <addisuzt@intrinsic.ai>
Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, on second look, I realized this doesn't have any tests. Would you mind adding one in test/common_test?

@khalidbourr
Copy link
Author

Actually, on second look, I realized this doesn't have any tests. Would you mind adding one in test/common_test?

Sure !

Signed-off-by: khalid <khalid.bourr@unicam.it>
@khalidbourr
Copy link
Author

I extended the already existed tests: SupportedRayIntersections and UnsupportedRayIntersections.

In SupportedRayIntersections:

if Ray hits sphere then collisionShapeId != 0 (valid hit)
If misses sphere then collisionShapeId == 0 (nothing hit)

In UnsupportedRayIntersections:

Ray would hit sphere but detector can't raycast then collisionShapeId == 0 (must be treated as miss)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants