Skip to content
13 changes: 12 additions & 1 deletion dartsim/src/SimulationFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,18 @@ SimulationFeatures::GetRayIntersectionFromLastStep(
intersection.point = firstHit.mPoint;
intersection.normal = firstHit.mNormal;
intersection.fraction = firstHit.mFraction;
}

// Map DART CollisionObject to gz-physics shape identity
if (firstHit.mCollisionObject)
{
auto *dtShapeFrame = firstHit.mCollisionObject->getShapeFrame();
if (dtShapeFrame && this->shapes.HasEntity(dtShapeFrame->asShapeNode()))
{
intersection.collisionShapeId =
this->shapes.IdentityOf(dtShapeFrame->asShapeNode());
}
}
}
else
{
// Set invalid measurements to NaN according to REP-117
Expand Down
4 changes: 4 additions & 0 deletions include/gz/physics/GetRayIntersection.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class GZ_PHYSICS_VISIBLE GetRayIntersectionFromLastStepFeature

/// \brief The normal at the hit point in the world coordinates
VectorType normal;

/// \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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

};

public: template <typename PolicyT, typename FeaturesT>
Expand Down
3 changes: 2 additions & 1 deletion include/gz/physics/detail/GetRayIntersection.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ auto GetRayIntersectionFromLastStepFeature::World<
this->template Interface<GetRayIntersectionFromLastStepFeature>()
->GetRayIntersectionFromLastStep(this->identity, _from, _to);

RayIntersection intersection{result.point, result.fraction, result.normal};
RayIntersection intersection{
result.point, result.fraction, result.normal, result.collisionShapeId};

RayIntersectionData output;
output.template Get<RayIntersection>() = std::move(intersection);
Expand Down
Loading