summit/frontend/node_modules/three-stdlib/libs/MotionControllers.cjs.map

1 line
23 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"MotionControllers.cjs","sources":["../../src/libs/MotionControllers.ts"],"sourcesContent":["/**\n * @webxr-input-profiles/motion-controllers 1.0.0 https://github.com/immersive-web/webxr-input-profiles\n */\n\nimport type { Object3D } from 'three'\n\ninterface GamepadIndices {\n button: number\n xAxis?: number\n yAxis?: number\n}\n\ninterface VisualResponseDescription {\n componentProperty: string\n states: string[]\n valueNodeProperty: string\n valueNodeName: string\n minNodeName?: string\n maxNodeName?: string\n}\n\ntype VisualResponses = Record<string, VisualResponseDescription>\n\ninterface ComponentDescription {\n type: string\n gamepadIndices: GamepadIndices\n rootNodeName: string\n visualResponses: VisualResponses\n touchPointNodeName?: string\n}\n\ninterface Components {\n [componentKey: string]: ComponentDescription\n}\n\ninterface LayoutDescription {\n selectComponentId: string\n components: Components\n gamepadMapping: string\n rootNodeName: string\n assetPath: string\n}\n\ntype Layouts = Partial<Record<XRHandedness, LayoutDescription>>\n\nexport interface Profile {\n profileId: string\n fallbackProfileIds: string[]\n layouts: Layouts\n}\n\ninterface ProfilesList {\n [profileId: string]: { path: string; deprecated?: boolean } | undefined\n}\n\nconst MotionControllerConstants = {\n Handedness: {\n NONE: 'none',\n LEFT: 'left',\n RIGHT: 'right',\n },\n\n ComponentState: {\n DEFAULT: 'default',\n TOUCHED: 'touched',\n PRESSED: 'pressed',\n },\n\n ComponentProperty: {\n BUTTON: 'button',\n X_AXIS: 'xAxis',\n Y_AXIS: 'yAxis',\n STATE: 'state',\n },\n\n ComponentType: {\n TRIGGER: 'trigger',\n SQUEEZE: 'squeeze',\n TOUCHPAD: 'touchpad',\n THUMBSTICK: 'thumbstick',\n BUTTON: 'button',\n },\n\n ButtonTouchThreshold: 0.05,\n\n AxisTouchThreshold: 0.1,\n\n VisualResponseProperty: {\n TRANSFORM: 'transform',\n VISIBILITY: 'visibility',\n },\n}\n\n/**\n * @description Static helper function to fetch a JSON file and turn it into a JS object\n * @param {string} path - Path to JSON file to be fetched\n */\nasync function fetchJsonFile<T>(path: string): Promise<T> {\n const response = await fetch(path)\n if (!response.ok) {\n throw new Error(response.statusText)\n } else {\n return response.json()\n }\n}\n\nasync function fetchProfilesList(basePath: string): Promise<ProfilesList> {\n if (!basePath) {\n throw new Error('No basePath supplied')\n }\n\n const profileListFileName = 'profilesList.json'\n const profilesList = await fetchJsonFile<ProfilesList>(`${basePath}/${profileListFileName}`)\n return profilesList\n}\n\nasync function fetchProfile(\n xrInputSource: XRInputSource,\n basePath: string,\n defaultProfile: string | null = null,\n getAssetPath = true,\n): Promise<{ profile: Profile; assetPath: string | undefined }> {\n if (!xrInputSource) {\n throw new Error('No xrInputSource supplied')\n }\n\n if (!basePath) {\n throw new Error('No basePath supplied')\n }\n\n // Get the list of profiles\n const supportedProfilesList = await fetchProfilesList(basePath)\n\n // Find the relative path to the first requested profile that is recognized\n let match: { profileId: string; profilePath: string; deprecated: boolean } | undefined = undefined\n xrInputSource.profiles.some((profileId: string) => {\n const supportedProfile = supportedProfilesList[profileId]\n if (supportedProfile) {\n match = {\n profileId,\n profilePath: `${basePath}/${supportedProfile.path}`,\n deprecated: !!supportedProfile.deprecated,\n }\n }\n return !!match\n })\n\n if (!match) {\n if (!defaultProfile) {\n throw new Error('No matching profile name found')\n }\n\n const supportedProfile = supportedProfilesList[defaultProfile]\n if (!supportedProfile) {\n throw new Error(`No matching profile name found and default profile \"${defaultProfile}\" missing.`)\n }\n\n match = {\n profileId: defaultProfile,\n profilePath: `${basePath}/${supported