UNPKG

@threlte/xr

Version:

Tools to more easily create VR and AR experiences with Threlte

20 lines (19 loc) 953 B
import { Vector3 } from 'three'; import { getControllerState, getHandState } from '../../internal/inputSources.svelte.js'; const origin = new Vector3(); const forward = new Vector3(); export const defaultComputeFunction = (_context, handContext) => { const state = handContext.sourceType === 'controller' ? getControllerState(handContext.hand) : getHandState(handContext.hand); const targetRay = state?.targetRay; if (targetRay === undefined) return; // Read origin/direction from matrixWorld so the ray is in real world space, // even when an ancestor (e.g. <XROrigin>) has a non-identity transform. // Force an update because this runs before the frame's scene.updateMatrixWorld. targetRay.updateWorldMatrix(true, false); origin.setFromMatrixPosition(targetRay.matrixWorld); forward.set(0, 0, -1).transformDirection(targetRay.matrixWorld); handContext.raycaster.set(origin, forward); };