useSelectionHighlight hook.
The Pattern
- A hook listens for double-clicks and raycasts to find the clicked body
- The
useSelectionHighlighthook applies a visual highlight to the selected body
Composing with useSelectionHighlight
Using the onSelection Callback
<MujocoCanvas> also has a built-in onSelection callback that fires on double-click:
How SceneRenderer Stores Body IDs
<SceneRenderer /> sets userData.bodyID on every mesh it creates. When raycasting, walk up the object tree with obj.parent until you find a node with userData.bodyID — child meshes (e.g. geom sub-meshes) don’t have it directly, but their parent body group does.
useSelectionHighlight Options
For more advanced selection visuals (outlines, postprocessing, custom shaders), use
useBodyMeshes to get direct access to the body’s Three.js meshes.