Getting triangle index from a ray cast result #269
Replies: 1 comment
-
That triangle_idx is not what you think it is. It is an index into a local triangle block. During shape creation all triangles are shuffled around into blocks of triangles that are close to each other. This means it has no relation to the original mesh you supplied. You can only use the SubShapeID to get information about a triangle (its material or normal). The max amount of materials per mesh is 32 but I see why you think it's 8 (the error message is incorrect). This is fixed in #264. To put more than 32 materials per mesh, just group your triangles into sub meshes that have max 32 materials and combine those meshes in a StaticCompoundShape. The limit of 32 materials per mesh was chosen to keep the memory consumption of mesh shapes down. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I would like to know the index of the triangle that was hit by a ray cast, in particular by
physics_system->GetNarrowPhaseQuery().CastRay().
The reason I want the triangle index is so that I can work out which material is assigned to the hit triangle (I can't use the material indices stored in the Jolt shape, as they are restricted to at most 8 different materials, and I may have more than 8).
I would also like to work out the hit barycentric and UV coordinates, which I can do if I can get the hit triangle index.
Is this possible in Jolt?
Currently it looks like the triangle index information is being lost on this line:
mHit.mSubShapeID2 = mSubShapeIDCreator.PushID(inTriangleBlockID, mTriangleBlockIDBits).PushID(triangle_idx, NumTriangleBits).GetID();
(Jolt\Physics\Collision\Shape\MeshShape.cpp, line 664)
Beta Was this translation helpful? Give feedback.
All reactions