The primary hook for accessing the MuJoCo simulation API from any component inside <MujocoCanvas>.Narrow on isReady, isPending, or isError to get type-safe access to the API and refs.
IK control is provided by the useIkController() hook — see useIkController and IK Control.Camera animation is provided by the standalone useCameraAnimation() hook — see useCameraAnimation.
For advanced use cases, access the raw MuJoCo model and data objects:
function AdvancedComponent() { const sim = useMujoco(); useFrame(() => { if (!sim.isReady) return; const model = sim.mjModelRef.current; const data = sim.mjDataRef.current; if (!model || !data) return; // Read raw WASM arrays const nq = model.nq; const qpos = data.qpos; // Float64Array }); return null;}
Direct model/data access bypasses the API’s safety checks. Be careful with array indexing and avoid writing to arrays that the provider manages (e.g., qfrc_applied is zeroed each frame).