forked from EXT/VR180-Web-Player
More reffactors
This commit is contained in:
52
src/vr180player/xr/input-mode.ts
Normal file
52
src/vr180player/xr/input-mode.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
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';
|
||||
}
|
||||
Reference in New Issue
Block a user