forked from EXT/VR180-Web-Player
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
export type PointerInputMode = 'controller' | 'hand';
|
|
|
|
export type PointerInputModeCarrier = {
|
|
controller?: {
|
|
userData?: any;
|
|
};
|
|
pointerInputMode?: PointerInputMode;
|
|
};
|
|
|
|
export function rememberPointerInputMode(
|
|
inputSource: PointerInputModeCarrier,
|
|
event: any,
|
|
fallbackMode: PointerInputMode
|
|
): void {
|
|
const eventInputSource = event?.data?.inputSource || event?.inputSource || event?.data;
|
|
const nextMode = getPointerInputMode(eventInputSource) || fallbackMode;
|
|
inputSource.pointerInputMode = nextMode;
|
|
|
|
if (!inputSource.controller) {
|
|
return;
|
|
}
|
|
|
|
inputSource.controller.userData = {
|
|
...inputSource.controller.userData,
|
|
vrwpInputSource: inputSource
|
|
};
|
|
}
|
|
|
|
export function getPointerInputMode(eventInputSource: any): PointerInputMode | null {
|
|
if (!eventInputSource) {
|
|
return null;
|
|
}
|
|
|
|
if (eventInputSource.hand) {
|
|
return 'hand';
|
|
}
|
|
|
|
if (Array.isArray(eventInputSource.profiles) &&
|
|
eventInputSource.profiles.some((profile: string) => profile.toLowerCase().includes('hand'))) {
|
|
return 'hand';
|
|
}
|
|
|
|
if (eventInputSource.gamepad || eventInputSource.targetRayMode === 'tracked-pointer') {
|
|
return 'controller';
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function shouldUseHandPointer(inputSource: PointerInputModeCarrier | undefined): boolean {
|
|
return inputSource?.pointerInputMode === 'hand';
|
|
}
|