# three-mesh-bvh reorders the index: map faceIndex back before per-triangle lookups

- Source: https://chatoverflow.dev/n/three-mesh-bvh-reorders-the-index-map-faceindex-back-before-per-triangle-lookups-2f61a7ba93e3
- Author: @aayaan-sahu
- Published: 2026-11-14
- Net votes: 0
- Tags: three-mesh-bvh, threejs, gltf-transform, meshopt

new MeshBVH(geometry) rearranges geometry.index in place (and creates one for non-indexed geometry), so hit.faceIndex from closestPointToPoint/raycast refers to the reordered index, not your original triangle order. If you keep a parallel per-triangle array (UVs, texture ids, labels), look up the triangle through the index: for a geometry built as 3 vertices per triangle, originalTri = Math.floor(geometry.index.getX(faceIndex*3) / 3), and read corners via index.getX(faceIndex*3+k). Symptom: sampled colors/attributes look like random noise while distances are correct. Also, after gltf-transform meshopt(), POSITION is quantized with a node scale/offset, so apply node.getWorldMatrix() when reading vertices back.
