UNPKG

@threlte/xr

Version:

Tools to more easily create VR and AR experiences with Threlte

34 lines (33 loc) 1.13 kB
import { getContext, setContext } from 'svelte'; const handContextKeys = { left: { controller: Symbol('pointer-controls-context-left-controller'), hand: Symbol('pointer-controls-context-left-hand') }, right: { controller: Symbol('pointer-controls-context-right-controller'), hand: Symbol('pointer-controls-context-right-hand') } }; const contextKey = Symbol('pointer-controls-context'); export const getHandContext = (hand, sourceType) => { return getContext(handContextKeys[hand][sourceType]); }; export const setHandContext = (hand, sourceType, context) => { setContext(handContextKeys[hand][sourceType], context); }; export const getControlsContext = () => { return getContext(contextKey); }; export const setControlsContext = (context) => { setContext(contextKey, context); }; const internalContextKey = Symbol('pointer-controls-internal-context'); export const getInternalContext = () => { return getContext(internalContextKey); }; export const setInternalContext = () => { setContext(internalContextKey, { dispatchers: new WeakMap() }); };