@threlte/xr
Version:
Tools to more easily create VR and AR experiences with Threlte
25 lines (24 loc) • 883 B
JavaScript
import { injectPlugin, isInstanceOf } from '@threlte/core';
import { useTouchControls } from './hook.js';
import { events } from './types.js';
export const injectTouchControlsPlugin = () => {
injectPlugin('threlte-touch-controls', (args) => {
if (!isInstanceOf(args.ref, 'Object3D'))
return;
const { addInteractiveObject, removeInteractiveObject } = useTouchControls();
$effect.pre(() => {
const ref = args.ref;
const props = args.props;
const hasEventHandlers = events.some((eventName) => typeof props[eventName] === 'function');
if (!hasEventHandlers)
return;
addInteractiveObject(ref, props);
return () => {
removeInteractiveObject(ref);
};
});
return {
pluginProps: events
};
});
};