@iwsdk/xr-input 1.0.0-rc.1 → 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.
Files changed (36) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +3 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/pointer/filtered-eye-gaze.d.ts +48 -0
  6. package/dist/pointer/filtered-eye-gaze.d.ts.map +1 -0
  7. package/dist/pointer/filtered-eye-gaze.js +118 -0
  8. package/dist/pointer/filtered-eye-gaze.js.map +1 -0
  9. package/dist/pointer/gaze-candidate-provider.d.ts +58 -0
  10. package/dist/pointer/gaze-candidate-provider.d.ts.map +1 -0
  11. package/dist/pointer/gaze-conecaster.d.ts +130 -0
  12. package/dist/pointer/gaze-conecaster.d.ts.map +1 -0
  13. package/dist/pointer/gaze-conecaster.js +456 -0
  14. package/dist/pointer/gaze-conecaster.js.map +1 -0
  15. package/dist/pointer/gaze-pointer.d.ts +266 -0
  16. package/dist/pointer/gaze-pointer.d.ts.map +1 -0
  17. package/dist/pointer/gaze-pointer.js +865 -0
  18. package/dist/pointer/gaze-pointer.js.map +1 -0
  19. package/dist/pointer/multi-pointer.d.ts +21 -6
  20. package/dist/pointer/multi-pointer.d.ts.map +1 -1
  21. package/dist/pointer/multi-pointer.js +52 -12
  22. package/dist/pointer/multi-pointer.js.map +1 -1
  23. package/dist/rig/xr-origin.d.ts +26 -0
  24. package/dist/rig/xr-origin.d.ts.map +1 -1
  25. package/dist/rig/xr-origin.js +25 -1
  26. package/dist/rig/xr-origin.js.map +1 -1
  27. package/dist/version.d.ts +1 -1
  28. package/dist/visual/adapter/hand-visual-adapter.d.ts +9 -0
  29. package/dist/visual/adapter/hand-visual-adapter.d.ts.map +1 -1
  30. package/dist/visual/adapter/hand-visual-adapter.js +47 -9
  31. package/dist/visual/adapter/hand-visual-adapter.js.map +1 -1
  32. package/dist/xr-input-manager.d.ts +57 -1
  33. package/dist/xr-input-manager.d.ts.map +1 -1
  34. package/dist/xr-input-manager.js +285 -15
  35. package/dist/xr-input-manager.js.map +1 -1
  36. package/package.json +1 -1
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
@@ -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":";;;;;;;;;;;;;;;;;;;;;"}
@@ -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,UAAU,GAAG,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,cAAc;AAE7D,QAAA,MAAM,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;QACtD,MAAM,EAAE,GAAG,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;AACnC,QAAA,MAAM,SA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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,oBAAoB,EACpB,qBAAqB,EACrB,OAAO,EACR,MAAM,8BAA8B,CAAC;AAGtC;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC;AAQ9D;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAMjC,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gEAAgE;IAChE,QAA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