UNPKG

@threlte/xr

Version:

Tools to more easily create VR and AR experiences with Threlte

28 lines (27 loc) 983 B
import { getControlsContext, getInternalContext } from './context.js'; export const usePointerControls = () => { const context = getControlsContext(); const { dispatchers } = getInternalContext(); if (!context) { throw new Error('No pointer controls context found. Did you forget to implement pointerControls()?'); } const addInteractiveObject = (object, events) => { // check if the object is already in the list if (context.interactiveObjects.indexOf(object) > -1) { return; } dispatchers.set(object, events); context.interactiveObjects.push(object); }; const removeInteractiveObject = (object) => { const index = context.interactiveObjects.indexOf(object); if (index === -1) return; context.interactiveObjects.splice(index, 1); dispatchers.delete(object); }; return { addInteractiveObject, removeInteractiveObject }; };