I'm performing a ray test on a number of triangle meshes and attempting to get the hit face normal in the ray result callback. The way to do this seems to be creating a custom ray result callback and overriding addSingleResult, which gives me access to the local shape info m_triangleIndex member. So far I'm thinking something like:
Code: Select all
btScalar addSingleResult(btCollisionWorld::LocalRayResult &result, bool) override
{
// ...
// Get the triangle which generated the hit and calculate its normal.
const auto *triangleShape = static_cast<const btBvhTriangleMeshShape *>(m_collisionObject->getCollisionShape());
const auto *triangleMesh = static_cast<const btTriangleIndexVertexArray *>(triangleShape->getMeshInterface());
const int subPart = result.m_localShapeInfo->m_shapePart;
const int triangleIndex = result.m_localShapeInfo->m_triangleIndex;
triangleMesh->getLockedReadOnlyVertexIndexBase(..., subPart);
// Calculate the face index here.
triangleMesh->unLockReadOnlyVertexBase(subPart);
// ...
}