UNPKG

@threlte/xr

Version:

Tools to more easily create VR and AR experiences with Threlte

27 lines (26 loc) 923 B
import { getControlsContext, getInternalContext } from './context.js'; export const useTouchControls = () => { const context = getControlsContext(); const { dispatchers } = getInternalContext(); if (!context) { throw new Error('No touch controls context found. Did you forget to implement touchControls()?'); } const addInteractiveObject = (object, events) => { 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 }; };