UNPKG

@threlte/xr

Version:

Tools to more easily create VR and AR experiences with Threlte

26 lines (25 loc) 934 B
import { getControlsContext, getInternalContext } from './context'; 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); context.interactiveObjects.splice(index, 1); dispatchers.delete(object); }; return { addInteractiveObject, removeInteractiveObject }; };