@iwsdk/xr-input 1.0.0-rc.0 → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gamepad/generated-profiles.js.map +1 -1
- package/dist/gamepad/input-profiles.js.map +1 -1
- package/dist/gamepad/stateful-button-axes-device.js.map +1 -1
- package/dist/gamepad/stateful-gamepad.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/pointer/cursor-visual.js.map +1 -1
- package/dist/pointer/filtered-eye-gaze.d.ts +48 -0
- package/dist/pointer/filtered-eye-gaze.d.ts.map +1 -0
- package/dist/pointer/filtered-eye-gaze.js +118 -0
- package/dist/pointer/filtered-eye-gaze.js.map +1 -0
- package/dist/pointer/gaze-candidate-provider.d.ts +58 -0
- package/dist/pointer/gaze-candidate-provider.d.ts.map +1 -0
- package/dist/pointer/gaze-conecaster.d.ts +130 -0
- package/dist/pointer/gaze-conecaster.d.ts.map +1 -0
- package/dist/pointer/gaze-conecaster.js +456 -0
- package/dist/pointer/gaze-conecaster.js.map +1 -0
- package/dist/pointer/gaze-pointer.d.ts +266 -0
- package/dist/pointer/gaze-pointer.d.ts.map +1 -0
- package/dist/pointer/gaze-pointer.js +865 -0
- package/dist/pointer/gaze-pointer.js.map +1 -0
- package/dist/pointer/grab-pointer.js.map +1 -1
- package/dist/pointer/multi-pointer.d.ts +21 -6
- package/dist/pointer/multi-pointer.d.ts.map +1 -1
- package/dist/pointer/multi-pointer.js +52 -12
- package/dist/pointer/multi-pointer.js.map +1 -1
- package/dist/pointer/ray-pointer.js.map +1 -1
- package/dist/pointer/touch-pointer.js.map +1 -1
- package/dist/pointer/visibility.js.map +1 -1
- package/dist/rig/xr-origin.d.ts +26 -0
- package/dist/rig/xr-origin.d.ts.map +1 -1
- package/dist/rig/xr-origin.js +25 -1
- package/dist/rig/xr-origin.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/visual/adapter/base-visual-adapter.js.map +1 -1
- package/dist/visual/adapter/controller-visual-adapter.js.map +1 -1
- package/dist/visual/adapter/hand-visual-adapter.d.ts +9 -0
- package/dist/visual/adapter/hand-visual-adapter.d.ts.map +1 -1
- package/dist/visual/adapter/hand-visual-adapter.js +47 -9
- package/dist/visual/adapter/hand-visual-adapter.js.map +1 -1
- package/dist/visual/impl/animated-controller-hand.js.map +1 -1
- package/dist/visual/impl/animated-controller.js.map +1 -1
- package/dist/visual/impl/animated-hand.js.map +1 -1
- package/dist/visual/impl/base-impl.js.map +1 -1
- package/dist/visual/utils/flex-batched-mesh.js.map +1 -1
- package/dist/visual/utils/simple-batched-mesh.js.map +1 -1
- package/dist/xr-input-manager.d.ts +57 -1
- package/dist/xr-input-manager.d.ts.map +1 -1
- package/dist/xr-input-manager.js +285 -15
- package/dist/xr-input-manager.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-profiles.js","sources":["../../src/gamepad/input-profiles.ts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"input-profiles.js","sources":["../../src/gamepad/input-profiles.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nexport const DEFAULT_PROFILES_PATH =\n 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles';\n\nimport {\n PROFILES_LIST,\n getProfile as getGeneratedProfile,\n} from './generated-profiles.js';\nconst DEFAULT_PROFILE = 'generic-trigger';\nconst PROFILE_LIST_NAME = 'profilesList.json';\n\ntype ComponentState = 'default' | 'touched' | 'pressed';\ntype ValueNodeProperty = 'transform' | 'visibility';\ntype GamepadIndexKeys = 'button' | 'xAxis' | 'yAxis';\n\nexport interface InputComponentConfig {\n type: 'trigger' | 'squeeze' | 'thumbstick' | 'touchpad' | 'button';\n gamepadIndices: Partial<{ [id in GamepadIndexKeys]: number }>;\n rootNodeName: string;\n touchPointNodeName?: string;\n visualResponses: {\n [id: string]: {\n componentProperty: 'button' | 'xAxis' | 'yAxis' | 'state';\n states: ComponentState[];\n valueNodeProperty: ValueNodeProperty;\n valueNodeName: string;\n minNodeName?: string;\n maxNodeName?: string;\n };\n };\n}\n\nexport interface InputLayout {\n selectComponentId: string;\n components: { [id: string]: InputComponentConfig };\n rootNodeName: string;\n gamepadMapping: 'xr-standard' | '';\n assetPath: string;\n}\n\nexport interface InputProfile {\n profileId: string;\n fallbackProfileIds: string[];\n layouts: Partial<{ [handedness in XRHandedness]: InputLayout }>;\n}\n\nexport async function fetchJsonFile(path: string): Promise<InputProfile> {\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\nexport async function fetchProfilesList(\n basePath: string = DEFAULT_PROFILES_PATH,\n): Promise<any> {\n const profilesList = await fetchJsonFile(`${basePath}/${PROFILE_LIST_NAME}`);\n return profilesList;\n}\n\ntype FetchProfileOptions = {\n basePath?: string;\n defaultProfile?: string;\n getAssetPath?: boolean;\n};\n\nexport function fetchProfileSync(\n inputSource: XRInputSource,\n {\n defaultProfile = DEFAULT_PROFILE,\n }: Omit<FetchProfileOptions, 'basePath'> = {},\n): InputProfile {\n const supportedProfilesList = PROFILES_LIST;\n\n let match:\n | {\n profileId: string;\n profilePath: string;\n deprecated: boolean;\n }\n | undefined;\n inputSource.profiles.some((profileId) => {\n const supportedProfile = supportedProfilesList[profileId];\n if (supportedProfile) {\n match = {\n profileId,\n profilePath: supportedProfile.path,\n deprecated: !!supportedProfile.deprecated,\n };\n }\n return !!match;\n });\n\n if (!match) {\n const supportedProfile = supportedProfilesList[defaultProfile];\n if (!supportedProfile) {\n throw new Error(\n `No matching profile name found and default profile \"${defaultProfile}\" missing.`,\n );\n }\n\n match = {\n profileId: defaultProfile,\n profilePath: supportedProfile.path,\n deprecated: !!supportedProfile.deprecated,\n };\n }\n\n const profile = getGeneratedProfile(match.profilePath);\n return profile;\n}\n\nexport async function fetchProfile(\n inputSource: XRInputSource,\n {\n basePath = DEFAULT_PROFILES_PATH,\n defaultProfile = DEFAULT_PROFILE,\n }: FetchProfileOptions,\n): Promise<InputProfile> {\n const supportedProfilesList = await fetchProfilesList(basePath);\n\n let match:\n | {\n profileId: string;\n profilePath: string;\n deprecated: boolean;\n }\n | undefined;\n inputSource.profiles.some((profileId) => {\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 const supportedProfile = supportedProfilesList[defaultProfile];\n if (!supportedProfile) {\n throw new Error(\n `No matching profile name found and default profile \"${defaultProfile}\" missing.`,\n );\n }\n\n match = {\n profileId: defaultProfile,\n profilePath: `${basePath}/${supportedProfile.path}`,\n deprecated: !!supportedProfile.deprecated,\n };\n }\n\n const profile = await fetchJsonFile(match.profilePath);\n return profile;\n}\n\nexport function loadInputProfile(inputSource: XRInputSource) {\n const profileId = inputSource.profiles[0];\n let profile = fetchProfileSync(inputSource);\n const layout = profile.layouts[inputSource.handedness];\n if (!layout) {\n throw new DOMException('No applicable layout found', 'NotSupportedError');\n }\n return {\n inputSource,\n layout,\n profileId,\n resolvedProfileId: profile.profileId,\n assetPath: `${DEFAULT_PROFILES_PATH}/${profile.profileId}/${layout.assetPath}`,\n };\n}\n"],"names":["getGeneratedProfile"],"mappings":";;AAAA;;;;;AAKG;AAEI,MAAM,qBAAqB,GAChC;AAMF,MAAM,eAAe,GAAG,iBAAiB;AACzC,MAAM,iBAAiB,GAAG,mBAAmB;AAqCtC,eAAe,aAAa,CAAC,IAAY,EAAA;AAC9C,IAAA,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC;AAClC,IAAA,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;AAChB,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B,CAAC,WAAW,CAAC;IAC3C,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC;IACtD,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,MAAM,IAAI,YAAY,CAAC,4BAA4B,EAAE,mBAAmB,CAAC;IAC3E;IACA,OAAO;QACL,WAAW;QACX,MAAM;QACN,SAAS;QACT,iBAAiB,EAAE,OAAO,CAAC,SAAS;QACpC,SAAS,EAAE,CAAA,EAAG,qBAAqB,CAAA,CAAA,EAAI,OAAO,CAAC,SAAS,CAAA,CAAA,EAAI,MAAM,CAAC,SAAS,CAAA,CAAE;KAC/E;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateful-button-axes-device.js","sources":["../../src/gamepad/stateful-button-axes-device.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;AAKG;IAES;AAAZ,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,SAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAW;AACX,IAAA,SAAA,CAAA,SAAA,CAAA,IAAA,CAAA,GAAA,CAAA,CAAA,GAAA,IAAM;AACN,IAAA,SAAA,CAAA,SAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ;AACR,IAAA,SAAA,CAAA,SAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ;AACR,IAAA,SAAA,CAAA,SAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAS;AACX,CAAC,EANW,SAAS,KAAT,SAAS,GAAA,EAAA,CAAA,CAAA;MAmCR,wBAAwB,CAAA;IAkBnC,WAAA,CAAY,MAAwB,EAAE,WAAmB,EAAA;AAjBzC,QAAA,IAAA,CAAA,aAAa,GAAG,IAAI,GAAG,EAAkB;AACzC,QAAA,IAAA,CAAA,WAAW,GAAG,IAAI,GAAG,EAAoC;QAClE,IAAA,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-button-axes-device.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nexport enum AxesState {\n Default = 0,\n Up = 1,\n Down = 2,\n Left = 3,\n Right = 4,\n}\n\nexport type ButtonAxesComponentType =\n | 'trigger'\n | 'squeeze'\n | 'thumbstick'\n | 'touchpad'\n | 'button';\n\nexport type ButtonAxesComponentConfig = {\n type: ButtonAxesComponentType;\n gamepadIndices: Partial<{\n button: number;\n xAxis: number;\n yAxis: number;\n }>;\n};\n\nexport type ButtonAxesLayout = {\n selectComponentId: string;\n components: Record<string, ButtonAxesComponentConfig>;\n};\n\nexport type ButtonLike = {\n pressed: boolean;\n touched?: boolean;\n value?: number;\n};\n\nexport class StatefulButtonAxesDevice {\n public readonly buttonMapping = new Map<string, number>();\n public readonly axesMapping = new Map<string, { x: number; y: number }>();\n public axesThreshold = 0.8;\n\n protected readonly selectComponentId: string;\n private readonly pressedArrs: [Int8Array, Int8Array];\n private readonly touchedArrs: [Int8Array, Int8Array];\n private readonly valueArrs: [Float32Array, Float32Array];\n private readonly axesStates = new Map<\n string,\n { prev: AxesState; curr: AxesState }\n >();\n private readonly axes2DValues = new Map<string, number>();\n private readonly axesValues = new Map<string, { x: number; y: number }>();\n private currentIndex = 1;\n private previousIndex = 0;\n\n constructor(layout: ButtonAxesLayout, buttonCount: number) {\n this.selectComponentId = layout.selectComponentId;\n this.pressedArrs = [\n new Int8Array(buttonCount).fill(0),\n new Int8Array(buttonCount).fill(0),\n ];\n this.touchedArrs = [\n new Int8Array(buttonCount).fill(0),\n new Int8Array(buttonCount).fill(0),\n ];\n this.valueArrs = [\n new Float32Array(buttonCount).fill(0),\n new Float32Array(buttonCount).fill(0),\n ];\n\n Object.entries(layout.components).forEach(([id, config]) => {\n const buttonIdx = config.gamepadIndices.button;\n if (buttonIdx !== undefined) {\n this.buttonMapping.set(id, buttonIdx);\n }\n if (config.type === 'thumbstick' || config.type === 'touchpad') {\n const xAxis = config.gamepadIndices.xAxis;\n const yAxis = config.gamepadIndices.yAxis;\n if (xAxis !== undefined && yAxis !== undefined) {\n this.axesMapping.set(id, { x: xAxis, y: yAxis });\n this.axesValues.set(id, { x: 0, y: 0 });\n this.axes2DValues.set(id, 0);\n this.axesStates.set(id, {\n prev: AxesState.Default,\n curr: AxesState.Default,\n });\n }\n }\n });\n }\n\n update(buttons: ArrayLike<ButtonLike>, axes: ArrayLike<number>): void {\n this.currentIndex = 1 - this.currentIndex;\n this.previousIndex = 1 - this.previousIndex;\n\n for (let idx = 0; idx < this.pressedArrs[this.currentIndex].length; idx++) {\n const button = buttons[idx];\n this.pressedArrs[this.currentIndex][idx] = button?.pressed ? 1 : 0;\n this.touchedArrs[this.currentIndex][idx] = button?.touched ? 1 : 0;\n this.valueArrs[this.currentIndex][idx] = button?.value ?? 0;\n }\n\n this.axesMapping.forEach(({ x: xIdx, y: yIdx }, id) => {\n const axesValue = this.axesValues.get(id)!;\n const axesState = this.axesStates.get(id)!;\n axesState.prev = axesState.curr;\n axesValue.x = axes[xIdx] ?? 0;\n axesValue.y = axes[yIdx] ?? 0;\n const { x, y } = axesValue;\n const value2D = Math.sqrt(x * x + y * y);\n this.axes2DValues.set(id, value2D);\n if (value2D < this.axesThreshold) {\n axesState.curr = AxesState.Default;\n } else if (Math.abs(x) > Math.abs(y)) {\n axesState.curr = x > 0 ? AxesState.Right : AxesState.Left;\n } else {\n axesState.curr = y > 0 ? AxesState.Down : AxesState.Up;\n }\n });\n }\n\n private getButtonState(id: string, stateArr: [Int8Array, Int8Array]) {\n const idx = this.buttonMapping.get(id);\n return idx !== undefined ? stateArr[this.currentIndex][idx] : 0;\n }\n\n getButtonPressedByIdx(idx: number) {\n return !!this.pressedArrs[this.currentIndex][idx];\n }\n\n getButtonPressed(id: string) {\n return !!this.getButtonState(id, this.pressedArrs);\n }\n\n getButtonTouchedByIdx(idx: number) {\n return !!this.touchedArrs[this.currentIndex][idx];\n }\n\n getButtonTouched(id: string) {\n return !!this.getButtonState(id, this.touchedArrs);\n }\n\n getButtonValueByIdx(idx: number) {\n return this.valueArrs[this.currentIndex][idx] ?? 0;\n }\n\n getButtonValue(id: string) {\n const idx = this.buttonMapping.get(id);\n return idx !== undefined ? this.valueArrs[this.currentIndex][idx] : 0;\n }\n\n getButtonDownByIdx(idx: number) {\n return (\n (this.pressedArrs[this.currentIndex][idx] &\n ~this.pressedArrs[this.previousIndex][idx]) !==\n 0\n );\n }\n\n getButtonDown(id: string) {\n const idx = this.buttonMapping.get(id);\n return idx !== undefined\n ? (this.pressedArrs[this.currentIndex][idx] &\n ~this.pressedArrs[this.previousIndex][idx]) !==\n 0\n : false;\n }\n\n getButtonUpByIdx(idx: number) {\n return (\n (~this.pressedArrs[this.currentIndex][idx] &\n this.pressedArrs[this.previousIndex][idx]) !==\n 0\n );\n }\n\n getButtonUp(id: string) {\n const idx = this.buttonMapping.get(id);\n return idx !== undefined\n ? (~this.pressedArrs[this.currentIndex][idx] &\n this.pressedArrs[this.previousIndex][idx]) !==\n 0\n : false;\n }\n\n getSelectStart() {\n return this.getButtonDown(this.selectComponentId);\n }\n\n getSelectEnd() {\n return this.getButtonUp(this.selectComponentId);\n }\n\n getSelecting() {\n return this.getButtonPressed(this.selectComponentId);\n }\n\n getAxesValues(id: string) {\n return this.axesValues.get(id);\n }\n\n getAxesState(id: string) {\n return this.axesStates.get(id)?.curr;\n }\n\n get2DInputValue(id: string) {\n return this.axes2DValues.get(id);\n }\n\n getAxesEnteringState(id: string, state: AxesState) {\n const axesState = this.axesStates.get(id);\n return axesState\n ? axesState.curr === state && axesState.prev !== state\n : false;\n }\n\n getAxesLeavingState(id: string, state: AxesState) {\n const axesState = this.axesStates.get(id);\n return axesState\n ? axesState.curr !== state && axesState.prev === state\n : false;\n }\n\n getAxesEnteringUp(id: string) {\n return this.getAxesEnteringState(id, AxesState.Up);\n }\n\n getAxesEnteringDown(id: string) {\n return this.getAxesEnteringState(id, AxesState.Down);\n }\n\n getAxesEnteringLeft(id: string) {\n return this.getAxesEnteringState(id, AxesState.Left);\n }\n\n getAxesEnteringRight(id: string) {\n return this.getAxesEnteringState(id, AxesState.Right);\n }\n\n getAxesLeavingUp(id: string) {\n return this.getAxesLeavingState(id, AxesState.Up);\n }\n\n getAxesLeavingDown(id: string) {\n return this.getAxesLeavingState(id, AxesState.Down);\n }\n\n getAxesLeavingLeft(id: string) {\n return this.getAxesLeavingState(id, AxesState.Left);\n }\n\n getAxesLeavingRight(id: string) {\n return this.getAxesLeavingState(id, AxesState.Right);\n }\n}\n"],"names":[],"mappings":"AAAA;;;;;AAKG;IAES;AAAZ,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,SAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAW;AACX,IAAA,SAAA,CAAA,SAAA,CAAA,IAAA,CAAA,GAAA,CAAA,CAAA,GAAA,IAAM;AACN,IAAA,SAAA,CAAA,SAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ;AACR,IAAA,SAAA,CAAA,SAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ;AACR,IAAA,SAAA,CAAA,SAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAS;AACX,CAAC,EANW,SAAS,KAAT,SAAS,GAAA,EAAA,CAAA,CAAA;MAmCR,wBAAwB,CAAA;IAkBnC,WAAA,CAAY,MAAwB,EAAE,WAAmB,EAAA;AAjBzC,QAAA,IAAA,CAAA,aAAa,GAAG,IAAI,GAAG,EAAkB;AACzC,QAAA,IAAA,CAAA,WAAW,GAAG,IAAI,GAAG,EAAoC;QAClE,IAAA,CAAA,aAAa,GAAG,GAAG;AAMT,QAAA,IAAA,CAAA,UAAU,GAAG,IAAI,GAAG,EAGlC;AACc,QAAA,IAAA,CAAA,YAAY,GAAG,IAAI,GAAG,EAAkB;AACxC,QAAA,IAAA,CA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AI,SAAS,CAAC,IAAI,KAAK;cAC/C,KAAK;IACX;AAEA,IAAA,iBAAiB,CAAC,EAAU,EAAA;QAC1B,OAAO,IAAI,CAAC,oBAAoB,CAAC,EAAE,EAAE,SAAS,CAAC,EAAE,CAAC;IACpD;AAEA,IAAA,mBAAmB,CAAC,EAAU,EAAA;QAC5B,OAAO,IAAI,CAAC,oBAAoB,CAAC,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC;IACtD;AAEA,IAAA,mBAAmB,CAAC,EAAU,EAAA;QAC5B,OAAO,IAAI,CAAC,oBAAoB,CAAC,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC;IACtD;AAEA,IAAA,oBAAoB,CAAC,EAAU,EAAA;QAC7B,OAAO,IAAI,CAAC,oBAAoB,CAAC,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC;IACvD;AAEA,IAAA,gBAAgB,CAAC,EAAU,EAAA;QACzB,OAAO,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE,SAAS,CAAC,EAAE,CAAC;IACnD;AAEA,IAAA,kBAAkB,CAAC,EAAU,EAAA;QAC3B,OAAO,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC;IACrD;AAEA,IAAA,kBAAkB,CAAC,EAAU,EAAA;QAC3B,OAAO,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC;IACrD;AAEA,IAAA,mBAAmB,CAAC,EAAU,EAAA;QAC5B,OAAO,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC;IACtD;AACD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateful-gamepad.js","sources":["../../src/gamepad/stateful-gamepad.ts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"stateful-gamepad.js","sources":["../../src/gamepad/stateful-gamepad.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport type { InputConfig } from '../visual/adapter/base-visual-adapter.js';\nimport { StatefulButtonAxesDevice } from './stateful-button-axes-device.js';\nexport { AxesState } from './stateful-button-axes-device.js';\n\nexport enum InputComponent {\n Trigger = 'xr-standard-trigger',\n Squeeze = 'xr-standard-squeeze',\n Touchpad = 'xr-standard-touchpad',\n Thumbstick = 'xr-standard-thumbstick',\n A_Button = 'a-button',\n B_Button = 'b-button',\n X_Button = 'x-button',\n Y_Button = 'y-button',\n Thumbrest = 'thumbrest',\n Menu = 'menu',\n}\n\nexport class StatefulGamepad extends StatefulButtonAxesDevice {\n public readonly handedness: XRHandedness;\n public readonly gamepad: Gamepad;\n public readonly inputSource: XRInputSource;\n\n constructor({ inputSource, layout }: InputConfig) {\n super(layout, inputSource.gamepad!.buttons.length);\n this.handedness = inputSource.handedness;\n this.gamepad = inputSource.gamepad!;\n this.inputSource = inputSource;\n }\n\n update() {\n super.update(this.gamepad.buttons, this.gamepad.axes);\n }\n}\n"],"names":[],"mappings":";;;AAAA;;;;;AAKG;IAMS;AAAZ,CAAA,UAAY,cAAc,EAAA;AACxB,IAAA,cAAA,CAAA,SAAA,CAAA,GAAA,qBAA+B;AAC/B,IAAA,cAAA,CAAA,SAAA,CAAA,GAAA,qBAA+B;AAC/B,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,sBAAiC;AACjC,IAAA,cAAA,CAAA,YAAA,CAAA,GAAA,wBAAqC;AACrC,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACrB,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACrB,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACrB,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACrB,IAAA,cAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AACvB,IAAA,cAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACf,CAAC,EAXW,cAAc,KAAd,cAAc,GAAA,EAAA,CAAA,CAAA;AAapB,MAAO,eAAgB,SAAQ,wBAAwB,CAAA;AAK3D,IAAA,WAAA,CAAY,EAAE,WAAW,EAAE,MAAM,EAAe,EAAA;QAC9C,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,OAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;AAClD,QAAA,IAAI,CAAC,UAAU,GAAG,WAAW,CAAC,UAAU;AACxC,QAAA,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC,OAAQ;AACnC,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW;IAChC;IAEA,MAAM,GAAA;AACJ,QAAA,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IACvD;AACD;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -23,4 +23,8 @@ export * from './pointer/ray-pointer.js';
|
|
|
23
23
|
export * from './pointer/multi-pointer.js';
|
|
24
24
|
export * from './pointer/cursor-visual.js';
|
|
25
25
|
export * from './pointer/visibility.js';
|
|
26
|
+
export * from './pointer/filtered-eye-gaze.js';
|
|
27
|
+
export * from './pointer/gaze-candidate-provider.js';
|
|
28
|
+
export * from './pointer/gaze-conecaster.js';
|
|
29
|
+
export * from './pointer/gaze-pointer.js';
|
|
26
30
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,0CAA0C,CAAC;AACzD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yCAAyC,CAAC;AAGxD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,sCAAsC,CAAC;AACrD,cAAc,2CAA2C,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAGlE,cAAc,yCAAyC,CAAC;AACxD,cAAc,gCAAgC,CAAC;AAG/C,cAAc,qCAAqC,CAAC;AAGpD,cAAc,oBAAoB,CAAC;AAGnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,0CAA0C,CAAC;AACzD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yCAAyC,CAAC;AAGxD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,sCAAsC,CAAC;AACrD,cAAc,2CAA2C,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAGlE,cAAc,yCAAyC,CAAC;AACxD,cAAc,gCAAgC,CAAC;AAG/C,cAAc,qCAAqC,CAAC;AAGpD,cAAc,oBAAoB,CAAC;AAGnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sCAAsC,CAAC;AACrD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,4 +17,7 @@ export { RayDisplayMode, RayPointer } from './pointer/ray-pointer.js';
|
|
|
17
17
|
export { InteractorState, MultiPointer } from './pointer/multi-pointer.js';
|
|
18
18
|
export { CursorVisual } from './pointer/cursor-visual.js';
|
|
19
19
|
export { isObjectTreeVisible } from './pointer/visibility.js';
|
|
20
|
+
export { FilteredEyeGaze } from './pointer/filtered-eye-gaze.js';
|
|
21
|
+
export { GazeConecaster, defaultGazeComparer } from './pointer/gaze-conecaster.js';
|
|
22
|
+
export { GazePointer } from './pointer/gaze-pointer.js';
|
|
20
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cursor-visual.js","sources":["../../src/pointer/cursor-visual.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;;;AAKG;AAeH,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS;AAE1B,MAAM,SAAS,GAAG,GAAG;AACrB,IAAI,aAAwC;AAE5C,SAAS,gBAAgB,GAAA;IACvB,IAAI,aAAa,EAAE;AACjB,QAAA,OAAO,aAAa;IACtB;IAEA,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;AAC/C,IAAA,MAAM,CAAC,KAAK,GAAG,SAAS;AACxB,IAAA,MAAM,CAAC,MAAM,GAAG,SAAS;IACzB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAE;AACpC,IAAA,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;AAChD,IAAA,GAAG,CAAC,SAAS,GAAG,OAAO;IACvB,GAAG,CAAC,SAAS,EAAE;IACf,GAAG,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,CAAC,EAAE,CAAC,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C/B;AAEA;;AAEG;IACH,OAAO,GAAA;AACL,QAAA,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE;AAC9B,QAAA,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE;AAC9B,QAAA,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE;IAChC;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"cursor-visual.js","sources":["../../src/pointer/cursor-visual.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport type { Intersection } from '@pmndrs/pointer-events';\nimport {\n CanvasTexture,\n CircleGeometry,\n MathUtils,\n Matrix3,\n Mesh,\n MeshBasicMaterial,\n Quaternion,\n Vector3,\n} from 'three';\nimport type { XROrigin } from '../rig/xr-origin.js';\n\nconst { lerp } = MathUtils;\n\nconst cursorRes = 512;\nlet cursorTexture: CanvasTexture | undefined;\n\nfunction getCursorTexture(): CanvasTexture {\n if (cursorTexture) {\n return cursorTexture;\n }\n\n const canvas = document.createElement('canvas');\n canvas.width = cursorRes;\n canvas.height = cursorRes;\n const ctx = canvas.getContext('2d')!;\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n ctx.fillStyle = 'white';\n ctx.beginPath();\n ctx.arc(cursorRes / 2, cursorRes / 2, (cursorRes / 16) * 7, 0, Math.PI * 2);\n ctx.fill();\n ctx.strokeStyle = 'gray';\n ctx.lineWidth = 3;\n ctx.beginPath();\n ctx.arc(cursorRes / 2, cursorRes / 2, (cursorRes / 16) * 7, 0, Math.PI * 2);\n ctx.stroke();\n cursorTexture = new CanvasTexture(canvas);\n return cursorTexture;\n}\n\nconst ZAxis = new Vector3(0, 0, 1);\nconst offsetHelper = new Vector3();\nconst cursorPosition = new Vector3();\nconst quaternionHelper = new Quaternion();\nconst scratchNormal = new Vector3();\nconst scratchNormalMatrix = new Matrix3();\n\nlet cursorCount = 0;\n\n/**\n * Shared cursor visual that can be updated from any pointer's intersection.\n * Renders as a circle mesh positioned at the intersection point, oriented to the surface normal.\n *\n * @category Pointer\n */\nexport class CursorVisual {\n private cursor: Mesh<CircleGeometry, MeshBasicMaterial>;\n private zOffset: number;\n private focusAlpha = 0;\n\n constructor(\n private xrOrigin: XROrigin,\n pointerIndex: number,\n ) {\n this.cursor = new Mesh(\n new CircleGeometry(0.008),\n new MeshBasicMaterial({\n map: getCursorTexture(),\n transparent: true,\n }),\n );\n this.cursor.renderOrder = Infinity;\n this.cursor.userData.attached = true;\n this.cursor.visible = false;\n this.zOffset = 0.004 + (pointerIndex + cursorCount++) * 0.001;\n xrOrigin.add(this.cursor);\n }\n\n /**\n * Update cursor position and orientation from an intersection.\n */\n updateFromIntersection(\n intersection: Intersection,\n delta: number,\n focused: boolean,\n ): void {\n cursorPosition.copy(intersection.pointOnFace);\n\n this.focusAlpha = lerp(this.focusAlpha, focused ? 1 : 0, 30 * delta);\n\n const cursorScale =\n (Math.max(0, intersection.distance - 0.3) + 1) *\n lerp(1, 0.8, this.focusAlpha);\n\n this.cursor.material.opacity = lerp(0.7, 1, this.focusAlpha);\n this.cursor.scale.setScalar(cursorScale);\n\n const normal = intersection.normal ?? intersection.face?.normal;\n if (normal != null) {\n // Convert local-space normal to world-space using normal matrix to handle non-uniform scales\n scratchNormal.copy(normal);\n scratchNormalMatrix.getNormalMatrix(intersection.object.matrixWorld);\n scratchNormal.applyNormalMatrix(scratchNormalMatrix).normalize();\n // Offset in world space while the intersection position is world-space.\n cursorPosition.addScaledVector(scratchNormal, this.zOffset);\n\n // Build a world-space orientation, then express it in xrOrigin space.\n this.cursor.quaternion.setFromUnitVectors(ZAxis, scratchNormal);\n this.xrOrigin.getWorldQuaternion(quaternionHelper).invert();\n this.cursor.quaternion.premultiply(quaternionHelper);\n } else if (intersection.pointerQuaternion) {\n // Offset along the world-space pointer direction before local conversion.\n offsetHelper.set(0, 0, this.zOffset);\n offsetHelper.applyQuaternion(intersection.pointerQuaternion);\n cursorPosition.add(offsetHelper);\n\n // Fallback: align cursor with the pointer's world-space orientation.\n this.cursor.quaternion.copy(intersection.pointerQuaternion);\n this.xrOrigin.getWorldQuaternion(quaternionHelper).invert();\n this.cursor.quaternion.premultiply(quaternionHelper);\n }\n\n this.xrOrigin.worldToLocal(cursorPosition);\n this.cursor.position.copy(cursorPosition);\n this.cursor.updateMatrix();\n }\n\n /**\n * Set cursor visibility.\n */\n setVisible(visible: boolean): void {\n this.cursor.visible = visible;\n }\n\n /**\n * Dispose of cursor resources.\n */\n dispose(): void {\n this.cursor.geometry.dispose();\n this.cursor.material.dispose();\n this.cursor.removeFromParent();\n }\n}\n"],"names":[],"mappings":";;AAAA;;;;;AAKG;AAeH,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS;AAE1B,MAAM,SAAS,GAAG,GAAG;AACrB,IAAI,aAAwC;AAE5C,SAAS,gBAAgB,GAAA;IACvB,IAAI,aAAa,EAAE;AACjB,QAAA,OAAO,aAAa;IACtB;IAEA,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;AAC/C,IAAA,MAAM,CAAC,KAAK,GAAG,SAAS;AACxB,IAAA,MAAM,CAAC,MAAM,GAAG,SAAS;IACzB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAE;AACpC,IAAA,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;AAChD,IAAA,GAAG,CAAC,SAAS,GAAG,OAAO;IACvB,GAAG,CAAC,SAAS,EAAE;IACf,GAAG,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3E,GAAG,CAAC,IAAI,EAAE;AACV,IAAA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,CAAC,QAAQ,CAAC,OAAO,EAAE;AAC9B,QAAA,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE;IAChC;AACD;;;;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { Quaternion, Vector3 } from 'three';
|
|
8
|
+
export interface FilteredEyeGazeOptions {
|
|
9
|
+
/** Min cutoff frequency in Hz. Lower = smoother at low speeds. */
|
|
10
|
+
minCutoff?: number;
|
|
11
|
+
/** Speed-coefficient. Higher = more responsive when moving fast. */
|
|
12
|
+
beta?: number;
|
|
13
|
+
/** Derivative filter cutoff in Hz. */
|
|
14
|
+
dCutoff?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Adaptive pose smoother for the gaze input source. Position xyz and
|
|
18
|
+
* quaternion xyzw are filtered component-wise; the quaternion is
|
|
19
|
+
* re-normalized after smoothing.
|
|
20
|
+
*
|
|
21
|
+
* Zero per-frame allocations: writes into reusable scratch vectors and the
|
|
22
|
+
* caller's output targets.
|
|
23
|
+
*
|
|
24
|
+
* @category Pointer
|
|
25
|
+
*/
|
|
26
|
+
export declare class FilteredEyeGaze {
|
|
27
|
+
minCutoff: number;
|
|
28
|
+
beta: number;
|
|
29
|
+
dCutoff: number;
|
|
30
|
+
private px;
|
|
31
|
+
private py;
|
|
32
|
+
private pz;
|
|
33
|
+
private qx;
|
|
34
|
+
private qy;
|
|
35
|
+
private qz;
|
|
36
|
+
private qw;
|
|
37
|
+
private readonly alignedQuaternion;
|
|
38
|
+
private readonly previousQuaternion;
|
|
39
|
+
private hasPreviousQuaternion;
|
|
40
|
+
constructor(opts?: FilteredEyeGazeOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Apply the filter to `inPos`/`inQuat`, writing results into `outPos`/`outQuat`.
|
|
43
|
+
* Pass dt in seconds.
|
|
44
|
+
*/
|
|
45
|
+
filter(inPos: Vector3, inQuat: Quaternion, dt: number, outPos: Vector3, outQuat: Quaternion): void;
|
|
46
|
+
reset(): void;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=filtered-eye-gaze.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtered-eye-gaze.d.ts","sourceRoot":"","sources":["../../src/pointer/filtered-eye-gaze.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAyD5C,MAAM,WAAW,sBAAsB;IACrC,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;GASG;AACH,qBAAa,eAAe;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAEvB,OAAO,CAAC,EAAE,CAAuB;IACjC,OAAO,CAAC,EAAE,CAAuB;IACjC,OAAO,CAAC,EAAE,CAAuB;IACjC,OAAO,CAAC,EAAE,CAAuB;IACjC,OAAO,CAAC,EAAE,CAAuB;IACjC,OAAO,CAAC,EAAE,CAAuB;IACjC,OAAO,CAAC,EAAE,CAAuB;IACjC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAoB;IACtD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoB;IACvD,OAAO,CAAC,qBAAqB,CAAS;gBAE1B,IAAI,GAAE,sBAA2B;IAM7C;;;OAGG;IACH,MAAM,CACJ,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,UAAU,EAClB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,UAAU,GAClB,IAAI;IAqCP,KAAK,IAAI,IAAI;CAYd"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Quaternion } from 'three';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Single-scalar OneEuro filter (Casiez et al. 2012). Adaptive smoothing: the
|
|
11
|
+
* cutoff frequency grows with the magnitude of the input's velocity, so slow
|
|
12
|
+
* motion is heavily smoothed (low jitter) while fast motion stays responsive.
|
|
13
|
+
*
|
|
14
|
+
* Reused for each independent scalar (position xyz + quaternion xyzw).
|
|
15
|
+
*/
|
|
16
|
+
class OneEuroScalar {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.hasPrev = false;
|
|
19
|
+
this.prevX = 0;
|
|
20
|
+
this.prevFilteredX = 0;
|
|
21
|
+
this.prevFilteredDx = 0;
|
|
22
|
+
}
|
|
23
|
+
filter(x, dt, minCutoff, beta, dCutoff) {
|
|
24
|
+
if (!this.hasPrev || dt <= 0) {
|
|
25
|
+
this.hasPrev = true;
|
|
26
|
+
this.prevX = x;
|
|
27
|
+
this.prevFilteredX = x;
|
|
28
|
+
this.prevFilteredDx = 0;
|
|
29
|
+
return x;
|
|
30
|
+
}
|
|
31
|
+
const dx = (x - this.prevX) / dt;
|
|
32
|
+
const aDx = lowpassAlpha(dCutoff, dt);
|
|
33
|
+
const filteredDx = aDx * dx + (1 - aDx) * this.prevFilteredDx;
|
|
34
|
+
const cutoff = minCutoff + beta * Math.abs(filteredDx);
|
|
35
|
+
const aX = lowpassAlpha(cutoff, dt);
|
|
36
|
+
const filteredX = aX * x + (1 - aX) * this.prevFilteredX;
|
|
37
|
+
this.prevX = x;
|
|
38
|
+
this.prevFilteredX = filteredX;
|
|
39
|
+
this.prevFilteredDx = filteredDx;
|
|
40
|
+
return filteredX;
|
|
41
|
+
}
|
|
42
|
+
reset() {
|
|
43
|
+
this.hasPrev = false;
|
|
44
|
+
this.prevX = 0;
|
|
45
|
+
this.prevFilteredX = 0;
|
|
46
|
+
this.prevFilteredDx = 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function lowpassAlpha(cutoff, dt) {
|
|
50
|
+
const tau = 1 / (2 * Math.PI * cutoff);
|
|
51
|
+
return 1 / (1 + tau / dt);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Adaptive pose smoother for the gaze input source. Position xyz and
|
|
55
|
+
* quaternion xyzw are filtered component-wise; the quaternion is
|
|
56
|
+
* re-normalized after smoothing.
|
|
57
|
+
*
|
|
58
|
+
* Zero per-frame allocations: writes into reusable scratch vectors and the
|
|
59
|
+
* caller's output targets.
|
|
60
|
+
*
|
|
61
|
+
* @category Pointer
|
|
62
|
+
*/
|
|
63
|
+
class FilteredEyeGaze {
|
|
64
|
+
constructor(opts = {}) {
|
|
65
|
+
var _a, _b, _c;
|
|
66
|
+
this.px = new OneEuroScalar();
|
|
67
|
+
this.py = new OneEuroScalar();
|
|
68
|
+
this.pz = new OneEuroScalar();
|
|
69
|
+
this.qx = new OneEuroScalar();
|
|
70
|
+
this.qy = new OneEuroScalar();
|
|
71
|
+
this.qz = new OneEuroScalar();
|
|
72
|
+
this.qw = new OneEuroScalar();
|
|
73
|
+
this.alignedQuaternion = new Quaternion();
|
|
74
|
+
this.previousQuaternion = new Quaternion();
|
|
75
|
+
this.hasPreviousQuaternion = false;
|
|
76
|
+
this.minCutoff = (_a = opts.minCutoff) !== null && _a !== void 0 ? _a : 1.5;
|
|
77
|
+
this.beta = (_b = opts.beta) !== null && _b !== void 0 ? _b : 0.05;
|
|
78
|
+
this.dCutoff = (_c = opts.dCutoff) !== null && _c !== void 0 ? _c : 1.0;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Apply the filter to `inPos`/`inQuat`, writing results into `outPos`/`outQuat`.
|
|
82
|
+
* Pass dt in seconds.
|
|
83
|
+
*/
|
|
84
|
+
filter(inPos, inQuat, dt, outPos, outQuat) {
|
|
85
|
+
const mc = this.minCutoff;
|
|
86
|
+
const b = this.beta;
|
|
87
|
+
const dc = this.dCutoff;
|
|
88
|
+
// q and -q encode the same rotation. Align every sample to the previous
|
|
89
|
+
// hemisphere before filtering components; otherwise a runtime that flips
|
|
90
|
+
// representation can make the scalar filters interpolate through a zero
|
|
91
|
+
// quaternion and produce a large, artificial gaze jump.
|
|
92
|
+
this.alignedQuaternion.copy(inQuat).normalize();
|
|
93
|
+
if (this.hasPreviousQuaternion &&
|
|
94
|
+
this.alignedQuaternion.dot(this.previousQuaternion) < 0) {
|
|
95
|
+
this.alignedQuaternion.set(-this.alignedQuaternion.x, -this.alignedQuaternion.y, -this.alignedQuaternion.z, -this.alignedQuaternion.w);
|
|
96
|
+
}
|
|
97
|
+
this.previousQuaternion.copy(this.alignedQuaternion);
|
|
98
|
+
this.hasPreviousQuaternion = true;
|
|
99
|
+
outPos.set(this.px.filter(inPos.x, dt, mc, b, dc), this.py.filter(inPos.y, dt, mc, b, dc), this.pz.filter(inPos.z, dt, mc, b, dc));
|
|
100
|
+
outQuat.set(this.qx.filter(this.alignedQuaternion.x, dt, mc, b, dc), this.qy.filter(this.alignedQuaternion.y, dt, mc, b, dc), this.qz.filter(this.alignedQuaternion.z, dt, mc, b, dc), this.qw.filter(this.alignedQuaternion.w, dt, mc, b, dc));
|
|
101
|
+
outQuat.normalize();
|
|
102
|
+
}
|
|
103
|
+
reset() {
|
|
104
|
+
this.px.reset();
|
|
105
|
+
this.py.reset();
|
|
106
|
+
this.pz.reset();
|
|
107
|
+
this.qx.reset();
|
|
108
|
+
this.qy.reset();
|
|
109
|
+
this.qz.reset();
|
|
110
|
+
this.qw.reset();
|
|
111
|
+
this.hasPreviousQuaternion = false;
|
|
112
|
+
this.alignedQuaternion.identity();
|
|
113
|
+
this.previousQuaternion.identity();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { FilteredEyeGaze };
|
|
118
|
+
//# sourceMappingURL=filtered-eye-gaze.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtered-eye-gaze.js","sources":["../../src/pointer/filtered-eye-gaze.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { Quaternion, Vector3 } from 'three';\n\n/**\n * Single-scalar OneEuro filter (Casiez et al. 2012). Adaptive smoothing: the\n * cutoff frequency grows with the magnitude of the input's velocity, so slow\n * motion is heavily smoothed (low jitter) while fast motion stays responsive.\n *\n * Reused for each independent scalar (position xyz + quaternion xyzw).\n */\nclass OneEuroScalar {\n private hasPrev = false;\n private prevX = 0;\n private prevFilteredX = 0;\n private prevFilteredDx = 0;\n\n filter(\n x: number,\n dt: number,\n minCutoff: number,\n beta: number,\n dCutoff: number,\n ): number {\n if (!this.hasPrev || dt <= 0) {\n this.hasPrev = true;\n this.prevX = x;\n this.prevFilteredX = x;\n this.prevFilteredDx = 0;\n return x;\n }\n\n const dx = (x - this.prevX) / dt;\n const aDx = lowpassAlpha(dCutoff, dt);\n const filteredDx = aDx * dx + (1 - aDx) * this.prevFilteredDx;\n\n const cutoff = minCutoff + beta * Math.abs(filteredDx);\n const aX = lowpassAlpha(cutoff, dt);\n const filteredX = aX * x + (1 - aX) * this.prevFilteredX;\n\n this.prevX = x;\n this.prevFilteredX = filteredX;\n this.prevFilteredDx = filteredDx;\n return filteredX;\n }\n\n reset(): void {\n this.hasPrev = false;\n this.prevX = 0;\n this.prevFilteredX = 0;\n this.prevFilteredDx = 0;\n }\n}\n\nfunction lowpassAlpha(cutoff: number, dt: number): number {\n const tau = 1 / (2 * Math.PI * cutoff);\n return 1 / (1 + tau / dt);\n}\n\nexport interface FilteredEyeGazeOptions {\n /** Min cutoff frequency in Hz. Lower = smoother at low speeds. */\n minCutoff?: number;\n /** Speed-coefficient. Higher = more responsive when moving fast. */\n beta?: number;\n /** Derivative filter cutoff in Hz. */\n dCutoff?: number;\n}\n\n/**\n * Adaptive pose smoother for the gaze input source. Position xyz and\n * quaternion xyzw are filtered component-wise; the quaternion is\n * re-normalized after smoothing.\n *\n * Zero per-frame allocations: writes into reusable scratch vectors and the\n * caller's output targets.\n *\n * @category Pointer\n */\nexport class FilteredEyeGaze {\n public minCutoff: number;\n public beta: number;\n public dCutoff: number;\n\n private px = new OneEuroScalar();\n private py = new OneEuroScalar();\n private pz = new OneEuroScalar();\n private qx = new OneEuroScalar();\n private qy = new OneEuroScalar();\n private qz = new OneEuroScalar();\n private qw = new OneEuroScalar();\n private readonly alignedQuaternion = new Quaternion();\n private readonly previousQuaternion = new Quaternion();\n private hasPreviousQuaternion = false;\n\n constructor(opts: FilteredEyeGazeOptions = {}) {\n this.minCutoff = opts.minCutoff ?? 1.5;\n this.beta = opts.beta ?? 0.05;\n this.dCutoff = opts.dCutoff ?? 1.0;\n }\n\n /**\n * Apply the filter to `inPos`/`inQuat`, writing results into `outPos`/`outQuat`.\n * Pass dt in seconds.\n */\n filter(\n inPos: Vector3,\n inQuat: Quaternion,\n dt: number,\n outPos: Vector3,\n outQuat: Quaternion,\n ): void {\n const mc = this.minCutoff;\n const b = this.beta;\n const dc = this.dCutoff;\n\n // q and -q encode the same rotation. Align every sample to the previous\n // hemisphere before filtering components; otherwise a runtime that flips\n // representation can make the scalar filters interpolate through a zero\n // quaternion and produce a large, artificial gaze jump.\n this.alignedQuaternion.copy(inQuat).normalize();\n if (\n this.hasPreviousQuaternion &&\n this.alignedQuaternion.dot(this.previousQuaternion) < 0\n ) {\n this.alignedQuaternion.set(\n -this.alignedQuaternion.x,\n -this.alignedQuaternion.y,\n -this.alignedQuaternion.z,\n -this.alignedQuaternion.w,\n );\n }\n this.previousQuaternion.copy(this.alignedQuaternion);\n this.hasPreviousQuaternion = true;\n outPos.set(\n this.px.filter(inPos.x, dt, mc, b, dc),\n this.py.filter(inPos.y, dt, mc, b, dc),\n this.pz.filter(inPos.z, dt, mc, b, dc),\n );\n outQuat.set(\n this.qx.filter(this.alignedQuaternion.x, dt, mc, b, dc),\n this.qy.filter(this.alignedQuaternion.y, dt, mc, b, dc),\n this.qz.filter(this.alignedQuaternion.z, dt, mc, b, dc),\n this.qw.filter(this.alignedQuaternion.w, dt, mc, b, dc),\n );\n outQuat.normalize();\n }\n\n reset(): void {\n this.px.reset();\n this.py.reset();\n this.pz.reset();\n this.qx.reset();\n this.qy.reset();\n this.qz.reset();\n this.qw.reset();\n this.hasPreviousQuaternion = false;\n this.alignedQuaternion.identity();\n this.previousQuaternion.identity();\n }\n}\n"],"names":[],"mappings":";;AAAA;;;;;AAKG;AAIH;;;;;;AAMG;AACH,MAAM,aAAa,CAAA;AAAnB,IAAA,WAAA,GAAA;QACU,IAAA,CAAA,OAAO,GAAG,KAAK;QACf,IAAA,CAAA,KAAK,GAAG,CAAC;QACT,IAAA,CAAA,aAAa,GAAG,CAAC;QACjB,IAAA,CAAA,cAAc,GAAG,CAAC;IAqC5B;IAnCE,MAAM,CACJ,CAAS,EACT,EAAU,EACV,SAAiB,EACjB,IAAY,EACZ,OAAe,EAAA;QAEf,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,IAAI,CAAC,EAAE;AAC5B,YAAA,IAAI,CAAC,OAAO,GAAG,IAAI;AACnB,YAAA,IAAI,CAAC,KAAK,GAAG,CAAC;AACd,YAAA,IAAI,CAAC,aAAa,GAAG,CAAC;AACtB,YAAA,IAAI,CAAC,cAAc,GAAG,CAAC;AACvB,YAAA,OAAO,CAAC;QACV;QAEA,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE;QAChC,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC;AACrC,QAAA,MAAM,UAA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CAAC,KAAK,EAAE;AACf,QAAA,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE;AACf,QAAA,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE;AACf,QAAA,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE;AACf,QAAA,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE;AACf,QAAA,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE;AACf,QAAA,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE;AACf,QAAA,IAAI,CAAC,qBAAqB,GAAG,KAAK;AAClC,QAAA,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE;AACjC,QAAA,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE;IACpC;AACD;;;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Intersection } from '@pmndrs/pointer-events';
|
|
8
|
+
import type { Object3D, Vector3 } from 'three';
|
|
9
|
+
/**
|
|
10
|
+
* Per-frame context passed into a GazeCandidateProvider. All fields are owned
|
|
11
|
+
* by the GazePointer and reused across frames; providers MUST NOT retain
|
|
12
|
+
* references to them past `update()`.
|
|
13
|
+
*/
|
|
14
|
+
export interface GazeCandidateContext {
|
|
15
|
+
/** Smoothed gaze origin in world space. */
|
|
16
|
+
origin: Vector3;
|
|
17
|
+
/** Smoothed gaze forward direction in world space (unit length). */
|
|
18
|
+
direction: Vector3;
|
|
19
|
+
/** Candidate Object3D roots to consider. */
|
|
20
|
+
candidates: ReadonlyArray<Object3D>;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve a pointer-events-compatible ray intersection inside one candidate
|
|
23
|
+
* root. The direction is world-space and unit length. Implementations must
|
|
24
|
+
* treat a `null` result as an ineligible or non-raycastable surface.
|
|
25
|
+
*/
|
|
26
|
+
intersectCandidate: (candidate: Object3D, direction: Vector3) => Intersection | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Result of a candidate query. The provider is responsible for computing
|
|
30
|
+
* angular distance and choosing the hit point/normal/face.
|
|
31
|
+
*/
|
|
32
|
+
export interface GazeHit {
|
|
33
|
+
/** The Object3D root that won this frame (typically the entity's root). */
|
|
34
|
+
object: Object3D;
|
|
35
|
+
/** The authoritative pointer-events intersection on the actionable leaf. */
|
|
36
|
+
intersection: Intersection;
|
|
37
|
+
/** Angular distance (radians) between gaze direction and direction-to-target. */
|
|
38
|
+
angularDistance: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Pluggable candidate-selection strategy for GazePointer. Implementations
|
|
42
|
+
* decide how to score and choose a target each frame.
|
|
43
|
+
*
|
|
44
|
+
* @category Pointer
|
|
45
|
+
*/
|
|
46
|
+
export interface GazeCandidateProvider {
|
|
47
|
+
/**
|
|
48
|
+
* Compute the best hit for this frame.
|
|
49
|
+
* @param time Elapsed time in seconds.
|
|
50
|
+
* @param dt Frame delta in seconds.
|
|
51
|
+
* @param ctx Per-frame gaze context. Do not retain references.
|
|
52
|
+
* @returns Best hit, or `null` if no candidate qualifies.
|
|
53
|
+
*/
|
|
54
|
+
update(time: number, dt: number, ctx: GazeCandidateContext): GazeHit | null;
|
|
55
|
+
/** Called when gaze becomes invalid (session end, suppression, etc.). */
|
|
56
|
+
reset(): void;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=gaze-candidate-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gaze-candidate-provider.d.ts","sourceRoot":"","sources":["../../src/pointer/gaze-candidate-provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE/C;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,2CAA2C;IAC3C,MAAM,EAAE,OAAO,CAAC;IAChB,oEAAoE;IACpE,SAAS,EAAE,OAAO,CAAC;IACnB,4CAA4C;IAC5C,UAAU,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IACpC;;;;OAIG;IACH,kBAAkB,EAAE,CAClB,SAAS,EAAE,QAAQ,EACnB,SAAS,EAAE,OAAO,KACf,YAAY,GAAG,IAAI,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,2EAA2E;IAC3E,MAAM,EAAE,QAAQ,CAAC;IACjB,4EAA4E;IAC5E,YAAY,EAAE,YAAY,CAAC;IAC3B,iFAAiF;IACjF,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,oBAAoB,GAAG,OAAO,GAAG,IAAI,CAAC;IAE5E,yEAAyE;IACzE,KAAK,IAAI,IAAI,CAAC;CACf"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { GazeCandidateContext, GazeCandidateProvider, GazeHit } from './gaze-candidate-provider.js';
|
|
8
|
+
/**
|
|
9
|
+
* Comparator over two `GazeHit` candidates. Return < 0 if `a` wins, > 0 if `b`
|
|
10
|
+
* wins, 0 for unchanged. The conecaster keeps the running best by comparing
|
|
11
|
+
* each new candidate against the current winner.
|
|
12
|
+
*/
|
|
13
|
+
export type GazeComparer = (a: GazeHit, b: GazeHit) => number;
|
|
14
|
+
/**
|
|
15
|
+
* Default comparer: closer-by-angle wins, then closer-by-distance.
|
|
16
|
+
*/
|
|
17
|
+
export declare const defaultGazeComparer: GazeComparer;
|
|
18
|
+
export interface GazeConecasterOptions {
|
|
19
|
+
/** Cone half-angle in radians. */
|
|
20
|
+
coneAngle?: number;
|
|
21
|
+
/** Cone length in meters. */
|
|
22
|
+
coneLength?: number;
|
|
23
|
+
/** Dwell-consensus window in seconds. */
|
|
24
|
+
dwellWindowSeconds?: number;
|
|
25
|
+
/** Custom comparer; defaults to {@link defaultGazeComparer}. */
|
|
26
|
+
comparer?: GazeComparer;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Default candidate provider: cone-membership filter + pointer-compatible
|
|
30
|
+
* surface resolution + time-weighted dwell consensus.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* - **Membership**: a coarse sphere distance reject prunes far candidates,
|
|
34
|
+
* then a precise OBB closest-point test admits the candidate iff the angle
|
|
35
|
+
* from the gaze direction to the closest point on its oriented bounding
|
|
36
|
+
* box (its local AABB transformed by `matrixWorld`) is within `coneAngle`.
|
|
37
|
+
* This avoids the bounding-sphere overestimation that would let large flat
|
|
38
|
+
* panels register hover from far past their visible silhouette.
|
|
39
|
+
* - **Geometry**: survivors are resolved by the callback supplied in
|
|
40
|
+
* {@link GazeCandidateContext}, so the exact same pointer-event eligibility
|
|
41
|
+
* and ordering rules are used for acquisition and dispatch.
|
|
42
|
+
* - **Comparer**: per-frame best is chosen by `comparer` (default angle ->
|
|
43
|
+
* distance).
|
|
44
|
+
* - **Dwell**: per-frame winners are appended to a ring buffer; samples older
|
|
45
|
+
* than `dwellWindowSeconds` are dropped; the object with the largest
|
|
46
|
+
* cumulative dt inside the window wins.
|
|
47
|
+
*
|
|
48
|
+
* @category Pointer
|
|
49
|
+
*/
|
|
50
|
+
export declare class GazeConecaster implements GazeCandidateProvider {
|
|
51
|
+
coneAngle: number;
|
|
52
|
+
coneLength: number;
|
|
53
|
+
dwellWindowSeconds: number;
|
|
54
|
+
comparer: GazeComparer;
|
|
55
|
+
private readonly sphere;
|
|
56
|
+
private readonly box;
|
|
57
|
+
private readonly localBox;
|
|
58
|
+
private readonly invWorld;
|
|
59
|
+
private readonly tmpMat;
|
|
60
|
+
private readonly tmpBox;
|
|
61
|
+
private readonly toCandidate;
|
|
62
|
+
private readonly sphereCenter;
|
|
63
|
+
private readonly localOrigin;
|
|
64
|
+
private readonly localDirection;
|
|
65
|
+
private readonly localBoxClosest;
|
|
66
|
+
private readonly localRayClosest;
|
|
67
|
+
private readonly worldBoxClosest;
|
|
68
|
+
private readonly worldBoxCenter;
|
|
69
|
+
private readonly localBoxCenter;
|
|
70
|
+
private pointBoundsFallback;
|
|
71
|
+
/** Ring of dwell samples (reused). */
|
|
72
|
+
private readonly dwellRing;
|
|
73
|
+
private dwellHead;
|
|
74
|
+
private dwellSize;
|
|
75
|
+
private readonly dwellCapacity;
|
|
76
|
+
/** Last reported dwell winner for the public `getDwellWinner()`. */
|
|
77
|
+
private currentDwellWinner;
|
|
78
|
+
constructor(opts?: GazeConecasterOptions);
|
|
79
|
+
update(time: number, dt: number, ctx: GazeCandidateContext): GazeHit | null;
|
|
80
|
+
reset(): void;
|
|
81
|
+
/** Internal: scan all candidates and return the best in-cone hit, or null. */
|
|
82
|
+
private findFrameBest;
|
|
83
|
+
/**
|
|
84
|
+
* Resolve a real pointer-events intersection for one in-cone target. The raw
|
|
85
|
+
* gaze ray wins when it already hits. Otherwise the ray bends first just
|
|
86
|
+
* inside the closest point on the candidate OBB, then tries the exact point,
|
|
87
|
+
* and finally its center.
|
|
88
|
+
*/
|
|
89
|
+
private resolveSurface;
|
|
90
|
+
/**
|
|
91
|
+
* Build both the world-space enclosing sphere (used for cone-membership)
|
|
92
|
+
* and a candidate-local AABB (used by the OBB fallback) in a single subtree
|
|
93
|
+
* walk. The local AABB is tighter than the world AABB for rotated objects:
|
|
94
|
+
* the cone-ring + OBB fallback uses it to produce a much better silhouette
|
|
95
|
+
* point than a sphere when the on-axis raycast misses.
|
|
96
|
+
*
|
|
97
|
+
* Results land on `this.sphere` and `this.localBox`. The local AABB is
|
|
98
|
+
* meaningful in `obj`'s local frame and must be transformed by
|
|
99
|
+
* `obj.matrixWorld` to land in world space.
|
|
100
|
+
*/
|
|
101
|
+
private computeBounds;
|
|
102
|
+
/**
|
|
103
|
+
* Manual `expandByObject` that swallows per-node failures (missing
|
|
104
|
+
* position attribute, null bounding box, etc.) instead of letting one bad
|
|
105
|
+
* descendant abort the whole subtree. Accumulates BOTH the world-space
|
|
106
|
+
* AABB (for cone-membership) and the candidate-local AABB (for the OBB
|
|
107
|
+
* fallback) in the same traversal.
|
|
108
|
+
*/
|
|
109
|
+
private expandSafely;
|
|
110
|
+
/**
|
|
111
|
+
* Closest point on the candidate's oriented bounding box (its local AABB
|
|
112
|
+
* transformed by `obj.matrixWorld`) to the gaze ray, in world space.
|
|
113
|
+
*
|
|
114
|
+
* Works in local space to avoid building 12 oriented edges in world: bring
|
|
115
|
+
* the ray into the candidate's frame, run iterative AABB-vs-line refinement
|
|
116
|
+
* (a few passes is plenty — it converges quadratically), then map the point
|
|
117
|
+
* back to world.
|
|
118
|
+
*/
|
|
119
|
+
private closestPointOnObb;
|
|
120
|
+
private recordDwell;
|
|
121
|
+
private pruneDwell;
|
|
122
|
+
private electDwellWinner;
|
|
123
|
+
/** Resolve the elected object against the current pose, never a stale hit. */
|
|
124
|
+
private resolveDwellWinner;
|
|
125
|
+
private removeDwellObject;
|
|
126
|
+
private clearDwellSlot;
|
|
127
|
+
/** Current dwell winner, or null. */
|
|
128
|
+
getDwellWinner(): GazeHit | null;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=gaze-conecaster.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gaze-conecaster.d.ts","sourceRoot":"","sources":["../../src/pointer/gaze-conecaster.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,o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