iwer 0.0.1

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 (161) hide show
  1. package/build/iwer.js +4628 -0
  2. package/build/iwer.min.js +1 -0
  3. package/build/iwer.module.js +4591 -0
  4. package/build/iwer.module.min.js +1 -0
  5. package/lib/action/ActionPlayer.d.ts +75 -0
  6. package/lib/action/ActionPlayer.d.ts.map +1 -0
  7. package/lib/action/ActionPlayer.js +206 -0
  8. package/lib/action/ActionPlayer.js.map +1 -0
  9. package/lib/action/ActionRecorder.d.ts +59 -0
  10. package/lib/action/ActionRecorder.d.ts.map +1 -0
  11. package/lib/action/ActionRecorder.js +162 -0
  12. package/lib/action/ActionRecorder.js.map +1 -0
  13. package/lib/action/Capture.d.ts +3 -0
  14. package/lib/action/Capture.d.ts.map +1 -0
  15. package/lib/action/Capture.js +26907 -0
  16. package/lib/action/Capture.js.map +1 -0
  17. package/lib/device/XRController.d.ts +24 -0
  18. package/lib/device/XRController.d.ts.map +1 -0
  19. package/lib/device/XRController.js +82 -0
  20. package/lib/device/XRController.js.map +1 -0
  21. package/lib/device/XRDevice.d.ts +142 -0
  22. package/lib/device/XRDevice.d.ts.map +1 -0
  23. package/lib/device/XRDevice.js +370 -0
  24. package/lib/device/XRDevice.js.map +1 -0
  25. package/lib/device/XRHandInput.d.ts +44 -0
  26. package/lib/device/XRHandInput.d.ts.map +1 -0
  27. package/lib/device/XRHandInput.js +133 -0
  28. package/lib/device/XRHandInput.js.map +1 -0
  29. package/lib/device/XRTrackedInput.d.ts +22 -0
  30. package/lib/device/XRTrackedInput.d.ts.map +1 -0
  31. package/lib/device/XRTrackedInput.js +89 -0
  32. package/lib/device/XRTrackedInput.js.map +1 -0
  33. package/lib/device/configs/controller/meta.d.ts +6 -0
  34. package/lib/device/configs/controller/meta.d.ts.map +1 -0
  35. package/lib/device/configs/controller/meta.js +152 -0
  36. package/lib/device/configs/controller/meta.js.map +1 -0
  37. package/lib/device/configs/hand/pinch.d.ts +3 -0
  38. package/lib/device/configs/hand/pinch.d.ts.map +1 -0
  39. package/lib/device/configs/hand/pinch.js +237 -0
  40. package/lib/device/configs/hand/pinch.js.map +1 -0
  41. package/lib/device/configs/hand/point.d.ts +3 -0
  42. package/lib/device/configs/hand/point.d.ts.map +1 -0
  43. package/lib/device/configs/hand/point.js +236 -0
  44. package/lib/device/configs/hand/point.js.map +1 -0
  45. package/lib/device/configs/hand/relaxed.d.ts +3 -0
  46. package/lib/device/configs/hand/relaxed.d.ts.map +1 -0
  47. package/lib/device/configs/hand/relaxed.js +236 -0
  48. package/lib/device/configs/hand/relaxed.js.map +1 -0
  49. package/lib/device/configs/headset/meta.d.ts +6 -0
  50. package/lib/device/configs/headset/meta.d.ts.map +1 -0
  51. package/lib/device/configs/headset/meta.js +99 -0
  52. package/lib/device/configs/headset/meta.js.map +1 -0
  53. package/lib/device/controllers.d.ts +31 -0
  54. package/lib/device/controllers.d.ts.map +1 -0
  55. package/lib/device/controllers.js +8 -0
  56. package/lib/device/controllers.js.map +1 -0
  57. package/lib/events/XRInputSourceEvent.d.ts +16 -0
  58. package/lib/events/XRInputSourceEvent.d.ts.map +1 -0
  59. package/lib/events/XRInputSourceEvent.js +14 -0
  60. package/lib/events/XRInputSourceEvent.js.map +1 -0
  61. package/lib/events/XRInputSourcesChangeEvent.d.ts +18 -0
  62. package/lib/events/XRInputSourcesChangeEvent.d.ts.map +1 -0
  63. package/lib/events/XRInputSourcesChangeEvent.js +18 -0
  64. package/lib/events/XRInputSourcesChangeEvent.js.map +1 -0
  65. package/lib/events/XRReferenceSpaceEvent.d.ts +16 -0
  66. package/lib/events/XRReferenceSpaceEvent.d.ts.map +1 -0
  67. package/lib/events/XRReferenceSpaceEvent.js +11 -0
  68. package/lib/events/XRReferenceSpaceEvent.js.map +1 -0
  69. package/lib/events/XRSessionEvent.d.ts +13 -0
  70. package/lib/events/XRSessionEvent.d.ts.map +1 -0
  71. package/lib/events/XRSessionEvent.js +10 -0
  72. package/lib/events/XRSessionEvent.js.map +1 -0
  73. package/lib/frameloop/XRFrame.d.ts +28 -0
  74. package/lib/frameloop/XRFrame.d.ts.map +1 -0
  75. package/lib/frameloop/XRFrame.js +117 -0
  76. package/lib/frameloop/XRFrame.js.map +1 -0
  77. package/lib/gamepad/Gamepad.d.ts +72 -0
  78. package/lib/gamepad/Gamepad.d.ts.map +1 -0
  79. package/lib/gamepad/Gamepad.js +126 -0
  80. package/lib/gamepad/Gamepad.js.map +1 -0
  81. package/lib/index.d.ts +24 -0
  82. package/lib/index.d.ts.map +1 -0
  83. package/lib/index.js +36 -0
  84. package/lib/index.js.map +1 -0
  85. package/lib/initialization/XRSystem.d.ts +13 -0
  86. package/lib/initialization/XRSystem.d.ts.map +1 -0
  87. package/lib/initialization/XRSystem.js +65 -0
  88. package/lib/initialization/XRSystem.js.map +1 -0
  89. package/lib/input/XRHand.d.ts +31 -0
  90. package/lib/input/XRHand.d.ts.map +1 -0
  91. package/lib/input/XRHand.js +31 -0
  92. package/lib/input/XRHand.js.map +1 -0
  93. package/lib/input/XRInputSource.d.ts +37 -0
  94. package/lib/input/XRInputSource.d.ts.map +1 -0
  95. package/lib/input/XRInputSource.js +51 -0
  96. package/lib/input/XRInputSource.js.map +1 -0
  97. package/lib/input/XRInputSourceArray.d.ts +11 -0
  98. package/lib/input/XRInputSourceArray.d.ts.map +1 -0
  99. package/lib/input/XRInputSourceArray.js +17 -0
  100. package/lib/input/XRInputSourceArray.js.map +1 -0
  101. package/lib/layers/XRWebGLLayer.d.ts +31 -0
  102. package/lib/layers/XRWebGLLayer.d.ts.map +1 -0
  103. package/lib/layers/XRWebGLLayer.js +67 -0
  104. package/lib/layers/XRWebGLLayer.js.map +1 -0
  105. package/lib/pose/XRJointPose.d.ts +11 -0
  106. package/lib/pose/XRJointPose.d.ts.map +1 -0
  107. package/lib/pose/XRJointPose.js +12 -0
  108. package/lib/pose/XRJointPose.js.map +1 -0
  109. package/lib/pose/XRPose.d.ts +16 -0
  110. package/lib/pose/XRPose.d.ts.map +1 -0
  111. package/lib/pose/XRPose.js +24 -0
  112. package/lib/pose/XRPose.js.map +1 -0
  113. package/lib/pose/XRViewerPose.d.ts +12 -0
  114. package/lib/pose/XRViewerPose.d.ts.map +1 -0
  115. package/lib/pose/XRViewerPose.js +14 -0
  116. package/lib/pose/XRViewerPose.js.map +1 -0
  117. package/lib/primitives/XRRigidTransform.d.ts +17 -0
  118. package/lib/primitives/XRRigidTransform.d.ts.map +1 -0
  119. package/lib/primitives/XRRigidTransform.js +54 -0
  120. package/lib/primitives/XRRigidTransform.js.map +1 -0
  121. package/lib/session/XRRenderState.d.ts +22 -0
  122. package/lib/session/XRRenderState.d.ts.map +1 -0
  123. package/lib/session/XRRenderState.js +26 -0
  124. package/lib/session/XRRenderState.js.map +1 -0
  125. package/lib/session/XRSession.d.ts +103 -0
  126. package/lib/session/XRSession.d.ts.map +1 -0
  127. package/lib/session/XRSession.js +459 -0
  128. package/lib/session/XRSession.js.map +1 -0
  129. package/lib/spaces/XRJointSpace.d.ts +13 -0
  130. package/lib/spaces/XRJointSpace.d.ts.map +1 -0
  131. package/lib/spaces/XRJointSpace.js +12 -0
  132. package/lib/spaces/XRJointSpace.js.map +1 -0
  133. package/lib/spaces/XRReferenceSpace.d.ts +22 -0
  134. package/lib/spaces/XRReferenceSpace.d.ts.map +1 -0
  135. package/lib/spaces/XRReferenceSpace.js +42 -0
  136. package/lib/spaces/XRReferenceSpace.js.map +1 -0
  137. package/lib/spaces/XRSpace.d.ts +20 -0
  138. package/lib/spaces/XRSpace.d.ts.map +1 -0
  139. package/lib/spaces/XRSpace.js +45 -0
  140. package/lib/spaces/XRSpace.js.map +1 -0
  141. package/lib/utils/DOMPointReadOnly.d.ts +17 -0
  142. package/lib/utils/DOMPointReadOnly.d.ts.map +1 -0
  143. package/lib/utils/DOMPointReadOnly.js +26 -0
  144. package/lib/utils/DOMPointReadOnly.js.map +1 -0
  145. package/lib/utils/Math.d.ts +49 -0
  146. package/lib/utils/Math.d.ts.map +1 -0
  147. package/lib/utils/Math.js +129 -0
  148. package/lib/utils/Math.js.map +1 -0
  149. package/lib/version.d.ts +2 -0
  150. package/lib/version.d.ts.map +1 -0
  151. package/lib/version.js +2 -0
  152. package/lib/version.js.map +1 -0
  153. package/lib/views/XRView.d.ts +25 -0
  154. package/lib/views/XRView.d.ts.map +1 -0
  155. package/lib/views/XRView.js +39 -0
  156. package/lib/views/XRView.js.map +1 -0
  157. package/lib/views/XRViewport.d.ts +15 -0
  158. package/lib/views/XRViewport.d.ts.map +1 -0
  159. package/lib/views/XRViewport.js +19 -0
  160. package/lib/views/XRViewport.js.map +1 -0
  161. package/package.json +63 -0
@@ -0,0 +1,4591 @@
1
+ /**
2
+ * Common utilities
3
+ * @module glMatrix
4
+ */
5
+ // Configuration Constants
6
+ var EPSILON = 0.000001;
7
+ var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
8
+ if (!Math.hypot) Math.hypot = function () {
9
+ var y = 0,
10
+ i = arguments.length;
11
+
12
+ while (i--) {
13
+ y += arguments[i] * arguments[i];
14
+ }
15
+
16
+ return Math.sqrt(y);
17
+ };
18
+
19
+ /**
20
+ * 3x3 Matrix
21
+ * @module mat3
22
+ */
23
+
24
+ /**
25
+ * Creates a new identity mat3
26
+ *
27
+ * @returns {mat3} a new 3x3 matrix
28
+ */
29
+
30
+ function create$4() {
31
+ var out = new ARRAY_TYPE(9);
32
+
33
+ if (ARRAY_TYPE != Float32Array) {
34
+ out[1] = 0;
35
+ out[2] = 0;
36
+ out[3] = 0;
37
+ out[5] = 0;
38
+ out[6] = 0;
39
+ out[7] = 0;
40
+ }
41
+
42
+ out[0] = 1;
43
+ out[4] = 1;
44
+ out[8] = 1;
45
+ return out;
46
+ }
47
+
48
+ /**
49
+ * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
50
+ * @module mat4
51
+ */
52
+
53
+ /**
54
+ * Creates a new identity mat4
55
+ *
56
+ * @returns {mat4} a new 4x4 matrix
57
+ */
58
+
59
+ function create$3() {
60
+ var out = new ARRAY_TYPE(16);
61
+
62
+ if (ARRAY_TYPE != Float32Array) {
63
+ out[1] = 0;
64
+ out[2] = 0;
65
+ out[3] = 0;
66
+ out[4] = 0;
67
+ out[6] = 0;
68
+ out[7] = 0;
69
+ out[8] = 0;
70
+ out[9] = 0;
71
+ out[11] = 0;
72
+ out[12] = 0;
73
+ out[13] = 0;
74
+ out[14] = 0;
75
+ }
76
+
77
+ out[0] = 1;
78
+ out[5] = 1;
79
+ out[10] = 1;
80
+ out[15] = 1;
81
+ return out;
82
+ }
83
+ /**
84
+ * Creates a new mat4 initialized with values from an existing matrix
85
+ *
86
+ * @param {ReadonlyMat4} a matrix to clone
87
+ * @returns {mat4} a new 4x4 matrix
88
+ */
89
+
90
+ function clone(a) {
91
+ var out = new ARRAY_TYPE(16);
92
+ out[0] = a[0];
93
+ out[1] = a[1];
94
+ out[2] = a[2];
95
+ out[3] = a[3];
96
+ out[4] = a[4];
97
+ out[5] = a[5];
98
+ out[6] = a[6];
99
+ out[7] = a[7];
100
+ out[8] = a[8];
101
+ out[9] = a[9];
102
+ out[10] = a[10];
103
+ out[11] = a[11];
104
+ out[12] = a[12];
105
+ out[13] = a[13];
106
+ out[14] = a[14];
107
+ out[15] = a[15];
108
+ return out;
109
+ }
110
+ /**
111
+ * Copy the values from one mat4 to another
112
+ *
113
+ * @param {mat4} out the receiving matrix
114
+ * @param {ReadonlyMat4} a the source matrix
115
+ * @returns {mat4} out
116
+ */
117
+
118
+ function copy$3(out, a) {
119
+ out[0] = a[0];
120
+ out[1] = a[1];
121
+ out[2] = a[2];
122
+ out[3] = a[3];
123
+ out[4] = a[4];
124
+ out[5] = a[5];
125
+ out[6] = a[6];
126
+ out[7] = a[7];
127
+ out[8] = a[8];
128
+ out[9] = a[9];
129
+ out[10] = a[10];
130
+ out[11] = a[11];
131
+ out[12] = a[12];
132
+ out[13] = a[13];
133
+ out[14] = a[14];
134
+ out[15] = a[15];
135
+ return out;
136
+ }
137
+ /**
138
+ * Inverts a mat4
139
+ *
140
+ * @param {mat4} out the receiving matrix
141
+ * @param {ReadonlyMat4} a the source matrix
142
+ * @returns {mat4} out
143
+ */
144
+
145
+ function invert(out, a) {
146
+ var a00 = a[0],
147
+ a01 = a[1],
148
+ a02 = a[2],
149
+ a03 = a[3];
150
+ var a10 = a[4],
151
+ a11 = a[5],
152
+ a12 = a[6],
153
+ a13 = a[7];
154
+ var a20 = a[8],
155
+ a21 = a[9],
156
+ a22 = a[10],
157
+ a23 = a[11];
158
+ var a30 = a[12],
159
+ a31 = a[13],
160
+ a32 = a[14],
161
+ a33 = a[15];
162
+ var b00 = a00 * a11 - a01 * a10;
163
+ var b01 = a00 * a12 - a02 * a10;
164
+ var b02 = a00 * a13 - a03 * a10;
165
+ var b03 = a01 * a12 - a02 * a11;
166
+ var b04 = a01 * a13 - a03 * a11;
167
+ var b05 = a02 * a13 - a03 * a12;
168
+ var b06 = a20 * a31 - a21 * a30;
169
+ var b07 = a20 * a32 - a22 * a30;
170
+ var b08 = a20 * a33 - a23 * a30;
171
+ var b09 = a21 * a32 - a22 * a31;
172
+ var b10 = a21 * a33 - a23 * a31;
173
+ var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
174
+
175
+ var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
176
+
177
+ if (!det) {
178
+ return null;
179
+ }
180
+
181
+ det = 1.0 / det;
182
+ out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
183
+ out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
184
+ out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
185
+ out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
186
+ out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
187
+ out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
188
+ out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
189
+ out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
190
+ out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
191
+ out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
192
+ out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
193
+ out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
194
+ out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
195
+ out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
196
+ out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
197
+ out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
198
+ return out;
199
+ }
200
+ /**
201
+ * Multiplies two mat4s
202
+ *
203
+ * @param {mat4} out the receiving matrix
204
+ * @param {ReadonlyMat4} a the first operand
205
+ * @param {ReadonlyMat4} b the second operand
206
+ * @returns {mat4} out
207
+ */
208
+
209
+ function multiply$1(out, a, b) {
210
+ var a00 = a[0],
211
+ a01 = a[1],
212
+ a02 = a[2],
213
+ a03 = a[3];
214
+ var a10 = a[4],
215
+ a11 = a[5],
216
+ a12 = a[6],
217
+ a13 = a[7];
218
+ var a20 = a[8],
219
+ a21 = a[9],
220
+ a22 = a[10],
221
+ a23 = a[11];
222
+ var a30 = a[12],
223
+ a31 = a[13],
224
+ a32 = a[14],
225
+ a33 = a[15]; // Cache only the current line of the second matrix
226
+
227
+ var b0 = b[0],
228
+ b1 = b[1],
229
+ b2 = b[2],
230
+ b3 = b[3];
231
+ out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
232
+ out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
233
+ out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
234
+ out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
235
+ b0 = b[4];
236
+ b1 = b[5];
237
+ b2 = b[6];
238
+ b3 = b[7];
239
+ out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
240
+ out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
241
+ out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
242
+ out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
243
+ b0 = b[8];
244
+ b1 = b[9];
245
+ b2 = b[10];
246
+ b3 = b[11];
247
+ out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
248
+ out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
249
+ out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
250
+ out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
251
+ b0 = b[12];
252
+ b1 = b[13];
253
+ b2 = b[14];
254
+ b3 = b[15];
255
+ out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
256
+ out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
257
+ out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
258
+ out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
259
+ return out;
260
+ }
261
+ /**
262
+ * Creates a matrix from a vector translation
263
+ * This is equivalent to (but much faster than):
264
+ *
265
+ * mat4.identity(dest);
266
+ * mat4.translate(dest, dest, vec);
267
+ *
268
+ * @param {mat4} out mat4 receiving operation result
269
+ * @param {ReadonlyVec3} v Translation vector
270
+ * @returns {mat4} out
271
+ */
272
+
273
+ function fromTranslation(out, v) {
274
+ out[0] = 1;
275
+ out[1] = 0;
276
+ out[2] = 0;
277
+ out[3] = 0;
278
+ out[4] = 0;
279
+ out[5] = 1;
280
+ out[6] = 0;
281
+ out[7] = 0;
282
+ out[8] = 0;
283
+ out[9] = 0;
284
+ out[10] = 1;
285
+ out[11] = 0;
286
+ out[12] = v[0];
287
+ out[13] = v[1];
288
+ out[14] = v[2];
289
+ out[15] = 1;
290
+ return out;
291
+ }
292
+ /**
293
+ * Creates a matrix from a quaternion rotation and vector translation
294
+ * This is equivalent to (but much faster than):
295
+ *
296
+ * mat4.identity(dest);
297
+ * mat4.translate(dest, vec);
298
+ * let quatMat = mat4.create();
299
+ * quat4.toMat4(quat, quatMat);
300
+ * mat4.multiply(dest, quatMat);
301
+ *
302
+ * @param {mat4} out mat4 receiving operation result
303
+ * @param {quat4} q Rotation quaternion
304
+ * @param {ReadonlyVec3} v Translation vector
305
+ * @returns {mat4} out
306
+ */
307
+
308
+ function fromRotationTranslation(out, q, v) {
309
+ // Quaternion math
310
+ var x = q[0],
311
+ y = q[1],
312
+ z = q[2],
313
+ w = q[3];
314
+ var x2 = x + x;
315
+ var y2 = y + y;
316
+ var z2 = z + z;
317
+ var xx = x * x2;
318
+ var xy = x * y2;
319
+ var xz = x * z2;
320
+ var yy = y * y2;
321
+ var yz = y * z2;
322
+ var zz = z * z2;
323
+ var wx = w * x2;
324
+ var wy = w * y2;
325
+ var wz = w * z2;
326
+ out[0] = 1 - (yy + zz);
327
+ out[1] = xy + wz;
328
+ out[2] = xz - wy;
329
+ out[3] = 0;
330
+ out[4] = xy - wz;
331
+ out[5] = 1 - (xx + zz);
332
+ out[6] = yz + wx;
333
+ out[7] = 0;
334
+ out[8] = xz + wy;
335
+ out[9] = yz - wx;
336
+ out[10] = 1 - (xx + yy);
337
+ out[11] = 0;
338
+ out[12] = v[0];
339
+ out[13] = v[1];
340
+ out[14] = v[2];
341
+ out[15] = 1;
342
+ return out;
343
+ }
344
+ /**
345
+ * Returns the translation vector component of a transformation
346
+ * matrix. If a matrix is built with fromRotationTranslation,
347
+ * the returned vector will be the same as the translation vector
348
+ * originally supplied.
349
+ * @param {vec3} out Vector to receive translation component
350
+ * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
351
+ * @return {vec3} out
352
+ */
353
+
354
+ function getTranslation(out, mat) {
355
+ out[0] = mat[12];
356
+ out[1] = mat[13];
357
+ out[2] = mat[14];
358
+ return out;
359
+ }
360
+ /**
361
+ * Returns the scaling factor component of a transformation
362
+ * matrix. If a matrix is built with fromRotationTranslationScale
363
+ * with a normalized Quaternion paramter, the returned vector will be
364
+ * the same as the scaling vector
365
+ * originally supplied.
366
+ * @param {vec3} out Vector to receive scaling factor component
367
+ * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
368
+ * @return {vec3} out
369
+ */
370
+
371
+ function getScaling(out, mat) {
372
+ var m11 = mat[0];
373
+ var m12 = mat[1];
374
+ var m13 = mat[2];
375
+ var m21 = mat[4];
376
+ var m22 = mat[5];
377
+ var m23 = mat[6];
378
+ var m31 = mat[8];
379
+ var m32 = mat[9];
380
+ var m33 = mat[10];
381
+ out[0] = Math.hypot(m11, m12, m13);
382
+ out[1] = Math.hypot(m21, m22, m23);
383
+ out[2] = Math.hypot(m31, m32, m33);
384
+ return out;
385
+ }
386
+ /**
387
+ * Returns a quaternion representing the rotational component
388
+ * of a transformation matrix. If a matrix is built with
389
+ * fromRotationTranslation, the returned quaternion will be the
390
+ * same as the quaternion originally supplied.
391
+ * @param {quat} out Quaternion to receive the rotation component
392
+ * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
393
+ * @return {quat} out
394
+ */
395
+
396
+ function getRotation(out, mat) {
397
+ var scaling = new ARRAY_TYPE(3);
398
+ getScaling(scaling, mat);
399
+ var is1 = 1 / scaling[0];
400
+ var is2 = 1 / scaling[1];
401
+ var is3 = 1 / scaling[2];
402
+ var sm11 = mat[0] * is1;
403
+ var sm12 = mat[1] * is2;
404
+ var sm13 = mat[2] * is3;
405
+ var sm21 = mat[4] * is1;
406
+ var sm22 = mat[5] * is2;
407
+ var sm23 = mat[6] * is3;
408
+ var sm31 = mat[8] * is1;
409
+ var sm32 = mat[9] * is2;
410
+ var sm33 = mat[10] * is3;
411
+ var trace = sm11 + sm22 + sm33;
412
+ var S = 0;
413
+
414
+ if (trace > 0) {
415
+ S = Math.sqrt(trace + 1.0) * 2;
416
+ out[3] = 0.25 * S;
417
+ out[0] = (sm23 - sm32) / S;
418
+ out[1] = (sm31 - sm13) / S;
419
+ out[2] = (sm12 - sm21) / S;
420
+ } else if (sm11 > sm22 && sm11 > sm33) {
421
+ S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
422
+ out[3] = (sm23 - sm32) / S;
423
+ out[0] = 0.25 * S;
424
+ out[1] = (sm12 + sm21) / S;
425
+ out[2] = (sm31 + sm13) / S;
426
+ } else if (sm22 > sm33) {
427
+ S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
428
+ out[3] = (sm31 - sm13) / S;
429
+ out[0] = (sm12 + sm21) / S;
430
+ out[1] = 0.25 * S;
431
+ out[2] = (sm23 + sm32) / S;
432
+ } else {
433
+ S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
434
+ out[3] = (sm12 - sm21) / S;
435
+ out[0] = (sm31 + sm13) / S;
436
+ out[1] = (sm23 + sm32) / S;
437
+ out[2] = 0.25 * S;
438
+ }
439
+
440
+ return out;
441
+ }
442
+ /**
443
+ * Creates a matrix from a quaternion rotation, vector translation and vector scale
444
+ * This is equivalent to (but much faster than):
445
+ *
446
+ * mat4.identity(dest);
447
+ * mat4.translate(dest, vec);
448
+ * let quatMat = mat4.create();
449
+ * quat4.toMat4(quat, quatMat);
450
+ * mat4.multiply(dest, quatMat);
451
+ * mat4.scale(dest, scale)
452
+ *
453
+ * @param {mat4} out mat4 receiving operation result
454
+ * @param {quat4} q Rotation quaternion
455
+ * @param {ReadonlyVec3} v Translation vector
456
+ * @param {ReadonlyVec3} s Scaling vector
457
+ * @returns {mat4} out
458
+ */
459
+
460
+ function fromRotationTranslationScale(out, q, v, s) {
461
+ // Quaternion math
462
+ var x = q[0],
463
+ y = q[1],
464
+ z = q[2],
465
+ w = q[3];
466
+ var x2 = x + x;
467
+ var y2 = y + y;
468
+ var z2 = z + z;
469
+ var xx = x * x2;
470
+ var xy = x * y2;
471
+ var xz = x * z2;
472
+ var yy = y * y2;
473
+ var yz = y * z2;
474
+ var zz = z * z2;
475
+ var wx = w * x2;
476
+ var wy = w * y2;
477
+ var wz = w * z2;
478
+ var sx = s[0];
479
+ var sy = s[1];
480
+ var sz = s[2];
481
+ out[0] = (1 - (yy + zz)) * sx;
482
+ out[1] = (xy + wz) * sx;
483
+ out[2] = (xz - wy) * sx;
484
+ out[3] = 0;
485
+ out[4] = (xy - wz) * sy;
486
+ out[5] = (1 - (xx + zz)) * sy;
487
+ out[6] = (yz + wx) * sy;
488
+ out[7] = 0;
489
+ out[8] = (xz + wy) * sz;
490
+ out[9] = (yz - wx) * sz;
491
+ out[10] = (1 - (xx + yy)) * sz;
492
+ out[11] = 0;
493
+ out[12] = v[0];
494
+ out[13] = v[1];
495
+ out[14] = v[2];
496
+ out[15] = 1;
497
+ return out;
498
+ }
499
+ /**
500
+ * Generates a perspective projection matrix with the given bounds.
501
+ * The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
502
+ * which matches WebGL/OpenGL's clip volume.
503
+ * Passing null/undefined/no value for far will generate infinite projection matrix.
504
+ *
505
+ * @param {mat4} out mat4 frustum matrix will be written into
506
+ * @param {number} fovy Vertical field of view in radians
507
+ * @param {number} aspect Aspect ratio. typically viewport width/height
508
+ * @param {number} near Near bound of the frustum
509
+ * @param {number} far Far bound of the frustum, can be null or Infinity
510
+ * @returns {mat4} out
511
+ */
512
+
513
+ function perspectiveNO(out, fovy, aspect, near, far) {
514
+ var f = 1.0 / Math.tan(fovy / 2),
515
+ nf;
516
+ out[0] = f / aspect;
517
+ out[1] = 0;
518
+ out[2] = 0;
519
+ out[3] = 0;
520
+ out[4] = 0;
521
+ out[5] = f;
522
+ out[6] = 0;
523
+ out[7] = 0;
524
+ out[8] = 0;
525
+ out[9] = 0;
526
+ out[11] = -1;
527
+ out[12] = 0;
528
+ out[13] = 0;
529
+ out[15] = 0;
530
+
531
+ if (far != null && far !== Infinity) {
532
+ nf = 1 / (near - far);
533
+ out[10] = (far + near) * nf;
534
+ out[14] = 2 * far * near * nf;
535
+ } else {
536
+ out[10] = -1;
537
+ out[14] = -2 * near;
538
+ }
539
+
540
+ return out;
541
+ }
542
+ /**
543
+ * Alias for {@link mat4.perspectiveNO}
544
+ * @function
545
+ */
546
+
547
+ var perspective = perspectiveNO;
548
+
549
+ /**
550
+ * 3 Dimensional Vector
551
+ * @module vec3
552
+ */
553
+
554
+ /**
555
+ * Creates a new, empty vec3
556
+ *
557
+ * @returns {vec3} a new 3D vector
558
+ */
559
+
560
+ function create$2() {
561
+ var out = new ARRAY_TYPE(3);
562
+
563
+ if (ARRAY_TYPE != Float32Array) {
564
+ out[0] = 0;
565
+ out[1] = 0;
566
+ out[2] = 0;
567
+ }
568
+
569
+ return out;
570
+ }
571
+ /**
572
+ * Calculates the length of a vec3
573
+ *
574
+ * @param {ReadonlyVec3} a vector to calculate length of
575
+ * @returns {Number} length of a
576
+ */
577
+
578
+ function length(a) {
579
+ var x = a[0];
580
+ var y = a[1];
581
+ var z = a[2];
582
+ return Math.hypot(x, y, z);
583
+ }
584
+ /**
585
+ * Creates a new vec3 initialized with the given values
586
+ *
587
+ * @param {Number} x X component
588
+ * @param {Number} y Y component
589
+ * @param {Number} z Z component
590
+ * @returns {vec3} a new 3D vector
591
+ */
592
+
593
+ function fromValues$2(x, y, z) {
594
+ var out = new ARRAY_TYPE(3);
595
+ out[0] = x;
596
+ out[1] = y;
597
+ out[2] = z;
598
+ return out;
599
+ }
600
+ /**
601
+ * Copy the values from one vec3 to another
602
+ *
603
+ * @param {vec3} out the receiving vector
604
+ * @param {ReadonlyVec3} a the source vector
605
+ * @returns {vec3} out
606
+ */
607
+
608
+ function copy$2(out, a) {
609
+ out[0] = a[0];
610
+ out[1] = a[1];
611
+ out[2] = a[2];
612
+ return out;
613
+ }
614
+ /**
615
+ * Set the components of a vec3 to the given values
616
+ *
617
+ * @param {vec3} out the receiving vector
618
+ * @param {Number} x X component
619
+ * @param {Number} y Y component
620
+ * @param {Number} z Z component
621
+ * @returns {vec3} out
622
+ */
623
+
624
+ function set$2(out, x, y, z) {
625
+ out[0] = x;
626
+ out[1] = y;
627
+ out[2] = z;
628
+ return out;
629
+ }
630
+ /**
631
+ * Adds two vec3's
632
+ *
633
+ * @param {vec3} out the receiving vector
634
+ * @param {ReadonlyVec3} a the first operand
635
+ * @param {ReadonlyVec3} b the second operand
636
+ * @returns {vec3} out
637
+ */
638
+
639
+ function add(out, a, b) {
640
+ out[0] = a[0] + b[0];
641
+ out[1] = a[1] + b[1];
642
+ out[2] = a[2] + b[2];
643
+ return out;
644
+ }
645
+ /**
646
+ * Normalize a vec3
647
+ *
648
+ * @param {vec3} out the receiving vector
649
+ * @param {ReadonlyVec3} a vector to normalize
650
+ * @returns {vec3} out
651
+ */
652
+
653
+ function normalize$2(out, a) {
654
+ var x = a[0];
655
+ var y = a[1];
656
+ var z = a[2];
657
+ var len = x * x + y * y + z * z;
658
+
659
+ if (len > 0) {
660
+ //TODO: evaluate use of glm_invsqrt here?
661
+ len = 1 / Math.sqrt(len);
662
+ }
663
+
664
+ out[0] = a[0] * len;
665
+ out[1] = a[1] * len;
666
+ out[2] = a[2] * len;
667
+ return out;
668
+ }
669
+ /**
670
+ * Calculates the dot product of two vec3's
671
+ *
672
+ * @param {ReadonlyVec3} a the first operand
673
+ * @param {ReadonlyVec3} b the second operand
674
+ * @returns {Number} dot product of a and b
675
+ */
676
+
677
+ function dot(a, b) {
678
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
679
+ }
680
+ /**
681
+ * Computes the cross product of two vec3's
682
+ *
683
+ * @param {vec3} out the receiving vector
684
+ * @param {ReadonlyVec3} a the first operand
685
+ * @param {ReadonlyVec3} b the second operand
686
+ * @returns {vec3} out
687
+ */
688
+
689
+ function cross(out, a, b) {
690
+ var ax = a[0],
691
+ ay = a[1],
692
+ az = a[2];
693
+ var bx = b[0],
694
+ by = b[1],
695
+ bz = b[2];
696
+ out[0] = ay * bz - az * by;
697
+ out[1] = az * bx - ax * bz;
698
+ out[2] = ax * by - ay * bx;
699
+ return out;
700
+ }
701
+ /**
702
+ * Performs a linear interpolation between two vec3's
703
+ *
704
+ * @param {vec3} out the receiving vector
705
+ * @param {ReadonlyVec3} a the first operand
706
+ * @param {ReadonlyVec3} b the second operand
707
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
708
+ * @returns {vec3} out
709
+ */
710
+
711
+ function lerp(out, a, b, t) {
712
+ var ax = a[0];
713
+ var ay = a[1];
714
+ var az = a[2];
715
+ out[0] = ax + t * (b[0] - ax);
716
+ out[1] = ay + t * (b[1] - ay);
717
+ out[2] = az + t * (b[2] - az);
718
+ return out;
719
+ }
720
+ /**
721
+ * Transforms the vec3 with a quat
722
+ * Can also be used for dual quaternions. (Multiply it with the real part)
723
+ *
724
+ * @param {vec3} out the receiving vector
725
+ * @param {ReadonlyVec3} a the vector to transform
726
+ * @param {ReadonlyQuat} q quaternion to transform with
727
+ * @returns {vec3} out
728
+ */
729
+
730
+ function transformQuat(out, a, q) {
731
+ // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed
732
+ var qx = q[0],
733
+ qy = q[1],
734
+ qz = q[2],
735
+ qw = q[3];
736
+ var x = a[0],
737
+ y = a[1],
738
+ z = a[2]; // var qvec = [qx, qy, qz];
739
+ // var uv = vec3.cross([], qvec, a);
740
+
741
+ var uvx = qy * z - qz * y,
742
+ uvy = qz * x - qx * z,
743
+ uvz = qx * y - qy * x; // var uuv = vec3.cross([], qvec, uv);
744
+
745
+ var uuvx = qy * uvz - qz * uvy,
746
+ uuvy = qz * uvx - qx * uvz,
747
+ uuvz = qx * uvy - qy * uvx; // vec3.scale(uv, uv, 2 * w);
748
+
749
+ var w2 = qw * 2;
750
+ uvx *= w2;
751
+ uvy *= w2;
752
+ uvz *= w2; // vec3.scale(uuv, uuv, 2);
753
+
754
+ uuvx *= 2;
755
+ uuvy *= 2;
756
+ uuvz *= 2; // return vec3.add(out, a, vec3.add(out, uv, uuv));
757
+
758
+ out[0] = x + uvx + uuvx;
759
+ out[1] = y + uvy + uuvy;
760
+ out[2] = z + uvz + uuvz;
761
+ return out;
762
+ }
763
+ /**
764
+ * Alias for {@link vec3.length}
765
+ * @function
766
+ */
767
+
768
+ var len = length;
769
+ /**
770
+ * Perform some operation over an array of vec3s.
771
+ *
772
+ * @param {Array} a the array of vectors to iterate over
773
+ * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
774
+ * @param {Number} offset Number of elements to skip at the beginning of the array
775
+ * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
776
+ * @param {Function} fn Function to call for each vector in the array
777
+ * @param {Object} [arg] additional argument to pass to fn
778
+ * @returns {Array} a
779
+ * @function
780
+ */
781
+
782
+ (function () {
783
+ var vec = create$2();
784
+ return function (a, stride, offset, count, fn, arg) {
785
+ var i, l;
786
+
787
+ if (!stride) {
788
+ stride = 3;
789
+ }
790
+
791
+ if (!offset) {
792
+ offset = 0;
793
+ }
794
+
795
+ if (count) {
796
+ l = Math.min(count * stride + offset, a.length);
797
+ } else {
798
+ l = a.length;
799
+ }
800
+
801
+ for (i = offset; i < l; i += stride) {
802
+ vec[0] = a[i];
803
+ vec[1] = a[i + 1];
804
+ vec[2] = a[i + 2];
805
+ fn(vec, vec, arg);
806
+ a[i] = vec[0];
807
+ a[i + 1] = vec[1];
808
+ a[i + 2] = vec[2];
809
+ }
810
+
811
+ return a;
812
+ };
813
+ })();
814
+
815
+ /**
816
+ * 4 Dimensional Vector
817
+ * @module vec4
818
+ */
819
+
820
+ /**
821
+ * Creates a new, empty vec4
822
+ *
823
+ * @returns {vec4} a new 4D vector
824
+ */
825
+
826
+ function create$1() {
827
+ var out = new ARRAY_TYPE(4);
828
+
829
+ if (ARRAY_TYPE != Float32Array) {
830
+ out[0] = 0;
831
+ out[1] = 0;
832
+ out[2] = 0;
833
+ out[3] = 0;
834
+ }
835
+
836
+ return out;
837
+ }
838
+ /**
839
+ * Creates a new vec4 initialized with the given values
840
+ *
841
+ * @param {Number} x X component
842
+ * @param {Number} y Y component
843
+ * @param {Number} z Z component
844
+ * @param {Number} w W component
845
+ * @returns {vec4} a new 4D vector
846
+ */
847
+
848
+ function fromValues$1(x, y, z, w) {
849
+ var out = new ARRAY_TYPE(4);
850
+ out[0] = x;
851
+ out[1] = y;
852
+ out[2] = z;
853
+ out[3] = w;
854
+ return out;
855
+ }
856
+ /**
857
+ * Copy the values from one vec4 to another
858
+ *
859
+ * @param {vec4} out the receiving vector
860
+ * @param {ReadonlyVec4} a the source vector
861
+ * @returns {vec4} out
862
+ */
863
+
864
+ function copy$1(out, a) {
865
+ out[0] = a[0];
866
+ out[1] = a[1];
867
+ out[2] = a[2];
868
+ out[3] = a[3];
869
+ return out;
870
+ }
871
+ /**
872
+ * Set the components of a vec4 to the given values
873
+ *
874
+ * @param {vec4} out the receiving vector
875
+ * @param {Number} x X component
876
+ * @param {Number} y Y component
877
+ * @param {Number} z Z component
878
+ * @param {Number} w W component
879
+ * @returns {vec4} out
880
+ */
881
+
882
+ function set$1(out, x, y, z, w) {
883
+ out[0] = x;
884
+ out[1] = y;
885
+ out[2] = z;
886
+ out[3] = w;
887
+ return out;
888
+ }
889
+ /**
890
+ * Normalize a vec4
891
+ *
892
+ * @param {vec4} out the receiving vector
893
+ * @param {ReadonlyVec4} a vector to normalize
894
+ * @returns {vec4} out
895
+ */
896
+
897
+ function normalize$1(out, a) {
898
+ var x = a[0];
899
+ var y = a[1];
900
+ var z = a[2];
901
+ var w = a[3];
902
+ var len = x * x + y * y + z * z + w * w;
903
+
904
+ if (len > 0) {
905
+ len = 1 / Math.sqrt(len);
906
+ }
907
+
908
+ out[0] = x * len;
909
+ out[1] = y * len;
910
+ out[2] = z * len;
911
+ out[3] = w * len;
912
+ return out;
913
+ }
914
+ /**
915
+ * Perform some operation over an array of vec4s.
916
+ *
917
+ * @param {Array} a the array of vectors to iterate over
918
+ * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
919
+ * @param {Number} offset Number of elements to skip at the beginning of the array
920
+ * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array
921
+ * @param {Function} fn Function to call for each vector in the array
922
+ * @param {Object} [arg] additional argument to pass to fn
923
+ * @returns {Array} a
924
+ * @function
925
+ */
926
+
927
+ (function () {
928
+ var vec = create$1();
929
+ return function (a, stride, offset, count, fn, arg) {
930
+ var i, l;
931
+
932
+ if (!stride) {
933
+ stride = 4;
934
+ }
935
+
936
+ if (!offset) {
937
+ offset = 0;
938
+ }
939
+
940
+ if (count) {
941
+ l = Math.min(count * stride + offset, a.length);
942
+ } else {
943
+ l = a.length;
944
+ }
945
+
946
+ for (i = offset; i < l; i += stride) {
947
+ vec[0] = a[i];
948
+ vec[1] = a[i + 1];
949
+ vec[2] = a[i + 2];
950
+ vec[3] = a[i + 3];
951
+ fn(vec, vec, arg);
952
+ a[i] = vec[0];
953
+ a[i + 1] = vec[1];
954
+ a[i + 2] = vec[2];
955
+ a[i + 3] = vec[3];
956
+ }
957
+
958
+ return a;
959
+ };
960
+ })();
961
+
962
+ /**
963
+ * Quaternion
964
+ * @module quat
965
+ */
966
+
967
+ /**
968
+ * Creates a new identity quat
969
+ *
970
+ * @returns {quat} a new quaternion
971
+ */
972
+
973
+ function create() {
974
+ var out = new ARRAY_TYPE(4);
975
+
976
+ if (ARRAY_TYPE != Float32Array) {
977
+ out[0] = 0;
978
+ out[1] = 0;
979
+ out[2] = 0;
980
+ }
981
+
982
+ out[3] = 1;
983
+ return out;
984
+ }
985
+ /**
986
+ * Sets a quat from the given angle and rotation axis,
987
+ * then returns it.
988
+ *
989
+ * @param {quat} out the receiving quaternion
990
+ * @param {ReadonlyVec3} axis the axis around which to rotate
991
+ * @param {Number} rad the angle in radians
992
+ * @returns {quat} out
993
+ **/
994
+
995
+ function setAxisAngle(out, axis, rad) {
996
+ rad = rad * 0.5;
997
+ var s = Math.sin(rad);
998
+ out[0] = s * axis[0];
999
+ out[1] = s * axis[1];
1000
+ out[2] = s * axis[2];
1001
+ out[3] = Math.cos(rad);
1002
+ return out;
1003
+ }
1004
+ /**
1005
+ * Multiplies two quat's
1006
+ *
1007
+ * @param {quat} out the receiving quaternion
1008
+ * @param {ReadonlyQuat} a the first operand
1009
+ * @param {ReadonlyQuat} b the second operand
1010
+ * @returns {quat} out
1011
+ */
1012
+
1013
+ function multiply(out, a, b) {
1014
+ var ax = a[0],
1015
+ ay = a[1],
1016
+ az = a[2],
1017
+ aw = a[3];
1018
+ var bx = b[0],
1019
+ by = b[1],
1020
+ bz = b[2],
1021
+ bw = b[3];
1022
+ out[0] = ax * bw + aw * bx + ay * bz - az * by;
1023
+ out[1] = ay * bw + aw * by + az * bx - ax * bz;
1024
+ out[2] = az * bw + aw * bz + ax * by - ay * bx;
1025
+ out[3] = aw * bw - ax * bx - ay * by - az * bz;
1026
+ return out;
1027
+ }
1028
+ /**
1029
+ * Performs a spherical linear interpolation between two quat
1030
+ *
1031
+ * @param {quat} out the receiving quaternion
1032
+ * @param {ReadonlyQuat} a the first operand
1033
+ * @param {ReadonlyQuat} b the second operand
1034
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
1035
+ * @returns {quat} out
1036
+ */
1037
+
1038
+ function slerp(out, a, b, t) {
1039
+ // benchmarks:
1040
+ // http://jsperf.com/quaternion-slerp-implementations
1041
+ var ax = a[0],
1042
+ ay = a[1],
1043
+ az = a[2],
1044
+ aw = a[3];
1045
+ var bx = b[0],
1046
+ by = b[1],
1047
+ bz = b[2],
1048
+ bw = b[3];
1049
+ var omega, cosom, sinom, scale0, scale1; // calc cosine
1050
+
1051
+ cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary)
1052
+
1053
+ if (cosom < 0.0) {
1054
+ cosom = -cosom;
1055
+ bx = -bx;
1056
+ by = -by;
1057
+ bz = -bz;
1058
+ bw = -bw;
1059
+ } // calculate coefficients
1060
+
1061
+
1062
+ if (1.0 - cosom > EPSILON) {
1063
+ // standard case (slerp)
1064
+ omega = Math.acos(cosom);
1065
+ sinom = Math.sin(omega);
1066
+ scale0 = Math.sin((1.0 - t) * omega) / sinom;
1067
+ scale1 = Math.sin(t * omega) / sinom;
1068
+ } else {
1069
+ // "from" and "to" quaternions are very close
1070
+ // ... so we can do a linear interpolation
1071
+ scale0 = 1.0 - t;
1072
+ scale1 = t;
1073
+ } // calculate final values
1074
+
1075
+
1076
+ out[0] = scale0 * ax + scale1 * bx;
1077
+ out[1] = scale0 * ay + scale1 * by;
1078
+ out[2] = scale0 * az + scale1 * bz;
1079
+ out[3] = scale0 * aw + scale1 * bw;
1080
+ return out;
1081
+ }
1082
+ /**
1083
+ * Calculates the conjugate of a quat
1084
+ * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
1085
+ *
1086
+ * @param {quat} out the receiving quaternion
1087
+ * @param {ReadonlyQuat} a quat to calculate conjugate of
1088
+ * @returns {quat} out
1089
+ */
1090
+
1091
+ function conjugate(out, a) {
1092
+ out[0] = -a[0];
1093
+ out[1] = -a[1];
1094
+ out[2] = -a[2];
1095
+ out[3] = a[3];
1096
+ return out;
1097
+ }
1098
+ /**
1099
+ * Creates a quaternion from the given 3x3 rotation matrix.
1100
+ *
1101
+ * NOTE: The resultant quaternion is not normalized, so you should be sure
1102
+ * to renormalize the quaternion yourself where necessary.
1103
+ *
1104
+ * @param {quat} out the receiving quaternion
1105
+ * @param {ReadonlyMat3} m rotation matrix
1106
+ * @returns {quat} out
1107
+ * @function
1108
+ */
1109
+
1110
+ function fromMat3(out, m) {
1111
+ // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
1112
+ // article "Quaternion Calculus and Fast Animation".
1113
+ var fTrace = m[0] + m[4] + m[8];
1114
+ var fRoot;
1115
+
1116
+ if (fTrace > 0.0) {
1117
+ // |w| > 1/2, may as well choose w > 1/2
1118
+ fRoot = Math.sqrt(fTrace + 1.0); // 2w
1119
+
1120
+ out[3] = 0.5 * fRoot;
1121
+ fRoot = 0.5 / fRoot; // 1/(4w)
1122
+
1123
+ out[0] = (m[5] - m[7]) * fRoot;
1124
+ out[1] = (m[6] - m[2]) * fRoot;
1125
+ out[2] = (m[1] - m[3]) * fRoot;
1126
+ } else {
1127
+ // |w| <= 1/2
1128
+ var i = 0;
1129
+ if (m[4] > m[0]) i = 1;
1130
+ if (m[8] > m[i * 3 + i]) i = 2;
1131
+ var j = (i + 1) % 3;
1132
+ var k = (i + 2) % 3;
1133
+ fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
1134
+ out[i] = 0.5 * fRoot;
1135
+ fRoot = 0.5 / fRoot;
1136
+ out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
1137
+ out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
1138
+ out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
1139
+ }
1140
+
1141
+ return out;
1142
+ }
1143
+ /**
1144
+ * Creates a new quat initialized with the given values
1145
+ *
1146
+ * @param {Number} x X component
1147
+ * @param {Number} y Y component
1148
+ * @param {Number} z Z component
1149
+ * @param {Number} w W component
1150
+ * @returns {quat} a new quaternion
1151
+ * @function
1152
+ */
1153
+
1154
+ var fromValues = fromValues$1;
1155
+ /**
1156
+ * Copy the values from one quat to another
1157
+ *
1158
+ * @param {quat} out the receiving quaternion
1159
+ * @param {ReadonlyQuat} a the source quaternion
1160
+ * @returns {quat} out
1161
+ * @function
1162
+ */
1163
+
1164
+ var copy = copy$1;
1165
+ /**
1166
+ * Set the components of a quat to the given values
1167
+ *
1168
+ * @param {quat} out the receiving quaternion
1169
+ * @param {Number} x X component
1170
+ * @param {Number} y Y component
1171
+ * @param {Number} z Z component
1172
+ * @param {Number} w W component
1173
+ * @returns {quat} out
1174
+ * @function
1175
+ */
1176
+
1177
+ var set = set$1;
1178
+ /**
1179
+ * Normalize a quat
1180
+ *
1181
+ * @param {quat} out the receiving quaternion
1182
+ * @param {ReadonlyQuat} a quaternion to normalize
1183
+ * @returns {quat} out
1184
+ * @function
1185
+ */
1186
+
1187
+ var normalize = normalize$1;
1188
+ /**
1189
+ * Sets a quaternion to represent the shortest rotation from one
1190
+ * vector to another.
1191
+ *
1192
+ * Both vectors are assumed to be unit length.
1193
+ *
1194
+ * @param {quat} out the receiving quaternion.
1195
+ * @param {ReadonlyVec3} a the initial vector
1196
+ * @param {ReadonlyVec3} b the destination vector
1197
+ * @returns {quat} out
1198
+ */
1199
+
1200
+ (function () {
1201
+ var tmpvec3 = create$2();
1202
+ var xUnitVec3 = fromValues$2(1, 0, 0);
1203
+ var yUnitVec3 = fromValues$2(0, 1, 0);
1204
+ return function (out, a, b) {
1205
+ var dot$1 = dot(a, b);
1206
+
1207
+ if (dot$1 < -0.999999) {
1208
+ cross(tmpvec3, xUnitVec3, a);
1209
+ if (len(tmpvec3) < 0.000001) cross(tmpvec3, yUnitVec3, a);
1210
+ normalize$2(tmpvec3, tmpvec3);
1211
+ setAxisAngle(out, tmpvec3, Math.PI);
1212
+ return out;
1213
+ } else if (dot$1 > 0.999999) {
1214
+ out[0] = 0;
1215
+ out[1] = 0;
1216
+ out[2] = 0;
1217
+ out[3] = 1;
1218
+ return out;
1219
+ } else {
1220
+ cross(tmpvec3, a, b);
1221
+ out[0] = tmpvec3[0];
1222
+ out[1] = tmpvec3[1];
1223
+ out[2] = tmpvec3[2];
1224
+ out[3] = 1 + dot$1;
1225
+ return normalize(out, out);
1226
+ }
1227
+ };
1228
+ })();
1229
+ /**
1230
+ * Performs a spherical linear interpolation with two control points
1231
+ *
1232
+ * @param {quat} out the receiving quaternion
1233
+ * @param {ReadonlyQuat} a the first operand
1234
+ * @param {ReadonlyQuat} b the second operand
1235
+ * @param {ReadonlyQuat} c the third operand
1236
+ * @param {ReadonlyQuat} d the fourth operand
1237
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
1238
+ * @returns {quat} out
1239
+ */
1240
+
1241
+ (function () {
1242
+ var temp1 = create();
1243
+ var temp2 = create();
1244
+ return function (out, a, b, c, d, t) {
1245
+ slerp(temp1, a, d, t);
1246
+ slerp(temp2, b, c, t);
1247
+ slerp(out, temp1, temp2, 2 * t * (1 - t));
1248
+ return out;
1249
+ };
1250
+ })();
1251
+ /**
1252
+ * Sets the specified quaternion with values corresponding to the given
1253
+ * axes. Each axis is a vec3 and is expected to be unit length and
1254
+ * perpendicular to all other specified axes.
1255
+ *
1256
+ * @param {ReadonlyVec3} view the vector representing the viewing direction
1257
+ * @param {ReadonlyVec3} right the vector representing the local "right" direction
1258
+ * @param {ReadonlyVec3} up the vector representing the local "up" direction
1259
+ * @returns {quat} out
1260
+ */
1261
+
1262
+ (function () {
1263
+ var matr = create$4();
1264
+ return function (out, view, right, up) {
1265
+ matr[0] = right[0];
1266
+ matr[3] = right[1];
1267
+ matr[6] = right[2];
1268
+ matr[1] = up[0];
1269
+ matr[4] = up[1];
1270
+ matr[7] = up[2];
1271
+ matr[2] = -view[0];
1272
+ matr[5] = -view[1];
1273
+ matr[8] = -view[2];
1274
+ return normalize(out, fromMat3(out, matr));
1275
+ };
1276
+ })();
1277
+
1278
+ const PRIVATE$k = Symbol('@immersive-web-emulation-runtime/xr-space');
1279
+ class XRSpace extends EventTarget {
1280
+ constructor(parentSpace, offsetMatrix) {
1281
+ super();
1282
+ this[PRIVATE$k] = {
1283
+ parentSpace,
1284
+ offsetMatrix: offsetMatrix ? clone(offsetMatrix) : create$3(),
1285
+ emulated: true,
1286
+ };
1287
+ }
1288
+ }
1289
+ class GlobalSpace extends XRSpace {
1290
+ constructor() {
1291
+ super(undefined, create$3()); // GlobalSpace has no parent
1292
+ }
1293
+ }
1294
+ class XRSpaceUtils {
1295
+ // Update the position component of the offsetMatrix of a given XRSpace
1296
+ static updateOffsetPosition(space, position) {
1297
+ const offsetMatrix = space[PRIVATE$k].offsetMatrix;
1298
+ fromTranslation(offsetMatrix, position);
1299
+ }
1300
+ // Update the rotation component of the offsetMatrix of a given XRSpace using a quaternion
1301
+ static updateOffsetQuaternion(space, quaternion) {
1302
+ const offsetMatrix = space[PRIVATE$k].offsetMatrix;
1303
+ const translation = create$2();
1304
+ getTranslation(translation, offsetMatrix);
1305
+ fromRotationTranslation(offsetMatrix, quaternion, translation);
1306
+ }
1307
+ // Update the offsetMatrix of a given XRSpace directly
1308
+ static updateOffsetMatrix(space, matrix) {
1309
+ const offsetMatrix = space[PRIVATE$k].offsetMatrix;
1310
+ copy$3(offsetMatrix, matrix);
1311
+ }
1312
+ // Calculate the global offset matrix for a given XRSpace
1313
+ static calculateGlobalOffsetMatrix(space, globalOffset = create$3()) {
1314
+ const parentOffset = space[PRIVATE$k].parentSpace
1315
+ ? XRSpaceUtils.calculateGlobalOffsetMatrix(space[PRIVATE$k].parentSpace)
1316
+ : create$3(); // Identity matrix for GlobalSpace
1317
+ multiply$1(globalOffset, parentOffset, space[PRIVATE$k].offsetMatrix);
1318
+ return globalOffset;
1319
+ }
1320
+ }
1321
+
1322
+ /**
1323
+ * Wrapper class for gl-matrix vec3
1324
+ * Minimal interoperable interface to Vector3 in Three.js and Babylon.js
1325
+ */
1326
+ class Vector3 {
1327
+ constructor(x = 0, y = 0, z = 0) {
1328
+ this.vec3 = fromValues$2(x, y, z);
1329
+ this.tempVec3 = create$2();
1330
+ }
1331
+ get x() {
1332
+ return this.vec3[0];
1333
+ }
1334
+ set x(value) {
1335
+ this.vec3[0] = value;
1336
+ }
1337
+ get y() {
1338
+ return this.vec3[1];
1339
+ }
1340
+ set y(value) {
1341
+ this.vec3[1] = value;
1342
+ }
1343
+ get z() {
1344
+ return this.vec3[2];
1345
+ }
1346
+ set z(value) {
1347
+ this.vec3[2] = value;
1348
+ }
1349
+ set(x, y, z) {
1350
+ set$2(this.vec3, x, y, z);
1351
+ return this;
1352
+ }
1353
+ clone() {
1354
+ return new Vector3(this.x, this.y, this.z);
1355
+ }
1356
+ copy(v) {
1357
+ this.x = v.x;
1358
+ this.y = v.y;
1359
+ this.z = v.z;
1360
+ return this;
1361
+ }
1362
+ round() {
1363
+ this.x = Math.round(this.x);
1364
+ this.y = Math.round(this.y);
1365
+ this.z = Math.round(this.z);
1366
+ return this;
1367
+ }
1368
+ normalize() {
1369
+ copy$2(this.tempVec3, this.vec3);
1370
+ normalize$2(this.vec3, this.tempVec3);
1371
+ return this;
1372
+ }
1373
+ add(v) {
1374
+ copy$2(this.tempVec3, this.vec3);
1375
+ add(this.vec3, this.tempVec3, v.vec3);
1376
+ return this;
1377
+ }
1378
+ applyQuaternion(q) {
1379
+ copy$2(this.tempVec3, this.vec3);
1380
+ transformQuat(this.vec3, this.tempVec3, q.quat);
1381
+ return this;
1382
+ }
1383
+ }
1384
+ /**
1385
+ * Wrapper class for gl-matrix quat4
1386
+ * Minimal interoperable interface to Vector3 in Three.js and Babylon.js
1387
+ */
1388
+ class Quaternion {
1389
+ constructor(x = 0, y = 0, z = 0, w = 1) {
1390
+ this.quat = fromValues(x, y, z, w);
1391
+ this.tempQuat = create();
1392
+ }
1393
+ get x() {
1394
+ return this.quat[0];
1395
+ }
1396
+ set x(value) {
1397
+ this.quat[0] = value;
1398
+ }
1399
+ get y() {
1400
+ return this.quat[1];
1401
+ }
1402
+ set y(value) {
1403
+ this.quat[1] = value;
1404
+ }
1405
+ get z() {
1406
+ return this.quat[2];
1407
+ }
1408
+ set z(value) {
1409
+ this.quat[2] = value;
1410
+ }
1411
+ get w() {
1412
+ return this.quat[3];
1413
+ }
1414
+ set w(value) {
1415
+ this.quat[3] = value;
1416
+ }
1417
+ set(x, y, z, w) {
1418
+ set(this.quat, x, y, z, w);
1419
+ return this;
1420
+ }
1421
+ clone() {
1422
+ return new Quaternion(this.x, this.y, this.z, this.w);
1423
+ }
1424
+ copy(q) {
1425
+ set(this.quat, q.x, q.y, q.z, q.w);
1426
+ return this;
1427
+ }
1428
+ normalize() {
1429
+ copy(this.tempQuat, this.quat);
1430
+ normalize(this.quat, this.tempQuat);
1431
+ return this;
1432
+ }
1433
+ invert() {
1434
+ copy(this.tempQuat, this.quat);
1435
+ conjugate(this.quat, this.tempQuat);
1436
+ return this;
1437
+ }
1438
+ multiply(q) {
1439
+ copy(this.tempQuat, this.quat);
1440
+ multiply(this.quat, this.tempQuat, q.quat);
1441
+ return this;
1442
+ }
1443
+ setFromAxisAngle(axis, angle) {
1444
+ setAxisAngle(this.quat, axis.vec3, angle);
1445
+ return this;
1446
+ }
1447
+ }
1448
+
1449
+ const PRIVATE$j = Symbol('@immersive-web-emulation-runtime/gamepad');
1450
+ var GamepadMappingType;
1451
+ (function (GamepadMappingType) {
1452
+ GamepadMappingType["None"] = "";
1453
+ GamepadMappingType["Standard"] = "standard";
1454
+ GamepadMappingType["XRStandard"] = "xr-standard";
1455
+ })(GamepadMappingType || (GamepadMappingType = {}));
1456
+ class GamepadButton {
1457
+ constructor(type, eventTrigger) {
1458
+ this[PRIVATE$j] = {
1459
+ type,
1460
+ eventTrigger,
1461
+ pressed: false,
1462
+ touched: false,
1463
+ value: 0,
1464
+ lastFrameValue: 0,
1465
+ pendingValue: null,
1466
+ };
1467
+ }
1468
+ get pressed() {
1469
+ if (this[PRIVATE$j].type === 'manual') {
1470
+ return this[PRIVATE$j].pressed;
1471
+ }
1472
+ else {
1473
+ return this[PRIVATE$j].value > 0;
1474
+ }
1475
+ }
1476
+ get touched() {
1477
+ if (this[PRIVATE$j].type === 'manual') {
1478
+ return this[PRIVATE$j].touched;
1479
+ }
1480
+ else {
1481
+ return this[PRIVATE$j].touched || this.pressed;
1482
+ }
1483
+ }
1484
+ get value() {
1485
+ return this[PRIVATE$j].value;
1486
+ }
1487
+ }
1488
+ class EmptyGamepadButton {
1489
+ constructor() {
1490
+ this.pressed = false;
1491
+ this.touched = false;
1492
+ this.value = 0;
1493
+ }
1494
+ }
1495
+ class Gamepad {
1496
+ constructor(gamepadConfig, id = '', index = -1) {
1497
+ this[PRIVATE$j] = {
1498
+ id,
1499
+ index,
1500
+ connected: false,
1501
+ timestamp: performance.now(),
1502
+ mapping: gamepadConfig.mapping,
1503
+ buttonsMap: {},
1504
+ buttonsSequence: [],
1505
+ axesMap: {},
1506
+ axesSequence: [],
1507
+ hapticActuators: [],
1508
+ };
1509
+ gamepadConfig.buttons.forEach((buttonConfig) => {
1510
+ var _a;
1511
+ if (buttonConfig === null) {
1512
+ this[PRIVATE$j].buttonsSequence.push(null);
1513
+ }
1514
+ else {
1515
+ this[PRIVATE$j].buttonsSequence.push(buttonConfig.id);
1516
+ this[PRIVATE$j].buttonsMap[buttonConfig.id] = new GamepadButton(buttonConfig.type, (_a = buttonConfig.eventTrigger) !== null && _a !== void 0 ? _a : null);
1517
+ }
1518
+ });
1519
+ gamepadConfig.axes.forEach((axisConfig) => {
1520
+ if (axisConfig === null) {
1521
+ this[PRIVATE$j].axesSequence.push(null);
1522
+ }
1523
+ else {
1524
+ this[PRIVATE$j].axesSequence.push(axisConfig.id + axisConfig.type);
1525
+ if (!this[PRIVATE$j].axesMap[axisConfig.id]) {
1526
+ this[PRIVATE$j].axesMap[axisConfig.id] = { x: 0, y: 0 };
1527
+ }
1528
+ }
1529
+ });
1530
+ }
1531
+ get id() {
1532
+ return this[PRIVATE$j].id;
1533
+ }
1534
+ get index() {
1535
+ return this[PRIVATE$j].index;
1536
+ }
1537
+ get connected() {
1538
+ return this[PRIVATE$j].connected;
1539
+ }
1540
+ get timestamp() {
1541
+ return this[PRIVATE$j].timestamp;
1542
+ }
1543
+ get mapping() {
1544
+ return this[PRIVATE$j].mapping;
1545
+ }
1546
+ get axes() {
1547
+ const axes = [];
1548
+ this[PRIVATE$j].axesSequence.forEach((id) => {
1549
+ if (id === null) {
1550
+ axes.push(null);
1551
+ }
1552
+ else {
1553
+ const axisId = id.substring(0, id.length - 6);
1554
+ const axisType = id.substring(id.length - 6);
1555
+ axes.push(
1556
+ // if axis type is manual, then return the x value
1557
+ axisType === 'y-axis'
1558
+ ? this[PRIVATE$j].axesMap[axisId].y
1559
+ : this[PRIVATE$j].axesMap[axisId].x);
1560
+ }
1561
+ });
1562
+ return axes;
1563
+ }
1564
+ get buttons() {
1565
+ return this[PRIVATE$j].buttonsSequence.map((id) => id === null ? new EmptyGamepadButton() : this[PRIVATE$j].buttonsMap[id]);
1566
+ }
1567
+ get hapticActuators() {
1568
+ return this[PRIVATE$j].hapticActuators;
1569
+ }
1570
+ get vibrationActuator() {
1571
+ return null;
1572
+ }
1573
+ }
1574
+
1575
+ var XRHandedness;
1576
+ (function (XRHandedness) {
1577
+ XRHandedness["None"] = "none";
1578
+ XRHandedness["Left"] = "left";
1579
+ XRHandedness["Right"] = "right";
1580
+ })(XRHandedness || (XRHandedness = {}));
1581
+ var XRTargetRayMode;
1582
+ (function (XRTargetRayMode) {
1583
+ XRTargetRayMode["Gaze"] = "gaze";
1584
+ XRTargetRayMode["TrackedPointer"] = "tracked-pointer";
1585
+ XRTargetRayMode["Screen"] = "screen";
1586
+ XRTargetRayMode["TransientPointer"] = "transient-pointer";
1587
+ })(XRTargetRayMode || (XRTargetRayMode = {}));
1588
+ class XRInputSourceArray extends Array {
1589
+ }
1590
+ const PRIVATE$i = Symbol('@immersive-web-emulation-runtime/xr-input-source');
1591
+ class XRInputSource {
1592
+ constructor(handedness, targetRayMode, profiles, targetRaySpace, gamepad, gripSpace, hand) {
1593
+ this[PRIVATE$i] = {
1594
+ handedness,
1595
+ targetRayMode,
1596
+ targetRaySpace,
1597
+ gripSpace,
1598
+ profiles,
1599
+ gamepad,
1600
+ hand,
1601
+ };
1602
+ }
1603
+ get handedness() {
1604
+ return this[PRIVATE$i].handedness;
1605
+ }
1606
+ get targetRayMode() {
1607
+ return this[PRIVATE$i].targetRayMode;
1608
+ }
1609
+ get targetRaySpace() {
1610
+ return this[PRIVATE$i].targetRaySpace;
1611
+ }
1612
+ get gripSpace() {
1613
+ return this[PRIVATE$i].gripSpace;
1614
+ }
1615
+ get profiles() {
1616
+ return this[PRIVATE$i].profiles;
1617
+ }
1618
+ get gamepad() {
1619
+ return this[PRIVATE$i].gamepad;
1620
+ }
1621
+ get hand() {
1622
+ return this[PRIVATE$i].hand;
1623
+ }
1624
+ }
1625
+
1626
+ class XRInputSourceEvent extends Event {
1627
+ constructor(type, eventInitDict) {
1628
+ super(type, eventInitDict);
1629
+ if (!eventInitDict.frame) {
1630
+ throw new Error('XRInputSourceEventInit.frame is required');
1631
+ }
1632
+ if (!eventInitDict.inputSource) {
1633
+ throw new Error('XRInputSourceEventInit.inputSource is required');
1634
+ }
1635
+ this.frame = eventInitDict.frame;
1636
+ this.inputSource = eventInitDict.inputSource;
1637
+ }
1638
+ }
1639
+
1640
+ const PRIVATE$h = Symbol('@immersive-web-emulation-runtime/xr-tracked-input');
1641
+ const DEFAULT_TRANSFORM = {
1642
+ [XRHandedness.Left]: {
1643
+ position: new Vector3(-0.25, 1.5, -0.4),
1644
+ quaternion: new Quaternion(),
1645
+ },
1646
+ [XRHandedness.Right]: {
1647
+ position: new Vector3(0.25, 1.5, -0.4),
1648
+ quaternion: new Quaternion(),
1649
+ },
1650
+ [XRHandedness.None]: {
1651
+ position: new Vector3(0.25, 1.5, -0.4),
1652
+ quaternion: new Quaternion(),
1653
+ },
1654
+ };
1655
+ class XRTrackedInput {
1656
+ constructor(inputSource) {
1657
+ this[PRIVATE$h] = {
1658
+ inputSource,
1659
+ position: DEFAULT_TRANSFORM[inputSource.handedness].position.clone(),
1660
+ quaternion: DEFAULT_TRANSFORM[inputSource.handedness].quaternion.clone(),
1661
+ connected: true,
1662
+ lastFrameConnected: false,
1663
+ inputSourceChanged: true,
1664
+ };
1665
+ }
1666
+ get position() {
1667
+ return this[PRIVATE$h].position;
1668
+ }
1669
+ get quaternion() {
1670
+ return this[PRIVATE$h].quaternion;
1671
+ }
1672
+ get inputSource() {
1673
+ return this[PRIVATE$h].inputSource;
1674
+ }
1675
+ get connected() {
1676
+ return this[PRIVATE$h].connected;
1677
+ }
1678
+ set connected(value) {
1679
+ this[PRIVATE$h].connected = value;
1680
+ this[PRIVATE$h].inputSource.gamepad[PRIVATE$j].connected = value;
1681
+ }
1682
+ onFrameStart(frame) {
1683
+ const targetRaySpace = this[PRIVATE$h].inputSource.targetRaySpace;
1684
+ fromRotationTranslation(targetRaySpace[PRIVATE$k].offsetMatrix, this[PRIVATE$h].quaternion.quat, this[PRIVATE$h].position.vec3);
1685
+ const session = frame.session;
1686
+ this[PRIVATE$h].inputSource.gamepad.buttons.forEach((button) => {
1687
+ if (button instanceof GamepadButton) {
1688
+ // apply pending values and record last frame values
1689
+ button[PRIVATE$j].lastFrameValue = button[PRIVATE$j].value;
1690
+ if (button[PRIVATE$j].pendingValue != null) {
1691
+ button[PRIVATE$j].value = button[PRIVATE$j].pendingValue;
1692
+ button[PRIVATE$j].pendingValue = null;
1693
+ }
1694
+ // trigger input source events
1695
+ if (button[PRIVATE$j].eventTrigger != null) {
1696
+ if (button[PRIVATE$j].lastFrameValue === 0 &&
1697
+ button[PRIVATE$j].value > 0) {
1698
+ session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$j].eventTrigger, {
1699
+ frame,
1700
+ inputSource: this[PRIVATE$h].inputSource,
1701
+ }));
1702
+ session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$j].eventTrigger + 'start', {
1703
+ frame,
1704
+ inputSource: this[PRIVATE$h].inputSource,
1705
+ }));
1706
+ }
1707
+ else if (button[PRIVATE$j].lastFrameValue > 0 &&
1708
+ button[PRIVATE$j].value === 0) {
1709
+ session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$j].eventTrigger + 'end', {
1710
+ frame,
1711
+ inputSource: this[PRIVATE$h].inputSource,
1712
+ }));
1713
+ }
1714
+ }
1715
+ }
1716
+ });
1717
+ this[PRIVATE$h].inputSourceChanged =
1718
+ this.connected !== this[PRIVATE$h].lastFrameConnected;
1719
+ this[PRIVATE$h].lastFrameConnected = this.connected;
1720
+ }
1721
+ }
1722
+
1723
+ class XRController extends XRTrackedInput {
1724
+ constructor(controllerConfig, handedness, globalSpace) {
1725
+ if (!controllerConfig.layout[handedness]) {
1726
+ throw new DOMException('Handedness not supported', 'InvalidStateError');
1727
+ }
1728
+ const targetRaySpace = new XRSpace(globalSpace);
1729
+ const gripSpace = controllerConfig.layout[handedness].gripOffsetMatrix
1730
+ ? new XRSpace(targetRaySpace, controllerConfig.layout[handedness].gripOffsetMatrix)
1731
+ : undefined;
1732
+ const profiles = [
1733
+ controllerConfig.profileId,
1734
+ ...controllerConfig.fallbackProfileIds,
1735
+ ];
1736
+ const inputSource = new XRInputSource(handedness, XRTargetRayMode.TrackedPointer, profiles, targetRaySpace, new Gamepad(controllerConfig.layout[handedness].gamepad), gripSpace);
1737
+ super(inputSource);
1738
+ }
1739
+ updateButtonValue(id, value) {
1740
+ if (value > 1 || value < 0) {
1741
+ console.warn(`Out-of-range value ${value} provided for button ${id}.`);
1742
+ return;
1743
+ }
1744
+ const gamepadButton = this[PRIVATE$h].inputSource.gamepad[PRIVATE$j].buttonsMap[id];
1745
+ if (gamepadButton) {
1746
+ if (gamepadButton[PRIVATE$j].type === 'binary' &&
1747
+ value != 1 &&
1748
+ value != 0) {
1749
+ console.warn(`Non-binary value ${value} provided for binary button ${id}.`);
1750
+ return;
1751
+ }
1752
+ gamepadButton[PRIVATE$j].pendingValue = value;
1753
+ }
1754
+ else {
1755
+ console.warn(`Current controller does not have button ${id}.`);
1756
+ }
1757
+ }
1758
+ updateButtonTouch(id, touched) {
1759
+ const gamepadButton = this[PRIVATE$h].inputSource.gamepad[PRIVATE$j].buttonsMap[id];
1760
+ if (gamepadButton) {
1761
+ gamepadButton[PRIVATE$j].touched = touched;
1762
+ }
1763
+ else {
1764
+ console.warn(`Current controller does not have button ${id}.`);
1765
+ }
1766
+ }
1767
+ updateAxis(id, type, value) {
1768
+ if (value > 1 || value < -1) {
1769
+ console.warn(`Out-of-range value ${value} provided for ${id} axes.`);
1770
+ return;
1771
+ }
1772
+ const axesById = this[PRIVATE$h].inputSource.gamepad[PRIVATE$j].axesMap[id];
1773
+ if (axesById) {
1774
+ if (type === 'x-axis') {
1775
+ axesById.x = value;
1776
+ }
1777
+ else if (type === 'y-axis') {
1778
+ axesById.y = value;
1779
+ }
1780
+ }
1781
+ else {
1782
+ console.warn(`Current controller does not have ${id} axes.`);
1783
+ }
1784
+ }
1785
+ updateAxes(id, x, y) {
1786
+ if (x > 1 || x < -1 || y > 1 || y < -1) {
1787
+ console.warn(`Out-of-range value x:${x}, y:${y} provided for ${id} axes.`);
1788
+ return;
1789
+ }
1790
+ const axesById = this[PRIVATE$h].inputSource.gamepad[PRIVATE$j].axesMap[id];
1791
+ if (axesById) {
1792
+ axesById.x = x;
1793
+ axesById.y = y;
1794
+ }
1795
+ else {
1796
+ console.warn(`Current controller does not have ${id} axes.`);
1797
+ }
1798
+ }
1799
+ }
1800
+
1801
+ const PRIVATE$g = Symbol('@immersive-web-emulation-runtime/xr-view');
1802
+ var XREye;
1803
+ (function (XREye) {
1804
+ XREye["None"] = "none";
1805
+ XREye["Left"] = "left";
1806
+ XREye["Right"] = "right";
1807
+ })(XREye || (XREye = {}));
1808
+ class XRView {
1809
+ constructor(eye, projectionMatrix, transform, session) {
1810
+ this[PRIVATE$g] = {
1811
+ eye,
1812
+ projectionMatrix,
1813
+ transform,
1814
+ recommendedViewportScale: null,
1815
+ requestedViewportScale: 1.0,
1816
+ session,
1817
+ };
1818
+ }
1819
+ get eye() {
1820
+ return this[PRIVATE$g].eye;
1821
+ }
1822
+ get projectionMatrix() {
1823
+ return this[PRIVATE$g].projectionMatrix;
1824
+ }
1825
+ get transform() {
1826
+ return this[PRIVATE$g].transform;
1827
+ }
1828
+ get recommendedViewportScale() {
1829
+ return this[PRIVATE$g].recommendedViewportScale;
1830
+ }
1831
+ requestViewportScale(scale) {
1832
+ if (scale === null || scale <= 0 || scale > 1) {
1833
+ console.warn('Invalid scale value. Scale must be > 0 and <= 1.');
1834
+ return;
1835
+ }
1836
+ this[PRIVATE$g].requestedViewportScale = scale;
1837
+ }
1838
+ }
1839
+
1840
+ var XRHandJoint;
1841
+ (function (XRHandJoint) {
1842
+ XRHandJoint["Wrist"] = "wrist";
1843
+ XRHandJoint["ThumbMetacarpal"] = "thumb-metacarpal";
1844
+ XRHandJoint["ThumbPhalanxProximal"] = "thumb-phalanx-proximal";
1845
+ XRHandJoint["ThumbPhalanxDistal"] = "thumb-phalanx-distal";
1846
+ XRHandJoint["ThumbTip"] = "thumb-tip";
1847
+ XRHandJoint["IndexFingerMetacarpal"] = "index-finger-metacarpal";
1848
+ XRHandJoint["IndexFingerPhalanxProximal"] = "index-finger-phalanx-proximal";
1849
+ XRHandJoint["IndexFingerPhalanxIntermediate"] = "index-finger-phalanx-intermediate";
1850
+ XRHandJoint["IndexFingerPhalanxDistal"] = "index-finger-phalanx-distal";
1851
+ XRHandJoint["IndexFingerTip"] = "index-finger-tip";
1852
+ XRHandJoint["MiddleFingerMetacarpal"] = "middle-finger-metacarpal";
1853
+ XRHandJoint["MiddleFingerPhalanxProximal"] = "middle-finger-phalanx-proximal";
1854
+ XRHandJoint["MiddleFingerPhalanxIntermediate"] = "middle-finger-phalanx-intermediate";
1855
+ XRHandJoint["MiddleFingerPhalanxDistal"] = "middle-finger-phalanx-distal";
1856
+ XRHandJoint["MiddleFingerTip"] = "middle-finger-tip";
1857
+ XRHandJoint["RingFingerMetacarpal"] = "ring-finger-metacarpal";
1858
+ XRHandJoint["RingFingerPhalanxProximal"] = "ring-finger-phalanx-proximal";
1859
+ XRHandJoint["RingFingerPhalanxIntermediate"] = "ring-finger-phalanx-intermediate";
1860
+ XRHandJoint["RingFingerPhalanxDistal"] = "ring-finger-phalanx-distal";
1861
+ XRHandJoint["RingFingerTip"] = "ring-finger-tip";
1862
+ XRHandJoint["PinkyFingerMetacarpal"] = "pinky-finger-metacarpal";
1863
+ XRHandJoint["PinkyFingerPhalanxProximal"] = "pinky-finger-phalanx-proximal";
1864
+ XRHandJoint["PinkyFingerPhalanxIntermediate"] = "pinky-finger-phalanx-intermediate";
1865
+ XRHandJoint["PinkyFingerPhalanxDistal"] = "pinky-finger-phalanx-distal";
1866
+ XRHandJoint["PinkyFingerTip"] = "pinky-finger-tip";
1867
+ })(XRHandJoint || (XRHandJoint = {}));
1868
+ class XRHand extends Map {
1869
+ }
1870
+
1871
+ const PRIVATE$f = Symbol('@immersive-web-emulation-runtime/xr-joint-space');
1872
+ class XRJointSpace extends XRSpace {
1873
+ constructor(jointName, parentSpace, offsetMatrix) {
1874
+ super(parentSpace, offsetMatrix);
1875
+ this[PRIVATE$f] = { jointName, radius: 0 };
1876
+ }
1877
+ get jointName() {
1878
+ return this[PRIVATE$f].jointName;
1879
+ }
1880
+ }
1881
+
1882
+ const pinchHandPose = {
1883
+ jointTransforms: {
1884
+ wrist: {
1885
+ offsetMatrix: [
1886
+ 0.9060805439949036, -0.1844543218612671, 0.3807799518108368, 0,
1887
+ -0.08027800172567368, 0.8086723685264587, 0.5827555656433105, 0,
1888
+ -0.4154181182384491, -0.5585917234420776, 0.7179155349731445, 0,
1889
+ -0.06867414712905884, -0.009423808194696903, 0.10627774149179459, 1,
1890
+ ],
1891
+ radius: 0.021460847929120064,
1892
+ },
1893
+ 'thumb-metacarpal': {
1894
+ offsetMatrix: [
1895
+ -0.5012241005897522, -0.8650535345077515, -0.0213695727288723, 0,
1896
+ 0.7415963411331177, -0.4421543478965759, 0.5045139193534851, 0,
1897
+ -0.44587990641593933, 0.23702676594257355, 0.8631392121315002, 0,
1898
+ -0.032122574746608734, -0.01196830440312624, 0.07194234430789948, 1,
1899
+ ],
1900
+ radius: 0.019382517784833908,
1901
+ },
1902
+ 'thumb-phalanx-proximal': {
1903
+ offsetMatrix: [
1904
+ -0.3175753057003021, -0.9460570216178894, -0.06419729441404343, 0,
1905
+ 0.8958902955055237, -0.32153913378715515, 0.30658137798309326, 0,
1906
+ -0.3106854259967804, 0.03984907269477844, 0.9496771097183228, 0,
1907
+ -0.017625702545046806, -0.01967475935816765, 0.04387917369604111, 1,
1908
+ ],
1909
+ radius: 0.01228295173496008,
1910
+ },
1911
+ 'thumb-phalanx-distal': {
1912
+ offsetMatrix: [
1913
+ -0.4944636821746826, -0.8691971898078918, 0.001086252392269671, 0,
1914
+ 0.8307800889015198, -0.4722411036491394, 0.2946045398712158, 0,
1915
+ -0.25555649399757385, 0.14657381176948547, 0.9556186199188232, 0,
1916
+ -0.007126678712666035, -0.021021386608481407, 0.011786630377173424, 1,
1917
+ ],
1918
+ radius: 0.009768804535269737,
1919
+ },
1920
+ 'thumb-tip': {
1921
+ offsetMatrix: [
1922
+ -0.4944636821746826, -0.8691971898078918, 0.001086252392269671, 0,
1923
+ 0.8307800889015198, -0.4722411036491394, 0.2946045398712158, 0,
1924
+ -0.25555649399757385, 0.14657381176948547, 0.9556186199188232, 0,
1925
+ 0.0003423091256991029, -0.024528030306100845, -0.011410919018089771, 1,
1926
+ ],
1927
+ radius: 0.008768804371356964,
1928
+ },
1929
+ 'index-finger-metacarpal': {
1930
+ offsetMatrix: [
1931
+ 0.9060805439949036, -0.1844543218612671, 0.3807799518108368, 0,
1932
+ -0.08027800172567368, 0.8086723685264587, 0.5827555656433105, 0,
1933
+ -0.4154181182384491, -0.5585917234420776, 0.7179155349731445, 0,
1934
+ -0.038037415593862534, -0.0020236473064869642, 0.07626739144325256, 1,
1935
+ ],
1936
+ radius: 0.021228281781077385,
1937
+ },
1938
+ 'index-finger-phalanx-proximal': {
1939
+ offsetMatrix: [
1940
+ 0.7986818552017212, -0.35985732078552246, 0.48229536414146423, 0,
1941
+ 0.538311243057251, 0.7854709625244141, -0.30537736415863037, 0,
1942
+ -0.2689369022846222, 0.5035246014595032, 0.8210577368736267, 0,
1943
+ -0.006869405973702669, 0.033938243985176086, 0.04206443578004837, 1,
1944
+ ],
1945
+ radius: 0.010295259766280651,
1946
+ },
1947
+ 'index-finger-phalanx-intermediate': {
1948
+ offsetMatrix: [
1949
+ 0.8285930156707764, -0.32672837376594543, 0.4546217918395996, 0,
1950
+ 0.5577570199966431, 0.4116027057170868, -0.7207564115524292, 0,
1951
+ 0.04836784675717354, 0.8507823944091797, 0.5232869386672974, 0,
1952
+ 0.0033306588884443045, 0.014840902760624886, 0.010923954658210278, 1,
1953
+ ],
1954
+ radius: 0.00853810179978609,
1955
+ },
1956
+ 'index-finger-phalanx-distal': {
1957
+ offsetMatrix: [
1958
+ 0.8412464261054993, -0.35794928669929504, 0.4051857888698578, 0,
1959
+ 0.5139996409416199, 0.29711154103279114, -0.8046918511390686, 0,
1960
+ 0.16765329241752625, 0.8852096796035767, 0.4339304566383362, 0,
1961
+ 0.0021551470272243023, -0.0058362227864563465, -0.0017938464879989624,
1962
+ 1,
1963
+ ],
1964
+ radius: 0.007636196445673704,
1965
+ },
1966
+ 'index-finger-tip': {
1967
+ offsetMatrix: [
1968
+ 0.8412464261054993, -0.35794928669929504, 0.4051857888698578, 0,
1969
+ 0.5139996409416199, 0.29711154103279114, -0.8046918511390686, 0,
1970
+ 0.16765329241752625, 0.8852096796035767, 0.4339304566383362, 0,
1971
+ -0.00131594471167773, -0.025222131982445717, -0.012442642822861671, 1,
1972
+ ],
1973
+ radius: 0.006636196281760931,
1974
+ },
1975
+ 'middle-finger-metacarpal': {
1976
+ offsetMatrix: [
1977
+ 0.9060805439949036, -0.1844543218612671, 0.3807799518108368, 0,
1978
+ -0.08027800172567368, 0.8086723685264587, 0.5827555656433105, 0,
1979
+ -0.4154181182384491, -0.5585917234420776, 0.7179155349731445, 0,
1980
+ -0.05395089089870453, 0.003063359996303916, 0.07402937114238739, 1,
1981
+ ],
1982
+ radius: 0.021231964230537415,
1983
+ },
1984
+ 'middle-finger-phalanx-proximal': {
1985
+ offsetMatrix: [
1986
+ 0.9187911748886108, -0.1530158370733261, 0.36387869715690613, 0,
1987
+ 0.038666240870952606, 0.9522662162780762, 0.302808940410614, 0,
1988
+ -0.3928440511226654, -0.26414817571640015, 0.8808513283729553, 0,
1989
+ -0.02717282809317112, 0.04162866622209549, 0.03678669035434723, 1,
1990
+ ],
1991
+ radius: 0.01117393933236599,
1992
+ },
1993
+ 'middle-finger-phalanx-intermediate': {
1994
+ offsetMatrix: [
1995
+ 0.9228746294975281, -0.12856416404247284, 0.36300456523895264, 0,
1996
+ 0.14524033665657043, 0.9892153143882751, -0.01890045404434204, 0,
1997
+ -0.3566599190235138, 0.07016586512327194, 0.9315956234931946, 0,
1998
+ -0.01030921470373869, 0.05296773463487625, -0.0010256498353555799, 1,
1999
+ ],
2000
+ radius: 0.008030958473682404,
2001
+ },
2002
+ 'middle-finger-phalanx-distal': {
2003
+ offsetMatrix: [
2004
+ 0.9325166344642639, -0.040404170751571655, 0.35885775089263916, 0,
2005
+ 0.06836572289466858, 0.995502769947052, -0.0655682161450386, 0,
2006
+ -0.3545948565006256, 0.08567725121974945, 0.9310863614082336, 0,
2007
+ -0.0004833847051486373, 0.05103470757603645, -0.026690717786550522, 1,
2008
+ ],
2009
+ radius: 0.007629410829395056,
2010
+ },
2011
+ 'middle-finger-tip': {
2012
+ offsetMatrix: [
2013
+ 0.9325166344642639, -0.040404170751571655, 0.35885775089263916, 0,
2014
+ 0.06836572289466858, 0.995502769947052, -0.0655682161450386, 0,
2015
+ -0.3545948565006256, 0.08567725121974945, 0.9310863614082336, 0,
2016
+ 0.008158999495208263, 0.05004044249653816, -0.050120558589696884, 1,
2017
+ ],
2018
+ radius: 0.006629410665482283,
2019
+ },
2020
+ 'ring-finger-metacarpal': {
2021
+ offsetMatrix: [
2022
+ 0.9060805439949036, -0.1844543218612671, 0.3807799518108368, 0,
2023
+ -0.08027800172567368, 0.8086723685264587, 0.5827555656433105, 0,
2024
+ -0.4154181182384491, -0.5585917234420776, 0.7179155349731445, 0,
2025
+ -0.06732909381389618, 0.007902119308710098, 0.07209732383489609, 1,
2026
+ ],
2027
+ radius: 0.019088275730609894,
2028
+ },
2029
+ 'ring-finger-phalanx-proximal': {
2030
+ offsetMatrix: [
2031
+ 0.9391821026802063, -0.027994679287075996, 0.34227466583251953, 0,
2032
+ -0.18282271921634674, 0.8029410243034363, 0.5673282742500305, 0,
2033
+ -0.2907087206840515, -0.5954000353813171, 0.7489906549453735, 0,
2034
+ -0.047129884362220764, 0.03806127607822418, 0.032147664576768875, 1,
2035
+ ],
2036
+ radius: 0.00992213748395443,
2037
+ },
2038
+ 'ring-finger-phalanx-intermediate': {
2039
+ offsetMatrix: [
2040
+ 0.9249380826950073, 0.03699534013867378, 0.3783116042613983, 0,
2041
+ -0.12898847460746765, 0.9667453765869141, 0.2208271026611328, 0,
2042
+ -0.3575615882873535, -0.25304901599884033, 0.8989526629447937, 0,
2043
+ -0.03579339757561684, 0.06127955764532089, 0.002939916681498289, 1,
2044
+ ],
2045
+ radius: 0.007611672393977642,
2046
+ },
2047
+ 'ring-finger-phalanx-distal': {
2048
+ offsetMatrix: [
2049
+ 0.9001164436340332, 0.03983335196971893, 0.4338230490684509, 0,
2050
+ -0.09662467986345291, 0.9892624020576477, 0.10964841395616531, 0,
2051
+ -0.4247973561286926, -0.14061418175697327, 0.8943013548851013, 0,
2052
+ -0.026291755959391594, 0.06800390034914017, -0.02094830758869648, 1,
2053
+ ],
2054
+ radius: 0.007231088820844889,
2055
+ },
2056
+ 'ring-finger-tip': {
2057
+ offsetMatrix: [
2058
+ 0.9001164436340332, 0.03983335196971893, 0.4338230490684509, 0,
2059
+ -0.09662467986345291, 0.9892624020576477, 0.10964841395616531, 0,
2060
+ -0.4247973561286926, -0.14061418175697327, 0.8943013548851013, 0,
2061
+ -0.016345610842108727, 0.07300511747598648, -0.04263874143362045, 1,
2062
+ ],
2063
+ radius: 0.0062310886569321156,
2064
+ },
2065
+ 'pinky-finger-metacarpal': {
2066
+ offsetMatrix: [
2067
+ 0.8769711852073669, 0.31462907791137695, 0.36322021484375, 0,
2068
+ -0.4506046175956726, 0.801031768321991, 0.39408499002456665, 0,
2069
+ -0.16696058213710785, -0.5092697143554688, 0.8442559838294983, 0,
2070
+ -0.07460174709558487, 0.0062340241856873035, 0.06756893545389175, 1,
2071
+ ],
2072
+ radius: 0.01808827556669712,
2073
+ },
2074
+ 'pinky-finger-phalanx-proximal': {
2075
+ offsetMatrix: [
2076
+ 0.9498357176780701, 0.1553308218717575, 0.2714462876319885, 0,
2077
+ -0.3019258379936218, 0.6817675232887268, 0.6663586497306824, 0,
2078
+ -0.08155745267868042, -0.7148879170417786, 0.694466233253479, 0,
2079
+ -0.06697750836610794, 0.029482364654541016, 0.02902858518064022, 1,
2080
+ ],
2081
+ radius: 0.008483353070914745,
2082
+ },
2083
+ 'pinky-finger-phalanx-intermediate': {
2084
+ offsetMatrix: [
2085
+ 0.9214097261428833, 0.27928245067596436, 0.2701927423477173, 0,
2086
+ -0.3670244514942169, 0.8538867831230164, 0.36901235580444336, 0,
2087
+ -0.12765564024448395, -0.43917882442474365, 0.8892839550971985, 0,
2088
+ -0.06447203457355499, 0.05144399777054787, 0.0076942890882492065, 1,
2089
+ ],
2090
+ radius: 0.0067641944624483585,
2091
+ },
2092
+ 'pinky-finger-phalanx-distal': {
2093
+ offsetMatrix: [
2094
+ 0.9038633704185486, 0.23618005216121674, 0.3567195236682892, 0,
2095
+ -0.3532794713973999, 0.8823202252388, 0.3109731376171112, 0,
2096
+ -0.24129553139209747, -0.4070987403392792, 0.8809353709220886, 0,
2097
+ -0.06187915802001953, 0.060364335775375366, -0.010368337854743004, 1,
2098
+ ],
2099
+ radius: 0.0064259846694767475,
2100
+ },
2101
+ 'pinky-finger-tip': {
2102
+ offsetMatrix: [
2103
+ 0.9038633704185486, 0.23618005216121674, 0.3567195236682892, 0,
2104
+ -0.3532794713973999, 0.8823202252388, 0.3109731376171112, 0,
2105
+ -0.24129553139209747, -0.4070987403392792, 0.8809353709220886, 0,
2106
+ -0.056796226650476456, 0.07042007893323898, -0.02921444922685623, 1,
2107
+ ],
2108
+ radius: 0.005425984505563974,
2109
+ },
2110
+ },
2111
+ gripOffsetMatrix: [
2112
+ 0.08027800917625427, -0.8086723685264587, -0.5827556252479553, 0,
2113
+ -0.4154181480407715, -0.5585916638374329, 0.7179154753684998, 0,
2114
+ -0.9060805439949036, 0.1844543218612671, -0.3807799518108368, 0,
2115
+ -0.038054611533880234, -0.002910431008785963, 0.03720742464065552, 1,
2116
+ ],
2117
+ };
2118
+
2119
+ const pointHandPose = {
2120
+ jointTransforms: {
2121
+ wrist: {
2122
+ offsetMatrix: [
2123
+ 0.9340395331382751, -0.13936476409435272, 0.32885703444480896, 0,
2124
+ -0.005510995630174875, 0.914999783039093, 0.40341612696647644, 0,
2125
+ -0.3571262061595917, -0.37861889600753784, 0.8538784384727478, 0,
2126
+ -0.05789132043719292, 0.01670890860259533, 0.11183350533246994, 1,
2127
+ ],
2128
+ radius: 0.021460847929120064,
2129
+ },
2130
+ 'thumb-metacarpal': {
2131
+ offsetMatrix: [
2132
+ 0.02145560085773468, -0.9978390336036682, 0.0621047280728817, 0,
2133
+ 0.41311800479888916, 0.06541631370782852, 0.9083252549171448, 0,
2134
+ -0.9104245901107788, 0.006167683284729719, 0.4136286973953247, 0,
2135
+ -0.016488194465637207, 0.012708572670817375, 0.08862338215112686, 1,
2136
+ ],
2137
+ radius: 0.019382517784833908,
2138
+ },
2139
+ 'thumb-phalanx-proximal': {
2140
+ offsetMatrix: [
2141
+ 0.21270370483398438, -0.966137707233429, 0.14606566727161407, 0,
2142
+ 0.49890995025634766, 0.2359165996313095, 0.8339261412620544, 0,
2143
+ -0.8401462435722351, -0.10450579971075058, 0.5321959853172302, 0,
2144
+ 0.013112368993461132, 0.012508046813309193, 0.07517509907484055, 1,
2145
+ ],
2146
+ radius: 0.01228295173496008,
2147
+ },
2148
+ 'thumb-phalanx-distal': {
2149
+ offsetMatrix: [
2150
+ 0.01653280481696129, -0.9986647963523865, 0.048943229019641876, 0,
2151
+ 0.26313456892967224, 0.051570065319538116, 0.9633802771568298, 0,
2152
+ -0.9646173715591431, -0.0030490627977997065, 0.26363563537597656, 0,
2153
+ 0.04150351136922836, 0.016039609909057617, 0.05719054117798805, 1,
2154
+ ],
2155
+ radius: 0.009768804535269737,
2156
+ },
2157
+ 'thumb-tip': {
2158
+ offsetMatrix: [
2159
+ 0.01653280481696129, -0.9986647963523865, 0.048943229019641876, 0,
2160
+ 0.26313456892967224, 0.051570065319538116, 0.9633802771568298, 0,
2161
+ -0.9646173715591431, -0.0030490627977997065, 0.26363563537597656, 0,
2162
+ 0.06548332422971725, 0.01683700829744339, 0.0516640841960907, 1,
2163
+ ],
2164
+ radius: 0.008768804371356964,
2165
+ },
2166
+ 'index-finger-metacarpal': {
2167
+ offsetMatrix: [
2168
+ 0.9340395331382751, -0.13936476409435272, 0.32885703444480896, 0,
2169
+ -0.005510995630174875, 0.914999783039093, 0.40341612696647644, 0,
2170
+ -0.3571262061595917, -0.37861889600753784, 0.8538784384727478, 0,
2171
+ -0.02592567168176174, 0.019982583820819855, 0.08479326963424683, 1,
2172
+ ],
2173
+ radius: 0.021228281781077385,
2174
+ },
2175
+ 'index-finger-phalanx-proximal': {
2176
+ offsetMatrix: [
2177
+ 0.9063700437545776, -0.21756279468536377, 0.3621589243412018, 0,
2178
+ 0.0970839336514473, 0.9415287375450134, 0.3226419687271118, 0,
2179
+ -0.41117796301841736, -0.2572731077671051, 0.8744958639144897, 0,
2180
+ -0.0015709538711234927, 0.043078210204839706, 0.034657616168260574, 1,
2181
+ ],
2182
+ radius: 0.010295259766280651,
2183
+ },
2184
+ 'index-finger-phalanx-intermediate': {
2185
+ offsetMatrix: [
2186
+ 0.9159826040267944, -0.1651475727558136, 0.36565208435058594, 0,
2187
+ 0.09755707532167435, 0.9756820797920227, 0.1962820291519165, 0,
2188
+ -0.3891757130622864, -0.14411886036396027, 0.9098196625709534, 0,
2189
+ 0.014023927971720695, 0.052835866808891296, 0.0014903299743309617, 1,
2190
+ ],
2191
+ radius: 0.00853810179978609,
2192
+ },
2193
+ 'index-finger-phalanx-distal': {
2194
+ offsetMatrix: [
2195
+ 0.9378057718276978, -0.12329639494419098, 0.3245268166065216, 0,
2196
+ 0.032558172941207886, 0.9619227051734924, 0.2713746726512909, 0,
2197
+ -0.3456292748451233, -0.2439306229352951, 0.9061115384101868, 0,
2198
+ 0.023482320830225945, 0.05633850023150444, -0.020621655508875847, 1,
2199
+ ],
2200
+ radius: 0.007636196445673704,
2201
+ },
2202
+ 'index-finger-tip': {
2203
+ offsetMatrix: [
2204
+ 0.9378057718276978, -0.12329639494419098, 0.3245268166065216, 0,
2205
+ 0.032558172941207886, 0.9619227051734924, 0.2713746726512909, 0,
2206
+ -0.3456292748451233, -0.2439306229352951, 0.9061115384101868, 0,
2207
+ 0.03096788562834263, 0.06281610578298569, -0.040703095495700836, 1,
2208
+ ],
2209
+ radius: 0.006636196281760931,
2210
+ },
2211
+ 'middle-finger-metacarpal': {
2212
+ offsetMatrix: [
2213
+ 0.9340395331382751, -0.13936476409435272, 0.32885703444480896, 0,
2214
+ -0.005510995630174875, 0.914999783039093, 0.40341612696647644, 0,
2215
+ -0.3571262061595917, -0.37861889600753784, 0.8538784384727478, 0,
2216
+ -0.04184452444314957, 0.022474845871329308, 0.08177298307418823, 1,
2217
+ ],
2218
+ radius: 0.021231964230537415,
2219
+ },
2220
+ 'middle-finger-phalanx-proximal': {
2221
+ offsetMatrix: [
2222
+ 0.9720265865325928, -0.08313076198101044, 0.21966552734375, 0,
2223
+ 0.20477405190467834, 0.7580050826072693, -0.6192700862884521, 0,
2224
+ -0.11502730846405029, 0.6469289064407349, 0.7538246512413025, 0,
2225
+ -0.022107340395450592, 0.05035499855875969, 0.02970452979207039, 1,
2226
+ ],
2227
+ radius: 0.01117393933236599,
2228
+ },
2229
+ 'middle-finger-phalanx-intermediate': {
2230
+ offsetMatrix: [
2231
+ 0.9779140949249268, -0.07129573822021484, 0.19646917283535004, 0,
2232
+ 0.1287083923816681, -0.5352076292037964, -0.8348574042320251, 0,
2233
+ 0.1646735966205597, 0.8417060971260071, -0.5142109394073486, 0,
2234
+ -0.017169542610645294, 0.022584279999136925, -0.00265491777099669, 1,
2235
+ ],
2236
+ radius: 0.008030958473682404,
2237
+ },
2238
+ 'middle-finger-phalanx-distal': {
2239
+ offsetMatrix: [
2240
+ 0.9774913787841797, -0.19657190144062042, 0.07661263644695282, 0,
2241
+ -0.1924918293952942, -0.9796126484870911, -0.05749811604619026, 0,
2242
+ 0.08635343611240387, 0.041456472128629684, -0.995401918888092, 0,
2243
+ -0.02170622907578945, -0.0006043742760084569, 0.011511396616697311, 1,
2244
+ ],
2245
+ radius: 0.007629410829395056,
2246
+ },
2247
+ 'middle-finger-tip': {
2248
+ offsetMatrix: [
2249
+ 0.9774913787841797, -0.19657190144062042, 0.07661263644695282, 0,
2250
+ -0.1924918293952942, -0.9796126484870911, -0.05749811604619026, 0,
2251
+ 0.08635343611240387, 0.041456472128629684, -0.995401918888092, 0,
2252
+ -0.02438267692923546, -0.0026927536819130182, 0.03627248480916023, 1,
2253
+ ],
2254
+ radius: 0.006629410665482283,
2255
+ },
2256
+ 'ring-finger-metacarpal': {
2257
+ offsetMatrix: [
2258
+ 0.9340395331382751, -0.13936476409435272, 0.32885703444480896, 0,
2259
+ -0.005510995630174875, 0.914999783039093, 0.40341612696647644, 0,
2260
+ -0.3571262061595917, -0.37861889600753784, 0.8538784384727478, 0,
2261
+ -0.05944233387708664, 0.0264605600386858, 0.07478221505880356, 1,
2262
+ ],
2263
+ radius: 0.019088275730609894,
2264
+ },
2265
+ 'ring-finger-phalanx-proximal': {
2266
+ offsetMatrix: [
2267
+ 0.9842101335525513, 0.024470895528793335, 0.1753024309873581, 0,
2268
+ 0.12200043350458145, 0.6237703561782837, -0.7720272541046143, 0,
2269
+ -0.12824076414108276, 0.7812241315841675, 0.610936164855957, 0,
2270
+ -0.04249368980526924, 0.0467497780919075, 0.027722163125872612, 1,
2271
+ ],
2272
+ radius: 0.00992213748395443,
2273
+ },
2274
+ 'ring-finger-phalanx-intermediate': {
2275
+ offsetMatrix: [
2276
+ 0.9941774606704712, 0.05949164181947708, 0.08983955532312393, 0,
2277
+ 0.10504482686519623, -0.7208291888237, -0.6851072907447815, 0,
2278
+ 0.024001073092222214, 0.6905553936958313, -0.7228817939758301, 0,
2279
+ -0.0374927744269371, 0.016285063698887825, 0.0038980208337306976, 1,
2280
+ ],
2281
+ radius: 0.007611672393977642,
2282
+ },
2283
+ 'ring-finger-phalanx-distal': {
2284
+ offsetMatrix: [
2285
+ 0.9995742440223694, 0.01638498157262802, 0.02412819117307663, 0,
2286
+ 0.007813597097992897, -0.9474818110466003, 0.31971633434295654, 0,
2287
+ 0.028100071474909782, -0.31939181685447693, -0.9472070932388306, 0,
2288
+ -0.038130562752485275, -0.0020653479732573032, 0.02310742810368538, 1,
2289
+ ],
2290
+ radius: 0.007231088820844889,
2291
+ },
2292
+ 'ring-finger-tip': {
2293
+ offsetMatrix: [
2294
+ 0.9995742440223694, 0.01638498157262802, 0.02412819117307663, 0,
2295
+ 0.007813597097992897, -0.9474818110466003, 0.31971633434295654, 0,
2296
+ 0.028100071474909782, -0.31939181685447693, -0.9472070932388306, 0,
2297
+ -0.0390593595802784, 0.004176302347332239, 0.0466572530567646, 1,
2298
+ ],
2299
+ radius: 0.0062310886569321156,
2300
+ },
2301
+ 'pinky-finger-metacarpal': {
2302
+ offsetMatrix: [
2303
+ 0.9147363901138306, 0.3458845317363739, 0.20885537564754486, 0,
2304
+ -0.3923271894454956, 0.8839452862739563, 0.2544005811214447, 0,
2305
+ -0.09662359952926636, -0.3146490156650543, 0.9442773461341858, 0,
2306
+ -0.06715242564678192, 0.024195827543735504, 0.07137546688318253, 1,
2307
+ ],
2308
+ radius: 0.01808827556669712,
2309
+ },
2310
+ 'pinky-finger-phalanx-proximal': {
2311
+ offsetMatrix: [
2312
+ 0.9613109827041626, 0.22439135611057281, 0.15977802872657776, 0,
2313
+ 0.01002211682498455, 0.5511574745178223, -0.8343409299850464, 0,
2314
+ -0.27528178691864014, 0.8036624789237976, 0.5275853276252747, 0,
2315
+ -0.06273911893367767, 0.038559623062610626, 0.028268879279494286, 1,
2316
+ ],
2317
+ radius: 0.008483353070914745,
2318
+ },
2319
+ 'pinky-finger-phalanx-intermediate': {
2320
+ offsetMatrix: [
2321
+ 0.9820972084999084, 0.18811029195785522, -0.00995189044624567, 0,
2322
+ 0.14063723385334015, -0.7673450708389282, -0.6256227493286133, 0,
2323
+ -0.12532226741313934, 0.6130226850509644, -0.7800630927085876, 0,
2324
+ -0.05428232625126839, 0.013870777562260628, 0.012061242014169693, 1,
2325
+ ],
2326
+ radius: 0.0067641944624483585,
2327
+ },
2328
+ 'pinky-finger-phalanx-distal': {
2329
+ offsetMatrix: [
2330
+ 0.9744614362716675, 0.20454788208007812, -0.09265263378620148, 0,
2331
+ 0.22429193556308746, -0.9065253138542175, 0.35764020681381226, 0,
2332
+ -0.010836843401193619, -0.3692878782749176, -0.9292529225349426, 0,
2333
+ -0.05173685774207115, 0.0014194445684552193, 0.02790539152920246, 1,
2334
+ ],
2335
+ radius: 0.0064259846694767475,
2336
+ },
2337
+ 'pinky-finger-tip': {
2338
+ offsetMatrix: [
2339
+ 0.9744614362716675, 0.20454788208007812, -0.09265263378620148, 0,
2340
+ 0.22429193556308746, -0.9065253138542175, 0.35764020681381226, 0,
2341
+ -0.010836843401193619, -0.3692878782749176, -0.9292529225349426, 0,
2342
+ -0.05098633095622063, 0.008463085629045963, 0.048688892275094986, 1,
2343
+ ],
2344
+ radius: 0.005425984505563974,
2345
+ },
2346
+ },
2347
+ gripOffsetMatrix: [
2348
+ 0.005510995630174875, -0.9149997234344482, -0.40341615676879883, 0,
2349
+ -0.3571262061595917, -0.37861889600753784, 0.8538784384727478, 0,
2350
+ -0.9340395331382751, 0.13936474919319153, -0.32885703444480896, 0,
2351
+ -0.031803809106349945, 0.007837686687707901, 0.04313928261399269, 1,
2352
+ ],
2353
+ };
2354
+
2355
+ const relaxedHandPose = {
2356
+ jointTransforms: {
2357
+ wrist: {
2358
+ offsetMatrix: [
2359
+ 0.9616971015930176, -0.13805118203163147, 0.2368120402097702, 0,
2360
+ 0.0005348679260350764, 0.8648636937141418, 0.5020061135292053, 0,
2361
+ -0.2741127610206604, -0.48265108466148376, 0.8318111300468445, 0,
2362
+ -0.04913589730858803, 0.0021463718730956316, 0.11701996624469757, 1,
2363
+ ],
2364
+ radius: 0.021460847929120064,
2365
+ },
2366
+ 'thumb-metacarpal': {
2367
+ offsetMatrix: [
2368
+ -0.07536252588033676, -0.9959676265716553, -0.04867160692811012, 0,
2369
+ 0.5877083539962769, -0.08379616588354111, 0.8047218918800354, 0,
2370
+ -0.8055551648139954, 0.032041035592556, 0.5916536450386047, 0,
2371
+ -0.010643752291798592, 0.0006936835707165301, 0.08736639469861984, 1,
2372
+ ],
2373
+ radius: 0.019382517784833908,
2374
+ },
2375
+ 'thumb-phalanx-proximal': {
2376
+ offsetMatrix: [
2377
+ 0.1374533325433731, -0.9904957413673401, 0.004982374142855406, 0,
2378
+ 0.5534393787384033, 0.08097179979085922, 0.8289443850517273, 0,
2379
+ -0.8214688897132874, -0.11118389666080475, 0.559309184551239, 0,
2380
+ 0.015547193586826324, -0.0003480653394944966, 0.0681300163269043, 1,
2381
+ ],
2382
+ radius: 0.01228295173496008,
2383
+ },
2384
+ 'thumb-phalanx-distal': {
2385
+ offsetMatrix: [
2386
+ -0.04659227654337883, -0.9974699020385742, -0.05369402840733528, 0,
2387
+ 0.6812446117401123, -0.07104194164276123, 0.728600800037384, 0,
2388
+ -0.7305715084075928, -0.002631746232509613, 0.6828309893608093, 0,
2389
+ 0.04330715537071228, 0.003409178927540779, 0.0492292083799839, 1,
2390
+ ],
2391
+ radius: 0.009768804535269737,
2392
+ },
2393
+ 'thumb-tip': {
2394
+ offsetMatrix: [
2395
+ -0.04659227654337883, -0.9974699020385742, -0.05369402840733528, 0,
2396
+ 0.6812446117401123, -0.07104194164276123, 0.728600800037384, 0,
2397
+ -0.7305715084075928, -0.002631746232509613, 0.6828309893608093, 0,
2398
+ 0.062003348022699356, 0.004069602582603693, 0.03322213143110275, 1,
2399
+ ],
2400
+ radius: 0.008768804371356964,
2401
+ },
2402
+ 'index-finger-metacarpal': {
2403
+ offsetMatrix: [
2404
+ 0.9616971015930176, -0.13805118203163147, 0.2368120402097702, 0,
2405
+ 0.0005348679260350764, 0.8648636937141418, 0.5020061135292053, 0,
2406
+ -0.2741127610206604, -0.48265108466148376, 0.8318111300468445, 0,
2407
+ -0.02009812369942665, 0.008770795539021492, 0.08660387247800827, 1,
2408
+ ],
2409
+ radius: 0.021228281781077385,
2410
+ },
2411
+ 'index-finger-phalanx-proximal': {
2412
+ offsetMatrix: [
2413
+ 0.9001791477203369, -0.2598813474178314, 0.3494834005832672, 0,
2414
+ 0.06073702871799469, 0.8695210218429565, 0.490146666765213, 0,
2415
+ -0.4312632381916046, -0.41999316215515137, 0.7985095381736755, 0,
2416
+ -0.00017739279428496957, 0.03890012577176094, 0.039073407649993896, 1,
2417
+ ],
2418
+ radius: 0.010295259766280651,
2419
+ },
2420
+ 'index-finger-phalanx-intermediate': {
2421
+ offsetMatrix: [
2422
+ 0.9082008600234985, -0.20898112654685974, 0.36262574791908264, 0,
2423
+ 0.11045389622449875, 0.9553793668746948, 0.27395179867744446, 0,
2424
+ -0.40369608998298645, -0.20874978601932526, 0.8907597661018372, 0,
2425
+ 0.01617925800383091, 0.05482936650514603, 0.008788082748651505, 1,
2426
+ ],
2427
+ radius: 0.00853810179978609,
2428
+ },
2429
+ 'index-finger-phalanx-distal': {
2430
+ offsetMatrix: [
2431
+ 0.9309692978858948, -0.16783711314201355, 0.32423174381256104, 0,
2432
+ 0.1080828532576561, 0.9749603867530823, 0.1943446695804596, 0,
2433
+ -0.34873148798942566, -0.14588497579097748, 0.9257990717887878, 0,
2434
+ 0.02599053829908371, 0.059902746230363846, -0.012860597111284733, 1,
2435
+ ],
2436
+ radius: 0.007636196445673704,
2437
+ },
2438
+ 'index-finger-tip': {
2439
+ offsetMatrix: [
2440
+ 0.9309692978858948, -0.16783711314201355, 0.32423174381256104, 0,
2441
+ 0.1080828532576561, 0.9749603867530823, 0.1943446695804596, 0,
2442
+ -0.34873148798942566, -0.14588497579097748, 0.9257990717887878, 0,
2443
+ 0.03362493962049484, 0.06421422213315964, -0.033461250364780426, 1,
2444
+ ],
2445
+ radius: 0.006636196281760931,
2446
+ },
2447
+ 'middle-finger-metacarpal': {
2448
+ offsetMatrix: [
2449
+ 0.9616971015930176, -0.13805118203163147, 0.2368120402097702, 0,
2450
+ 0.0005348679260350764, 0.8648636937141418, 0.5020061135292053, 0,
2451
+ -0.2741127610206604, -0.48265108466148376, 0.8318111300468445, 0,
2452
+ -0.03627845644950867, 0.011579737067222595, 0.08550142496824265, 1,
2453
+ ],
2454
+ radius: 0.021231964230537415,
2455
+ },
2456
+ 'middle-finger-phalanx-proximal': {
2457
+ offsetMatrix: [
2458
+ 0.9876697659492493, -0.06786545366048813, 0.1410750150680542, 0,
2459
+ -0.015095947310328484, 0.855663537979126, 0.5173118710517883, 0,
2460
+ -0.15582047402858734, -0.5130629539489746, 0.8440889716148376, 0,
2461
+ -0.021259509027004242, 0.04587256908416748, 0.03659208118915558, 1,
2462
+ ],
2463
+ radius: 0.01117393933236599,
2464
+ },
2465
+ 'middle-finger-phalanx-intermediate': {
2466
+ offsetMatrix: [
2467
+ 0.988391637802124, -0.04354291781783104, 0.14555205404758453, 0,
2468
+ 0.008894841186702251, 0.9729899168014526, 0.23067504167556763, 0,
2469
+ -0.15166506171226501, -0.22670257091522217, 0.9620829224586487, 0,
2470
+ -0.014570588245987892, 0.06789684295654297, 0.0003578895702958107, 1,
2471
+ ],
2472
+ radius: 0.008030958473682404,
2473
+ },
2474
+ 'middle-finger-phalanx-distal': {
2475
+ offsetMatrix: [
2476
+ 0.9853697419166565, 0.044260796159505844, 0.16458062827587128, 0,
2477
+ -0.0757969319820404, 0.9787378311157227, 0.19059516489505768, 0,
2478
+ -0.1526455283164978, -0.20028135180473328, 0.9677740931510925, 0,
2479
+ -0.010392282158136368, 0.07414241135120392, -0.026147106662392616, 1,
2480
+ ],
2481
+ radius: 0.007629410829395056,
2482
+ },
2483
+ 'middle-finger-tip': {
2484
+ offsetMatrix: [
2485
+ 0.9853697419166565, 0.044260796159505844, 0.16458062827587128, 0,
2486
+ -0.0757969319820404, 0.9787378311157227, 0.19059516489505768, 0,
2487
+ -0.1526455283164978, -0.20028135180473328, 0.9677740931510925, 0,
2488
+ -0.0069718430750072, 0.08024183660745621, -0.05014154314994812, 1,
2489
+ ],
2490
+ radius: 0.006629410665482283,
2491
+ },
2492
+ 'ring-finger-metacarpal': {
2493
+ offsetMatrix: [
2494
+ 0.9616971015930176, -0.13805118203163147, 0.2368120402097702, 0,
2495
+ 0.0005348679260350764, 0.8648636937141418, 0.5020061135292053, 0,
2496
+ -0.2741127610206604, -0.48265108466148376, 0.8318111300468445, 0,
2497
+ -0.05402477830648422, 0.015797706320881844, 0.08152295649051666, 1,
2498
+ ],
2499
+ radius: 0.019088275730609894,
2500
+ },
2501
+ 'ring-finger-phalanx-proximal': {
2502
+ offsetMatrix: [
2503
+ 0.9940828680992126, 0.05735103040933609, 0.09224652498960495, 0,
2504
+ -0.10022822767496109, 0.8116500377655029, 0.5754809379577637, 0,
2505
+ -0.041867565363645554, -0.5813214182853699, 0.8125960826873779, 0,
2506
+ -0.041623555123806, 0.04171867296099663, 0.03582974523305893, 1,
2507
+ ],
2508
+ radius: 0.00992213748395443,
2509
+ },
2510
+ 'ring-finger-phalanx-intermediate': {
2511
+ offsetMatrix: [
2512
+ 0.9843675494194031, 0.12044742703437805, 0.12850022315979004, 0,
2513
+ -0.15629759430885315, 0.9337108135223389, 0.3221098482608795, 0,
2514
+ -0.08118485659360886, -0.3371586799621582, 0.937940776348114, 0,
2515
+ -0.039990875869989395, 0.06438793987035751, 0.004141641780734062, 1,
2516
+ ],
2517
+ radius: 0.007611672393977642,
2518
+ },
2519
+ 'ring-finger-phalanx-distal': {
2520
+ offsetMatrix: [
2521
+ 0.9748351573944092, 0.11857274919748306, 0.18877571821212769, 0,
2522
+ -0.15575434267520905, 0.9681083559989929, 0.19623035192489624, 0,
2523
+ -0.15948788821697235, -0.22069483995437622, 0.9622148275375366, 0,
2524
+ -0.03783353418111801, 0.07334739714860916, -0.020782606676220894, 1,
2525
+ ],
2526
+ radius: 0.007231088820844889,
2527
+ },
2528
+ 'ring-finger-tip': {
2529
+ offsetMatrix: [
2530
+ 0.9748351573944092, 0.11857274919748306, 0.18877571821212769, 0,
2531
+ -0.15575434267520905, 0.9681083559989929, 0.19623035192489624, 0,
2532
+ -0.15948788821697235, -0.22069483995437622, 0.9622148275375366, 0,
2533
+ -0.03445569798350334, 0.0802423357963562, -0.04392268508672714, 1,
2534
+ ],
2535
+ radius: 0.0062310886569321156,
2536
+ },
2537
+ 'pinky-finger-metacarpal': {
2538
+ offsetMatrix: [
2539
+ 0.9181402921676636, 0.35625091195106506, 0.17350243031978607, 0,
2540
+ -0.39615097641944885, 0.8352503180503845, 0.38134080171585083, 0,
2541
+ -0.009065053425729275, -0.41885748505592346, 0.9080066680908203, 0,
2542
+ -0.06191859766840935, 0.013620133511722088, 0.07850203663110733, 1,
2543
+ ],
2544
+ radius: 0.01808827556669712,
2545
+ },
2546
+ 'pinky-finger-phalanx-proximal': {
2547
+ offsetMatrix: [
2548
+ 0.9714386463165283, 0.236698180437088, -0.016745081171393394, 0,
2549
+ -0.18462024629116058, 0.7982627749443054, 0.5733163952827454, 0,
2550
+ 0.14906984567642212, -0.5538501739501953, 0.8191629648208618, 0,
2551
+ -0.061502378433942795, 0.032741155475378036, 0.03705105185508728, 1,
2552
+ ],
2553
+ radius: 0.008483353070914745,
2554
+ },
2555
+ 'pinky-finger-phalanx-intermediate': {
2556
+ offsetMatrix: [
2557
+ 0.9337416291236877, 0.35620439052581787, -0.03527557849884033, 0,
2558
+ -0.33203884959220886, 0.8987522721290588, 0.28634607791900635, 0,
2559
+ 0.13370157778263092, -0.2556603252887726, 0.9574766755104065, 0,
2560
+ -0.06608185172080994, 0.049755651503801346, 0.011886020191013813, 1,
2561
+ ],
2562
+ radius: 0.0067641944624483585,
2563
+ },
2564
+ 'pinky-finger-phalanx-distal': {
2565
+ offsetMatrix: [
2566
+ 0.9419984817504883, 0.3303581774234772, 0.059175245463848114, 0,
2567
+ -0.33483216166496277, 0.9130291938781738, 0.23294763267040253, 0,
2568
+ 0.02292730286717415, -0.2392500638961792, 0.970687210559845, 0,
2569
+ -0.0687975287437439, 0.054948460310697556, -0.007561664097011089, 1,
2570
+ ],
2571
+ radius: 0.0064259846694767475,
2572
+ },
2573
+ 'pinky-finger-tip': {
2574
+ offsetMatrix: [
2575
+ 0.9419984817504883, 0.3303581774234772, 0.059175245463848114, 0,
2576
+ -0.33483216166496277, 0.9130291938781738, 0.23294763267040253, 0,
2577
+ 0.02292730286717415, -0.2392500638961792, 0.970687210559845, 0,
2578
+ -0.06947512179613113, 0.0613851435482502, -0.028543535619974136, 1,
2579
+ ],
2580
+ radius: 0.005425984505563974,
2581
+ },
2582
+ },
2583
+ gripOffsetMatrix: [
2584
+ -0.0005348679260350764, -0.8648636937141418, -0.5020061135292053, 0,
2585
+ -0.2741127908229828, -0.48265108466148376, 0.8318111896514893, 0,
2586
+ -0.9616971015930176, 0.13805119693279266, -0.2368120402097702, 0,
2587
+ -0.02878567762672901, 0.0017147823236882687, 0.04536811262369156, 1,
2588
+ ],
2589
+ };
2590
+
2591
+ const oculusHandConfig = {
2592
+ profileId: 'oculus-hand',
2593
+ fallbackProfileIds: [
2594
+ 'generic-hand',
2595
+ 'generic-hand-select',
2596
+ 'generic-trigger',
2597
+ ],
2598
+ poses: {
2599
+ default: relaxedHandPose,
2600
+ pinch: pinchHandPose,
2601
+ point: pointHandPose,
2602
+ },
2603
+ };
2604
+ const XRHandGamepadConfig = {
2605
+ mapping: GamepadMappingType.None,
2606
+ buttons: [{ id: 'pinch', type: 'analog', eventTrigger: 'select' }],
2607
+ axes: [],
2608
+ };
2609
+ const fromPosition = create$2();
2610
+ const fromQuaternion = create();
2611
+ const fromScale = create$2();
2612
+ const toPosition = create$2();
2613
+ const toQuaternion = create();
2614
+ const toScale = create$2();
2615
+ const interpolatedPosition = create$2();
2616
+ const interpolatedQuaternion = create();
2617
+ const interpolatedScale = create$2();
2618
+ const interpolateMatrix = (out, fromMatrix, toMatrix, alpha) => {
2619
+ getTranslation(fromPosition, fromMatrix);
2620
+ getRotation(fromQuaternion, fromMatrix);
2621
+ getScaling(fromScale, fromMatrix);
2622
+ getTranslation(toPosition, toMatrix);
2623
+ getRotation(toQuaternion, toMatrix);
2624
+ getScaling(toScale, toMatrix);
2625
+ lerp(interpolatedPosition, fromPosition, toPosition, alpha);
2626
+ slerp(interpolatedQuaternion, fromQuaternion, toQuaternion, alpha);
2627
+ lerp(interpolatedScale, fromScale, toScale, alpha);
2628
+ fromRotationTranslationScale(out, interpolatedQuaternion, interpolatedPosition, interpolatedScale);
2629
+ return out;
2630
+ };
2631
+ const mirrorMultiplierMatrix = [
2632
+ 1, -1, -1, 0, -1, 1, 1, 0, -1, 1, 1, 0, -1, 1, 1, 1,
2633
+ ];
2634
+ const mirrorMatrixToRight = (matrixLeft) => {
2635
+ for (let i = 0; i < 16; i++) {
2636
+ matrixLeft[i] *= mirrorMultiplierMatrix[i];
2637
+ }
2638
+ };
2639
+ const PRIVATE$e = Symbol('@immersive-web-emulation-runtime/xr-hand-input');
2640
+ class XRHandInput extends XRTrackedInput {
2641
+ constructor(handInputConfig, handedness, globalSpace) {
2642
+ if (handedness !== XRHandedness.Left && handedness !== XRHandedness.Right) {
2643
+ throw new DOMException('handedness for XRHandInput must be either "left" or "right"', 'InvalidStateError');
2644
+ }
2645
+ if (!handInputConfig.poses.default || !handInputConfig.poses.pinch) {
2646
+ throw new DOMException('"default" and "pinch" hand pose configs are required', 'InvalidStateError');
2647
+ }
2648
+ const targetRaySpace = new XRSpace(globalSpace);
2649
+ const gripSpace = new XRSpace(targetRaySpace);
2650
+ const profiles = [
2651
+ handInputConfig.profileId,
2652
+ ...handInputConfig.fallbackProfileIds,
2653
+ ];
2654
+ const hand = new XRHand();
2655
+ Object.values(XRHandJoint).forEach((jointName) => {
2656
+ hand.set(jointName, new XRJointSpace(jointName, targetRaySpace));
2657
+ });
2658
+ const inputSource = new XRInputSource(handedness, XRTargetRayMode.TrackedPointer, profiles, targetRaySpace, new Gamepad(XRHandGamepadConfig), gripSpace, hand);
2659
+ super(inputSource);
2660
+ this[PRIVATE$e] = {
2661
+ poseId: 'default',
2662
+ poses: handInputConfig.poses,
2663
+ };
2664
+ this.updateHandPose();
2665
+ }
2666
+ get poseId() {
2667
+ return this[PRIVATE$e].poseId;
2668
+ }
2669
+ set poseId(poseId) {
2670
+ if (!this[PRIVATE$e].poses[poseId]) {
2671
+ console.warn(`Pose config ${poseId} not found`);
2672
+ return;
2673
+ }
2674
+ this[PRIVATE$e].poseId = poseId;
2675
+ }
2676
+ updateHandPose() {
2677
+ const targetPose = this[PRIVATE$e].poses[this[PRIVATE$e].poseId];
2678
+ const pinchPose = this[PRIVATE$e].poses.pinch;
2679
+ Object.values(XRHandJoint).forEach((jointName) => {
2680
+ const targetJointMatrix = targetPose.jointTransforms[jointName].offsetMatrix;
2681
+ const pinchJointMatrix = pinchPose.jointTransforms[jointName].offsetMatrix;
2682
+ const jointSpace = this.inputSource.hand.get(jointName);
2683
+ interpolateMatrix(jointSpace[PRIVATE$k].offsetMatrix, targetJointMatrix, pinchJointMatrix, this.pinchValue);
2684
+ if (this.inputSource.handedness === XRHandedness.Right) {
2685
+ mirrorMatrixToRight(jointSpace[PRIVATE$k].offsetMatrix);
2686
+ }
2687
+ jointSpace[PRIVATE$f].radius =
2688
+ (1 - this.pinchValue) * targetPose.jointTransforms[jointName].radius +
2689
+ this.pinchValue * pinchPose.jointTransforms[jointName].radius;
2690
+ });
2691
+ if (targetPose.gripOffsetMatrix && pinchPose.gripOffsetMatrix) {
2692
+ interpolateMatrix(this.inputSource.gripSpace[PRIVATE$k].offsetMatrix, targetPose.gripOffsetMatrix, pinchPose.gripOffsetMatrix, this.pinchValue);
2693
+ }
2694
+ }
2695
+ get pinchValue() {
2696
+ return this[PRIVATE$h].inputSource.gamepad[PRIVATE$j]
2697
+ .buttonsMap['pinch'].value;
2698
+ }
2699
+ updatePinchValue(value) {
2700
+ if (value > 1 || value < 0) {
2701
+ console.warn(`Out-of-range value ${value} provided for pinch`);
2702
+ return;
2703
+ }
2704
+ const gamepadButton = this[PRIVATE$h].inputSource.gamepad[PRIVATE$j]
2705
+ .buttonsMap['pinch'];
2706
+ gamepadButton[PRIVATE$j].pendingValue = value;
2707
+ }
2708
+ onFrameStart(frame) {
2709
+ super.onFrameStart(frame);
2710
+ this.updateHandPose();
2711
+ }
2712
+ }
2713
+
2714
+ const PRIVATE$d = Symbol('@immersive-web-emulation-runtime/xr-pose');
2715
+ class XRPose {
2716
+ constructor(transform, emulatedPosition = false, linearVelocity = undefined, angularVelocity = undefined) {
2717
+ this[PRIVATE$d] = {
2718
+ transform,
2719
+ emulatedPosition,
2720
+ linearVelocity,
2721
+ angularVelocity,
2722
+ };
2723
+ }
2724
+ get transform() {
2725
+ return this[PRIVATE$d].transform;
2726
+ }
2727
+ get emulatedPosition() {
2728
+ return this[PRIVATE$d].emulatedPosition;
2729
+ }
2730
+ get linearVelocity() {
2731
+ return this[PRIVATE$d].linearVelocity;
2732
+ }
2733
+ get angularVelocity() {
2734
+ return this[PRIVATE$d].angularVelocity;
2735
+ }
2736
+ }
2737
+
2738
+ const PRIVATE$c = Symbol('@immersive-web-emulation-runtime/xr-joint-pose');
2739
+ class XRJointPose extends XRPose {
2740
+ constructor(transform, radius, emulatedPosition = false, linearVelocity = undefined, angularVelocity = undefined) {
2741
+ super(transform, emulatedPosition, linearVelocity, angularVelocity);
2742
+ this[PRIVATE$c] = { radius };
2743
+ }
2744
+ get radius() {
2745
+ return this[PRIVATE$c].radius;
2746
+ }
2747
+ }
2748
+
2749
+ class PolyfillDOMPointReadOnly {
2750
+ constructor(x = 0, y = 0, z = 0, w = 1) {
2751
+ this.x = x;
2752
+ this.y = y;
2753
+ this.z = z;
2754
+ this.w = w;
2755
+ Object.freeze(this);
2756
+ }
2757
+ static fromPoint(other) {
2758
+ return new PolyfillDOMPointReadOnly(other.x, other.y, other.z, other.w);
2759
+ }
2760
+ matrixTransform(_matrix) {
2761
+ // Implement matrix transformation logic here
2762
+ // This is a placeholder implementation
2763
+ return new PolyfillDOMPointReadOnly();
2764
+ }
2765
+ toJSON() {
2766
+ // Implement toJSON logic here
2767
+ // This is a placeholder implementation
2768
+ return { x: this.x, y: this.y, z: this.z, w: this.w };
2769
+ }
2770
+ }
2771
+ const DOMPointReadOnly = typeof globalThis.DOMPointReadOnly !== 'undefined'
2772
+ ? globalThis.DOMPointReadOnly
2773
+ : PolyfillDOMPointReadOnly;
2774
+
2775
+ const PRIVATE$b = Symbol('@immersive-web-emulation-runtime/xr-rigid-transform');
2776
+ class XRRigidTransform {
2777
+ constructor(position, orientation) {
2778
+ // Default values
2779
+ const defaultPosition = fromValues$2(0, 0, 0);
2780
+ const defaultOrientation = create();
2781
+ this[PRIVATE$b] = {
2782
+ matrix: create$3(),
2783
+ position: position
2784
+ ? fromValues$2(position.x, position.y, position.z)
2785
+ : defaultPosition,
2786
+ orientation: orientation
2787
+ ? normalize(create(), fromValues(orientation.x, orientation.y, orientation.z, orientation.w))
2788
+ : defaultOrientation,
2789
+ inverse: null,
2790
+ };
2791
+ this.updateMatrix();
2792
+ }
2793
+ updateMatrix() {
2794
+ fromRotationTranslation(this[PRIVATE$b].matrix, this[PRIVATE$b].orientation, this[PRIVATE$b].position);
2795
+ }
2796
+ get matrix() {
2797
+ return this[PRIVATE$b].matrix;
2798
+ }
2799
+ get position() {
2800
+ const pos = this[PRIVATE$b].position;
2801
+ return new DOMPointReadOnly(pos[0], pos[1], pos[2], 1);
2802
+ }
2803
+ get orientation() {
2804
+ const ori = this[PRIVATE$b].orientation;
2805
+ return new DOMPointReadOnly(ori[0], ori[1], ori[2], ori[3]);
2806
+ }
2807
+ get inverse() {
2808
+ if (!this[PRIVATE$b].inverse) {
2809
+ const invMatrix = create$3();
2810
+ if (!invert(invMatrix, this[PRIVATE$b].matrix)) {
2811
+ throw new Error('Matrix is not invertible.');
2812
+ }
2813
+ // Decomposing the inverse matrix into position and orientation
2814
+ let invPosition = create$2();
2815
+ getTranslation(invPosition, invMatrix);
2816
+ let invOrientation = create();
2817
+ getRotation(invOrientation, invMatrix);
2818
+ // Creating a new XRRigidTransform for the inverse
2819
+ this[PRIVATE$b].inverse = new XRRigidTransform(new DOMPointReadOnly(invPosition[0], invPosition[1], invPosition[2], 1), new DOMPointReadOnly(invOrientation[0], invOrientation[1], invOrientation[2], invOrientation[3]));
2820
+ // Setting the inverse of the inverse to be this transform
2821
+ this[PRIVATE$b].inverse[PRIVATE$b].inverse = this;
2822
+ }
2823
+ return this[PRIVATE$b].inverse;
2824
+ }
2825
+ }
2826
+
2827
+ const PRIVATE$a = Symbol('@immersive-web-emulation-runtime/xr-viewer-pose');
2828
+ class XRViewerPose extends XRPose {
2829
+ constructor(transform, views, emulatedPosition = false, linearVelocity = undefined, angularVelocity = undefined) {
2830
+ super(transform, emulatedPosition, linearVelocity, angularVelocity);
2831
+ this[PRIVATE$a] = {
2832
+ views: Object.freeze(views),
2833
+ };
2834
+ }
2835
+ get views() {
2836
+ return this[PRIVATE$a].views;
2837
+ }
2838
+ }
2839
+
2840
+ const PRIVATE$9 = Symbol('@immersive-web-emulation-runtime/xr-frame');
2841
+ const spaceGlobalMatrix = create$3();
2842
+ const baseSpaceGlobalMatrix = create$3();
2843
+ const baseSpaceGlobalMatrixInverse = create$3();
2844
+ const getOffsetMatrix = (offsetMatrix, space, baseSpace) => {
2845
+ XRSpaceUtils.calculateGlobalOffsetMatrix(space, spaceGlobalMatrix);
2846
+ XRSpaceUtils.calculateGlobalOffsetMatrix(baseSpace, baseSpaceGlobalMatrix);
2847
+ invert(baseSpaceGlobalMatrixInverse, baseSpaceGlobalMatrix);
2848
+ multiply$1(offsetMatrix, baseSpaceGlobalMatrixInverse, spaceGlobalMatrix);
2849
+ };
2850
+ class XRFrame {
2851
+ constructor(session, id, active, animationFrame, predictedDisplayTime) {
2852
+ this[PRIVATE$9] = {
2853
+ session,
2854
+ id,
2855
+ active,
2856
+ animationFrame,
2857
+ predictedDisplayTime,
2858
+ tempMat4: create$3(),
2859
+ };
2860
+ }
2861
+ get session() {
2862
+ return this[PRIVATE$9].session;
2863
+ }
2864
+ get predictedDisplayTime() {
2865
+ return this[PRIVATE$9].predictedDisplayTime;
2866
+ }
2867
+ getPose(space, baseSpace) {
2868
+ if (!this[PRIVATE$9].active) {
2869
+ throw new DOMException('XRFrame access outside the callback that produced it is invalid.', 'InvalidStateError');
2870
+ }
2871
+ getOffsetMatrix(this[PRIVATE$9].tempMat4, space, baseSpace);
2872
+ const position = create$2();
2873
+ getTranslation(position, this[PRIVATE$9].tempMat4);
2874
+ const orientation = create();
2875
+ getRotation(orientation, this[PRIVATE$9].tempMat4);
2876
+ return new XRPose(new XRRigidTransform({ x: position[0], y: position[1], z: position[2], w: 1.0 }, {
2877
+ x: orientation[0],
2878
+ y: orientation[1],
2879
+ z: orientation[2],
2880
+ w: orientation[3],
2881
+ }), space[PRIVATE$k].emulated);
2882
+ }
2883
+ getViewerPose(referenceSpace) {
2884
+ if (!this[PRIVATE$9].animationFrame) {
2885
+ throw new DOMException('getViewerPose can only be called on XRFrame objects passed to XRSession.requestAnimationFrame callbacks.', 'InvalidStateError');
2886
+ }
2887
+ const session = this[PRIVATE$9].session;
2888
+ const device = session[PRIVATE$6].device;
2889
+ const pose = this.getPose(device.viewerSpace, referenceSpace);
2890
+ const eyes = session[PRIVATE$6].mode === XRSessionMode.Inline
2891
+ ? [XREye.None]
2892
+ : [XREye.Left, XREye.Right];
2893
+ const views = [];
2894
+ eyes.forEach((eye) => {
2895
+ const viewSpace = device.viewSpaces[eye];
2896
+ const viewPose = this.getPose(viewSpace, referenceSpace);
2897
+ const projectionMatrix = session[PRIVATE$6].getProjectionMatrix(eye);
2898
+ const view = new XRView(eye, new Float32Array(projectionMatrix), viewPose.transform, session);
2899
+ views.push(view);
2900
+ });
2901
+ return new XRViewerPose(pose.transform, views, false);
2902
+ }
2903
+ getJointPose(joint, baseSpace) {
2904
+ const xrPose = this.getPose(joint, baseSpace);
2905
+ const radius = joint[PRIVATE$f].radius;
2906
+ return new XRJointPose(xrPose.transform, radius, false);
2907
+ }
2908
+ fillJointRadii(jointSpaces, radii) {
2909
+ // converting from sequence type to array
2910
+ jointSpaces = Array.from(jointSpaces);
2911
+ if (!this[PRIVATE$9].active) {
2912
+ throw new DOMException('XRFrame access outside the callback that produced it is invalid.', 'InvalidStateError');
2913
+ }
2914
+ if (jointSpaces.length > radii.length) {
2915
+ throw new DOMException('The length of jointSpaces is larger than the number of elements in radii', 'TypeError');
2916
+ }
2917
+ let allValid = true;
2918
+ for (let offset = 0; offset < jointSpaces.length; offset++) {
2919
+ if (!jointSpaces[offset][PRIVATE$f].radius) {
2920
+ radii[offset] = NaN;
2921
+ allValid = false;
2922
+ }
2923
+ else {
2924
+ radii[offset] = jointSpaces[offset][PRIVATE$f].radius;
2925
+ }
2926
+ }
2927
+ return allValid;
2928
+ }
2929
+ fillPoses(spaces, baseSpace, transforms) {
2930
+ // converting from sequence type to array
2931
+ spaces = Array.from(spaces);
2932
+ if (!this[PRIVATE$9].active) {
2933
+ throw new DOMException('XRFrame access outside the callback that produced it is invalid.', 'InvalidStateError');
2934
+ }
2935
+ if (spaces.length * 16 > transforms.length) {
2936
+ throw new DOMException('The length of spaces multiplied by 16 is larger than the number of elements in transforms', 'TypeError');
2937
+ }
2938
+ spaces.forEach((space, i) => {
2939
+ getOffsetMatrix(this[PRIVATE$9].tempMat4, space, baseSpace);
2940
+ for (let j = 0; j < 16; j++) {
2941
+ transforms[i * 16 + j] = this[PRIVATE$9].tempMat4[j];
2942
+ }
2943
+ });
2944
+ return true;
2945
+ }
2946
+ }
2947
+
2948
+ class XRInputSourcesChangeEvent extends Event {
2949
+ constructor(type, eventInitDict) {
2950
+ super(type, eventInitDict);
2951
+ if (!eventInitDict.session) {
2952
+ throw new Error('XRInputSourcesChangeEventInit.session is required');
2953
+ }
2954
+ if (!eventInitDict.added) {
2955
+ throw new Error('XRInputSourcesChangeEventInit.added is required');
2956
+ }
2957
+ if (!eventInitDict.removed) {
2958
+ throw new Error('XRInputSourcesChangeEventInit.removed is required');
2959
+ }
2960
+ this.session = eventInitDict.session;
2961
+ this.added = eventInitDict.added;
2962
+ this.removed = eventInitDict.removed;
2963
+ }
2964
+ }
2965
+
2966
+ var _a;
2967
+ const PRIVATE$8 = Symbol('@immersive-web-emulation-runtime/xr-reference-space');
2968
+ var XRReferenceSpaceType;
2969
+ (function (XRReferenceSpaceType) {
2970
+ XRReferenceSpaceType["Viewer"] = "viewer";
2971
+ XRReferenceSpaceType["Local"] = "local";
2972
+ XRReferenceSpaceType["LocalFloor"] = "local-floor";
2973
+ XRReferenceSpaceType["BoundedFloor"] = "bounded-floor";
2974
+ XRReferenceSpaceType["Unbounded"] = "unbounded";
2975
+ })(XRReferenceSpaceType || (XRReferenceSpaceType = {}));
2976
+ class XRReferenceSpace extends XRSpace {
2977
+ constructor(type, parentSpace, offsetMatrix) {
2978
+ super(parentSpace, offsetMatrix);
2979
+ this[_a] = {
2980
+ type: null,
2981
+ onreset: () => { },
2982
+ };
2983
+ this[PRIVATE$8].type = type;
2984
+ }
2985
+ get onreset() {
2986
+ var _b;
2987
+ return (_b = this[PRIVATE$8].onreset) !== null && _b !== void 0 ? _b : (() => { });
2988
+ }
2989
+ set onreset(callback) {
2990
+ if (this[PRIVATE$8].onreset) {
2991
+ this.removeEventListener('reset', this[PRIVATE$8].onreset);
2992
+ }
2993
+ this[PRIVATE$8].onreset = callback;
2994
+ if (callback) {
2995
+ this.addEventListener('reset', callback);
2996
+ }
2997
+ }
2998
+ // Create a new XRReferenceSpace with an offset from the current space
2999
+ getOffsetReferenceSpace(originOffset) {
3000
+ // Create a new XRReferenceSpace with the originOffset as its offsetMatrix
3001
+ // The new space's parent is set to 'this' (the current XRReferenceSpace)
3002
+ return new XRReferenceSpace(this[PRIVATE$8].type, this, originOffset);
3003
+ }
3004
+ }
3005
+ _a = PRIVATE$8;
3006
+
3007
+ const PRIVATE$7 = Symbol('@immersive-web-emulation-runtime/xr-render-state');
3008
+ class XRRenderState {
3009
+ constructor(init = {}, oldState) {
3010
+ this[PRIVATE$7] = {
3011
+ depthNear: init.depthNear || (oldState === null || oldState === void 0 ? void 0 : oldState.depthNear) || 0.1,
3012
+ depthFar: init.depthFar || (oldState === null || oldState === void 0 ? void 0 : oldState.depthFar) || 1000.0,
3013
+ inlineVerticalFieldOfView: init.inlineVerticalFieldOfView ||
3014
+ (oldState === null || oldState === void 0 ? void 0 : oldState.inlineVerticalFieldOfView) ||
3015
+ null,
3016
+ baseLayer: init.baseLayer || (oldState === null || oldState === void 0 ? void 0 : oldState.baseLayer) || null,
3017
+ };
3018
+ }
3019
+ get depthNear() {
3020
+ return this[PRIVATE$7].depthNear;
3021
+ }
3022
+ get depthFar() {
3023
+ return this[PRIVATE$7].depthFar;
3024
+ }
3025
+ get inlineVerticalFieldOfView() {
3026
+ return this[PRIVATE$7].inlineVerticalFieldOfView;
3027
+ }
3028
+ get baseLayer() {
3029
+ return this[PRIVATE$7].baseLayer;
3030
+ }
3031
+ }
3032
+
3033
+ class XRSessionEvent extends Event {
3034
+ constructor(type, eventInitDict) {
3035
+ super(type, eventInitDict);
3036
+ if (!eventInitDict.session) {
3037
+ throw new Error('XRSessionEventInit.session is required');
3038
+ }
3039
+ this.session = eventInitDict.session;
3040
+ }
3041
+ }
3042
+
3043
+ var XRVisibilityState;
3044
+ (function (XRVisibilityState) {
3045
+ XRVisibilityState["Visible"] = "visible";
3046
+ XRVisibilityState["VisibleBlurred"] = "visible-blurred";
3047
+ XRVisibilityState["Hidden"] = "hidden";
3048
+ })(XRVisibilityState || (XRVisibilityState = {}));
3049
+ var XRSessionMode;
3050
+ (function (XRSessionMode) {
3051
+ XRSessionMode["Inline"] = "inline";
3052
+ XRSessionMode["ImmersiveVR"] = "immersive-vr";
3053
+ XRSessionMode["ImmersiveAR"] = "immersive-ar";
3054
+ })(XRSessionMode || (XRSessionMode = {}));
3055
+ const PRIVATE$6 = Symbol('@immersive-web-emulation-runtime/xr-session');
3056
+ class XRSession extends EventTarget {
3057
+ constructor(device, mode, enabledFeatures) {
3058
+ super();
3059
+ this[PRIVATE$6] = {
3060
+ device,
3061
+ mode,
3062
+ renderState: new XRRenderState(),
3063
+ pendingRenderState: null,
3064
+ enabledFeatures: enabledFeatures,
3065
+ isSystemKeyboardSupported: false,
3066
+ ended: false,
3067
+ projectionMatrices: {
3068
+ [XREye.Left]: create$3(),
3069
+ [XREye.Right]: create$3(),
3070
+ [XREye.None]: create$3(),
3071
+ },
3072
+ getProjectionMatrix: (eye) => {
3073
+ return this[PRIVATE$6].projectionMatrices[eye];
3074
+ },
3075
+ referenceSpaceIsSupported: (referenceSpaceType) => {
3076
+ if (!this[PRIVATE$6].enabledFeatures.includes(referenceSpaceType)) {
3077
+ return false;
3078
+ }
3079
+ switch (referenceSpaceType) {
3080
+ case XRReferenceSpaceType.Viewer:
3081
+ return true;
3082
+ case XRReferenceSpaceType.Local:
3083
+ case XRReferenceSpaceType.LocalFloor:
3084
+ case XRReferenceSpaceType.BoundedFloor:
3085
+ case XRReferenceSpaceType.Unbounded:
3086
+ return this[PRIVATE$6].mode != XRSessionMode.Inline;
3087
+ }
3088
+ },
3089
+ frameHandle: 0,
3090
+ frameCallbacks: [],
3091
+ currentFrameCallbacks: null,
3092
+ onDeviceFrame: () => {
3093
+ if (this[PRIVATE$6].ended) {
3094
+ return;
3095
+ }
3096
+ this[PRIVATE$6].deviceFrameHandle = globalThis.requestAnimationFrame(this[PRIVATE$6].onDeviceFrame);
3097
+ if (this[PRIVATE$6].pendingRenderState != null) {
3098
+ this[PRIVATE$6].renderState = this[PRIVATE$6].pendingRenderState;
3099
+ this[PRIVATE$6].pendingRenderState = null;
3100
+ this[PRIVATE$6].device[PRIVATE$1].onBaseLayerSet(this[PRIVATE$6].renderState.baseLayer);
3101
+ }
3102
+ const baseLayer = this[PRIVATE$6].renderState.baseLayer;
3103
+ if (baseLayer === null) {
3104
+ return;
3105
+ }
3106
+ const context = baseLayer.context;
3107
+ const canvas = context.canvas;
3108
+ /**
3109
+ * This code snippet is designed to clear the buffers attached to an opaque framebuffer
3110
+ * at the beginning of each XR animation frame, but it only applies to immersive XR sessions.
3111
+ * The process is as follows:
3112
+ *
3113
+ * 1. Check if the session is immersive: It verifies if `session.immersive` is true.
3114
+ * This ensures that the buffer clearing operations are only performed for immersive
3115
+ * sessions, which have exclusive access to the XR device's display.
3116
+ *
3117
+ * 2. Save current clear values: The current clear values for the color, depth, and
3118
+ * stencil buffers are stored. These values need to be restored after clearing the
3119
+ * buffers to maintain the application's rendering state as expected.
3120
+ *
3121
+ * 3. Set clear values to defaults: The clear color is set to transparent black, the
3122
+ * clear depth to the maximum depth value (1.0), and the clear stencil to 0. This
3123
+ * ensures that the buffers are reset to a known state, free from any residual data.
3124
+ *
3125
+ * 4. Clear the buffers: The depth, color, and stencil buffers are cleared, removing
3126
+ * any content from previous frames and preparing them for new rendering operations.
3127
+ *
3128
+ * 5. Restore previous clear values: The original clear values are reinstated to return
3129
+ * the WebGL context to its state prior to this operation, allowing subsequent rendering
3130
+ * to proceed without interference.
3131
+ *
3132
+ * This clearing process is crucial for some XR devices to function correctly and to
3133
+ * prevent rendering artifacts from past frames. It ensures that each new frame starts
3134
+ * with a clean slate.
3135
+ */
3136
+ if (this[PRIVATE$6].mode != XRSessionMode.Inline) {
3137
+ const currentClearColor = context.getParameter(context.COLOR_CLEAR_VALUE);
3138
+ const currentClearDepth = context.getParameter(context.DEPTH_CLEAR_VALUE);
3139
+ const currentClearStencil = context.getParameter(context.STENCIL_CLEAR_VALUE);
3140
+ context.clearColor(0.0, 0.0, 0.0, 0.0);
3141
+ context.clearDepth(1);
3142
+ context.clearStencil(0.0);
3143
+ context.clear(context.DEPTH_BUFFER_BIT |
3144
+ context.COLOR_BUFFER_BIT |
3145
+ context.STENCIL_BUFFER_BIT);
3146
+ context.clearColor(currentClearColor[0], currentClearColor[1], currentClearColor[2], currentClearColor[3]);
3147
+ context.clearDepth(currentClearDepth);
3148
+ context.clearStencil(currentClearStencil);
3149
+ }
3150
+ // Calculate projection matrices
3151
+ const { depthNear, depthFar } = this[PRIVATE$6].renderState;
3152
+ const { width, height } = canvas;
3153
+ if (this[PRIVATE$6].mode !== XRSessionMode.Inline) {
3154
+ const aspect = (width * (this[PRIVATE$6].device.stereoEnabled ? 0.5 : 1.0)) / height;
3155
+ perspective(this[PRIVATE$6].projectionMatrices[XREye.Left], this[PRIVATE$6].device.fovy, aspect, depthNear, depthFar);
3156
+ copy$3(this[PRIVATE$6].projectionMatrices[XREye.Right], this[PRIVATE$6].projectionMatrices[XREye.Left]);
3157
+ }
3158
+ else {
3159
+ const aspect = width / height;
3160
+ perspective(this[PRIVATE$6].projectionMatrices[XREye.None], this[PRIVATE$6].renderState.inlineVerticalFieldOfView, aspect, depthNear, depthFar);
3161
+ }
3162
+ const frame = new XRFrame(this, this[PRIVATE$6].frameHandle, true, true, performance.now());
3163
+ this[PRIVATE$6].device[PRIVATE$1].onFrameStart(frame);
3164
+ this[PRIVATE$6].updateActiveInputSources();
3165
+ /*
3166
+ * For each entry in callbacks, in order:
3167
+ * - If the entry’s cancelled boolean is true, continue to the next entry.
3168
+ * - Invoke the Web IDL callback function, passing now and frame as the arguments.
3169
+ * - If an exception is thrown, report the exception.
3170
+ */
3171
+ // - Let callbacks be a list of the entries in session’s list of animation frame
3172
+ // callback, in the order in which they were added to the list.
3173
+ const callbacks = (this[PRIVATE$6].currentFrameCallbacks =
3174
+ this[PRIVATE$6].frameCallbacks);
3175
+ // - Set session’s list of animation frame callbacks to the empty list.
3176
+ this[PRIVATE$6].frameCallbacks = [];
3177
+ const rightNow = performance.now();
3178
+ for (let i = 0; i < callbacks.length; i++) {
3179
+ try {
3180
+ if (!callbacks[i].cancelled) {
3181
+ callbacks[i].callback(rightNow, frame);
3182
+ }
3183
+ }
3184
+ catch (err) {
3185
+ console.error(err);
3186
+ }
3187
+ }
3188
+ this[PRIVATE$6].currentFrameCallbacks = null;
3189
+ // - Set frame’s active boolean to false.
3190
+ frame[PRIVATE$9].active = false;
3191
+ },
3192
+ nominalFrameRate: device.internalNominalFrameRate,
3193
+ referenceSpaces: [],
3194
+ inputSourceArray: [],
3195
+ activeInputSources: [],
3196
+ updateActiveInputSources: () => {
3197
+ const handTrackingOn = this[PRIVATE$6].enabledFeatures.includes(WebXRFeatures.HandTracking);
3198
+ const prevInputs = this[PRIVATE$6].activeInputSources;
3199
+ const currInputs = this[PRIVATE$6].device.inputSources.filter((inputSource) => !inputSource.hand || handTrackingOn);
3200
+ const added = currInputs.filter((item) => !prevInputs.includes(item));
3201
+ const removed = prevInputs.filter((item) => !currInputs.includes(item));
3202
+ if (added.length > 0 || removed.length > 0) {
3203
+ this.dispatchEvent(new XRInputSourcesChangeEvent('inputsourceschange', {
3204
+ session: this,
3205
+ added,
3206
+ removed,
3207
+ }));
3208
+ }
3209
+ this[PRIVATE$6].activeInputSources = currInputs;
3210
+ },
3211
+ onend: null,
3212
+ oninputsourceschange: null,
3213
+ onselect: null,
3214
+ onselectstart: null,
3215
+ onselectend: null,
3216
+ onsqueeze: null,
3217
+ onsqueezestart: null,
3218
+ onsqueezeend: null,
3219
+ onvisibilitychange: null,
3220
+ onframeratechange: null,
3221
+ };
3222
+ // start the frameloop
3223
+ this[PRIVATE$6].onDeviceFrame();
3224
+ }
3225
+ get visibilityState() {
3226
+ return this[PRIVATE$6].device.visibilityState;
3227
+ }
3228
+ get frameRate() {
3229
+ return this[PRIVATE$6].nominalFrameRate;
3230
+ }
3231
+ get supportedFrameRates() {
3232
+ return new Float32Array(this[PRIVATE$6].device.supportedFrameRates);
3233
+ }
3234
+ get renderState() {
3235
+ return this[PRIVATE$6].renderState;
3236
+ }
3237
+ get inputSources() {
3238
+ // use the same array object
3239
+ this[PRIVATE$6].inputSourceArray.length = 0;
3240
+ if (!this[PRIVATE$6].ended && this[PRIVATE$6].mode !== XRSessionMode.Inline) {
3241
+ this[PRIVATE$6].inputSourceArray.push(...this[PRIVATE$6].activeInputSources);
3242
+ }
3243
+ return this[PRIVATE$6].inputSourceArray;
3244
+ }
3245
+ get enabledFeatures() {
3246
+ return this[PRIVATE$6].enabledFeatures;
3247
+ }
3248
+ get isSystemKeyboardSupported() {
3249
+ return this[PRIVATE$6].isSystemKeyboardSupported;
3250
+ }
3251
+ updateRenderState(state = {}) {
3252
+ if (this[PRIVATE$6].ended) {
3253
+ throw new DOMException('XRSession has already ended.', 'InvalidStateError');
3254
+ }
3255
+ if (state.baseLayer &&
3256
+ state.baseLayer[PRIVATE$5].session !== this) {
3257
+ throw new DOMException('Base layer was created by a different XRSession', 'InvalidStateError');
3258
+ }
3259
+ if (state.inlineVerticalFieldOfView != null &&
3260
+ this[PRIVATE$6].mode !== XRSessionMode.Inline) {
3261
+ throw new DOMException('InlineVerticalFieldOfView must not be set for an immersive session', 'InvalidStateError');
3262
+ }
3263
+ this[PRIVATE$6].pendingRenderState = new XRRenderState(state, this[PRIVATE$6].renderState);
3264
+ }
3265
+ // the nominal frame rate updates are emulated, no actual update to the
3266
+ // display frame rate of the device will be executed
3267
+ async updateTargetFrameRate(rate) {
3268
+ return new Promise((resolve, reject) => {
3269
+ if (this[PRIVATE$6].ended) {
3270
+ reject(new DOMException('XRSession has already ended.', 'InvalidStateError'));
3271
+ }
3272
+ else if (!this[PRIVATE$6].device.supportedFrameRates.includes(rate)) {
3273
+ reject(new DOMException('Requested frame rate not supported.', 'InvalidStateError'));
3274
+ }
3275
+ else {
3276
+ if (this[PRIVATE$6].nominalFrameRate === rate) {
3277
+ console.log(`Requested frame rate is the same as the current nominal frame rate, no update made`);
3278
+ }
3279
+ else {
3280
+ this[PRIVATE$6].nominalFrameRate = rate;
3281
+ this.dispatchEvent(new XRSessionEvent('frameratechange', { session: this }));
3282
+ console.log(`Nominal frame rate updated to ${rate}`);
3283
+ }
3284
+ resolve();
3285
+ }
3286
+ });
3287
+ }
3288
+ async requestReferenceSpace(type) {
3289
+ return new Promise((resolve, reject) => {
3290
+ if (this[PRIVATE$6].ended ||
3291
+ !this[PRIVATE$6].referenceSpaceIsSupported(type)) {
3292
+ reject(new DOMException('The requested reference space type is not supported.', 'NotSupportedError'));
3293
+ return;
3294
+ }
3295
+ let referenceSpace;
3296
+ switch (type) {
3297
+ case XRReferenceSpaceType.Viewer:
3298
+ referenceSpace = this[PRIVATE$6].device.viewerSpace;
3299
+ break;
3300
+ case XRReferenceSpaceType.Local:
3301
+ // creating an XRReferenceSpace with the current headset transform in global space
3302
+ referenceSpace = new XRReferenceSpace(type, this[PRIVATE$6].device[PRIVATE$1].globalSpace, this[PRIVATE$6].device.viewerSpace[PRIVATE$k].offsetMatrix);
3303
+ break;
3304
+ case XRReferenceSpaceType.LocalFloor:
3305
+ case XRReferenceSpaceType.BoundedFloor:
3306
+ case XRReferenceSpaceType.Unbounded:
3307
+ // TO-DO: add boundary geometry for bounded-floor
3308
+ referenceSpace = new XRReferenceSpace(type, this[PRIVATE$6].device[PRIVATE$1].globalSpace);
3309
+ break;
3310
+ }
3311
+ this[PRIVATE$6].referenceSpaces.push(referenceSpace);
3312
+ resolve(referenceSpace);
3313
+ });
3314
+ }
3315
+ requestAnimationFrame(callback) {
3316
+ if (this[PRIVATE$6].ended) {
3317
+ return 0;
3318
+ }
3319
+ const frameHandle = ++this[PRIVATE$6].frameHandle;
3320
+ this[PRIVATE$6].frameCallbacks.push({
3321
+ handle: frameHandle,
3322
+ callback,
3323
+ cancelled: false,
3324
+ });
3325
+ return frameHandle;
3326
+ }
3327
+ cancelAnimationFrame(handle) {
3328
+ // Remove the callback with that handle from the queue
3329
+ let callbacks = this[PRIVATE$6].frameCallbacks;
3330
+ let index = callbacks.findIndex((d) => d && d.handle === handle);
3331
+ if (index > -1) {
3332
+ callbacks[index].cancelled = true;
3333
+ callbacks.splice(index, 1);
3334
+ }
3335
+ // If cancelAnimationFrame is called from within a frame callback, also check
3336
+ // the remaining callbacks for the current frame:
3337
+ callbacks = this[PRIVATE$6].currentFrameCallbacks;
3338
+ if (callbacks) {
3339
+ index = callbacks.findIndex((d) => d && d.handle === handle);
3340
+ if (index > -1) {
3341
+ callbacks[index].cancelled = true;
3342
+ // Rely on cancelled flag only; don't mutate this array while it's being iterated
3343
+ }
3344
+ }
3345
+ }
3346
+ async end() {
3347
+ return new Promise((resolve, reject) => {
3348
+ if (this[PRIVATE$6].ended || this[PRIVATE$6].deviceFrameHandle === null) {
3349
+ reject(new DOMException('XRSession has already ended.', 'InvalidStateError'));
3350
+ }
3351
+ else {
3352
+ globalThis.cancelAnimationFrame(this[PRIVATE$6].deviceFrameHandle);
3353
+ this[PRIVATE$6].device[PRIVATE$1].onSessionEnd();
3354
+ this.dispatchEvent(new XRSessionEvent('end', { session: this }));
3355
+ resolve();
3356
+ }
3357
+ });
3358
+ }
3359
+ // events
3360
+ get onend() {
3361
+ var _a;
3362
+ return (_a = this[PRIVATE$6].onend) !== null && _a !== void 0 ? _a : (() => { });
3363
+ }
3364
+ set onend(callback) {
3365
+ if (this[PRIVATE$6].onend) {
3366
+ this.removeEventListener('end', this[PRIVATE$6].onend);
3367
+ }
3368
+ this[PRIVATE$6].onend = callback;
3369
+ if (callback) {
3370
+ this.addEventListener('end', callback);
3371
+ }
3372
+ }
3373
+ get oninputsourceschange() {
3374
+ var _a;
3375
+ return (_a = this[PRIVATE$6].oninputsourceschange) !== null && _a !== void 0 ? _a : (() => { });
3376
+ }
3377
+ set oninputsourceschange(callback) {
3378
+ if (this[PRIVATE$6].oninputsourceschange) {
3379
+ this.removeEventListener('inputsourceschange', this[PRIVATE$6].oninputsourceschange);
3380
+ }
3381
+ this[PRIVATE$6].oninputsourceschange = callback;
3382
+ if (callback) {
3383
+ this.addEventListener('inputsourceschange', callback);
3384
+ }
3385
+ }
3386
+ get onselect() {
3387
+ var _a;
3388
+ return (_a = this[PRIVATE$6].onselect) !== null && _a !== void 0 ? _a : (() => { });
3389
+ }
3390
+ set onselect(callback) {
3391
+ if (this[PRIVATE$6].onselect) {
3392
+ this.removeEventListener('select', this[PRIVATE$6].onselect);
3393
+ }
3394
+ this[PRIVATE$6].onselect = callback;
3395
+ if (callback) {
3396
+ this.addEventListener('select', callback);
3397
+ }
3398
+ }
3399
+ get onselectstart() {
3400
+ var _a;
3401
+ return (_a = this[PRIVATE$6].onselectstart) !== null && _a !== void 0 ? _a : (() => { });
3402
+ }
3403
+ set onselectstart(callback) {
3404
+ if (this[PRIVATE$6].onselectstart) {
3405
+ this.removeEventListener('selectstart', this[PRIVATE$6].onselectstart);
3406
+ }
3407
+ this[PRIVATE$6].onselectstart = callback;
3408
+ if (callback) {
3409
+ this.addEventListener('selectstart', callback);
3410
+ }
3411
+ }
3412
+ get onselectend() {
3413
+ var _a;
3414
+ return (_a = this[PRIVATE$6].onselectend) !== null && _a !== void 0 ? _a : (() => { });
3415
+ }
3416
+ set onselectend(callback) {
3417
+ if (this[PRIVATE$6].onselectend) {
3418
+ this.removeEventListener('selectend', this[PRIVATE$6].onselectend);
3419
+ }
3420
+ this[PRIVATE$6].onselectend = callback;
3421
+ if (callback) {
3422
+ this.addEventListener('selectend', callback);
3423
+ }
3424
+ }
3425
+ get onsqueeze() {
3426
+ var _a;
3427
+ return (_a = this[PRIVATE$6].onsqueeze) !== null && _a !== void 0 ? _a : (() => { });
3428
+ }
3429
+ set onsqueeze(callback) {
3430
+ if (this[PRIVATE$6].onsqueeze) {
3431
+ this.removeEventListener('squeeze', this[PRIVATE$6].onsqueeze);
3432
+ }
3433
+ this[PRIVATE$6].onsqueeze = callback;
3434
+ if (callback) {
3435
+ this.addEventListener('squeeze', callback);
3436
+ }
3437
+ }
3438
+ get onsqueezestart() {
3439
+ var _a;
3440
+ return (_a = this[PRIVATE$6].onsqueezestart) !== null && _a !== void 0 ? _a : (() => { });
3441
+ }
3442
+ set onsqueezestart(callback) {
3443
+ if (this[PRIVATE$6].onsqueezestart) {
3444
+ this.removeEventListener('squeezestart', this[PRIVATE$6].onsqueezestart);
3445
+ }
3446
+ this[PRIVATE$6].onsqueezestart = callback;
3447
+ if (callback) {
3448
+ this.addEventListener('squeezestart', callback);
3449
+ }
3450
+ }
3451
+ get onsqueezeend() {
3452
+ var _a;
3453
+ return (_a = this[PRIVATE$6].onsqueezeend) !== null && _a !== void 0 ? _a : (() => { });
3454
+ }
3455
+ set onsqueezeend(callback) {
3456
+ if (this[PRIVATE$6].onsqueezeend) {
3457
+ this.removeEventListener('squeezeend', this[PRIVATE$6].onsqueezeend);
3458
+ }
3459
+ this[PRIVATE$6].onsqueezeend = callback;
3460
+ if (callback) {
3461
+ this.addEventListener('squeezeend', callback);
3462
+ }
3463
+ }
3464
+ get onvisibilitychange() {
3465
+ var _a;
3466
+ return (_a = this[PRIVATE$6].onvisibilitychange) !== null && _a !== void 0 ? _a : (() => { });
3467
+ }
3468
+ set onvisibilitychange(callback) {
3469
+ if (this[PRIVATE$6].onvisibilitychange) {
3470
+ this.removeEventListener('visibilitychange', this[PRIVATE$6].onvisibilitychange);
3471
+ }
3472
+ this[PRIVATE$6].onvisibilitychange = callback;
3473
+ if (callback) {
3474
+ this.addEventListener('visibilitychange', callback);
3475
+ }
3476
+ }
3477
+ get onframeratechange() {
3478
+ var _a;
3479
+ return (_a = this[PRIVATE$6].onframeratechange) !== null && _a !== void 0 ? _a : (() => { });
3480
+ }
3481
+ set onframeratechange(callback) {
3482
+ if (this[PRIVATE$6].onframeratechange) {
3483
+ this.removeEventListener('frameratechange', this[PRIVATE$6].onframeratechange);
3484
+ }
3485
+ this[PRIVATE$6].onframeratechange = callback;
3486
+ if (callback) {
3487
+ this.addEventListener('frameratechange', callback);
3488
+ }
3489
+ }
3490
+ }
3491
+
3492
+ class XRLayer extends EventTarget {
3493
+ }
3494
+ const PRIVATE$5 = Symbol('@immersive-web-emulation-runtime/XRWebGLLayer');
3495
+ const defaultLayerInit = {
3496
+ antialias: true,
3497
+ depth: true,
3498
+ stencil: false,
3499
+ alpha: true,
3500
+ ignoreDepthValues: false,
3501
+ framebufferScaleFactor: 1.0,
3502
+ };
3503
+ class XRWebGLLayer extends XRLayer {
3504
+ constructor(session, context, layerInit = {}) {
3505
+ super();
3506
+ if (session[PRIVATE$6].ended) {
3507
+ throw new DOMException('Session has ended', 'InvalidStateError');
3508
+ }
3509
+ // TO-DO: Check that the context attribute has xrCompatible set to true
3510
+ // may require polyfilling the context and perhaps canvas.getContext
3511
+ // Default values for XRWebGLLayerInit, can be overridden by layerInit
3512
+ const config = { ...defaultLayerInit, ...layerInit };
3513
+ this[PRIVATE$5] = {
3514
+ session,
3515
+ context,
3516
+ antialias: config.antialias,
3517
+ };
3518
+ }
3519
+ get context() {
3520
+ return this[PRIVATE$5].context;
3521
+ }
3522
+ get antialias() {
3523
+ return this[PRIVATE$5].antialias;
3524
+ }
3525
+ get ignoreDepthValues() {
3526
+ return true;
3527
+ }
3528
+ get framebuffer() {
3529
+ return null;
3530
+ }
3531
+ get framebufferWidth() {
3532
+ return this[PRIVATE$5].context.drawingBufferWidth;
3533
+ }
3534
+ get framebufferHeight() {
3535
+ return this[PRIVATE$5].context.drawingBufferHeight;
3536
+ }
3537
+ getViewport(view) {
3538
+ if (view[PRIVATE$g].session !== this[PRIVATE$5].session) {
3539
+ throw new DOMException("View's session differs from Layer's session", 'InvalidStateError');
3540
+ }
3541
+ // TO-DO: check frame
3542
+ return this[PRIVATE$5].session[PRIVATE$6].device[PRIVATE$1].getViewport(this, view);
3543
+ }
3544
+ static getNativeFramebufferScaleFactor(session) {
3545
+ if (!(session instanceof XRSession)) {
3546
+ throw new TypeError('getNativeFramebufferScaleFactor must be passed a session.');
3547
+ }
3548
+ if (session[PRIVATE$6].ended) {
3549
+ return 0.0;
3550
+ }
3551
+ // Return 1.0 for simplicity, actual implementation might vary based on the device capabilities
3552
+ return 1.0;
3553
+ }
3554
+ }
3555
+
3556
+ const PRIVATE$4 = Symbol('@immersive-web-emulation-runtime/action-player');
3557
+ class ActionPlayer {
3558
+ constructor(refSpace, recording, ipd) {
3559
+ const { schema, frames } = recording;
3560
+ if (!frames || !schema || frames.length === 0) {
3561
+ throw new DOMException('wrong recording format', 'NotSupportedError');
3562
+ }
3563
+ const viewerSpace = new XRReferenceSpace(XRReferenceSpaceType.Viewer, refSpace);
3564
+ const viewSpaces = {
3565
+ [XREye.Left]: new XRSpace(viewerSpace),
3566
+ [XREye.Right]: new XRSpace(viewerSpace),
3567
+ [XREye.None]: new XRSpace(viewerSpace),
3568
+ };
3569
+ this[PRIVATE$4] = {
3570
+ refSpace,
3571
+ inputSources: new Map(),
3572
+ inputSchemas: new Map(),
3573
+ frames,
3574
+ recordedFramePointer: 0,
3575
+ startingTimeStamp: frames[0][0],
3576
+ endingTimeStamp: frames[frames.length - 1][0],
3577
+ playbackTime: frames[0][0],
3578
+ playing: false,
3579
+ viewerSpace,
3580
+ viewSpaces,
3581
+ vec3: create$2(),
3582
+ quat: create(),
3583
+ };
3584
+ fromTranslation(this[PRIVATE$4].viewSpaces[XREye.Left][PRIVATE$k].offsetMatrix, fromValues$2(-ipd / 2, 0, 0));
3585
+ fromTranslation(this[PRIVATE$4].viewSpaces[XREye.Right][PRIVATE$k].offsetMatrix, fromValues$2(ipd / 2, 0, 0));
3586
+ schema.forEach((schemaEntry) => {
3587
+ const index = schemaEntry[0];
3588
+ const schema = schemaEntry[1];
3589
+ let gamepad;
3590
+ if (schema.hasGamepad) {
3591
+ const buttons = [];
3592
+ for (let i = 0; i < schema.numButtons; i++) {
3593
+ buttons.push({ id: i.toString(), type: 'manual' });
3594
+ }
3595
+ const axes = [];
3596
+ for (let i = 0; i < schema.numAxes; i++) {
3597
+ axes.push({ id: i.toString(), type: 'manual' });
3598
+ }
3599
+ gamepad = new Gamepad({
3600
+ mapping: schema.mapping,
3601
+ buttons,
3602
+ axes,
3603
+ });
3604
+ }
3605
+ const targetRaySpace = new XRSpace(refSpace);
3606
+ let hand = undefined;
3607
+ if (schema.hasHand) {
3608
+ hand = new XRHand();
3609
+ Object.values(XRHandJoint).forEach((jointName) => {
3610
+ hand.set(jointName, new XRJointSpace(jointName, targetRaySpace));
3611
+ });
3612
+ }
3613
+ const inputSource = new XRInputSource(schema.handedness, schema.targetRayMode, schema.profiles, targetRaySpace, gamepad, schema.hasGrip ? new XRSpace(refSpace) : undefined, schema.hasHand ? hand : undefined);
3614
+ this[PRIVATE$4].inputSources.set(index, {
3615
+ active: false,
3616
+ source: inputSource,
3617
+ });
3618
+ this[PRIVATE$4].inputSchemas.set(index, schema);
3619
+ });
3620
+ }
3621
+ play() {
3622
+ this[PRIVATE$4].recordedFramePointer = 0;
3623
+ this[PRIVATE$4].playbackTime = this[PRIVATE$4].startingTimeStamp;
3624
+ this[PRIVATE$4].playing = true;
3625
+ this[PRIVATE$4].actualTimeStamp = performance.now();
3626
+ }
3627
+ stop() {
3628
+ this[PRIVATE$4].playing = false;
3629
+ }
3630
+ get playing() {
3631
+ return this[PRIVATE$4].playing;
3632
+ }
3633
+ get viewerSpace() {
3634
+ return this[PRIVATE$4].viewerSpace;
3635
+ }
3636
+ get viewSpaces() {
3637
+ return this[PRIVATE$4].viewSpaces;
3638
+ }
3639
+ get inputSources() {
3640
+ return Array.from(this[PRIVATE$4].inputSources.values())
3641
+ .filter((wrapper) => wrapper.active)
3642
+ .map((wrapper) => wrapper.source);
3643
+ }
3644
+ playFrame() {
3645
+ const now = performance.now();
3646
+ const delta = now - this[PRIVATE$4].actualTimeStamp;
3647
+ this[PRIVATE$4].actualTimeStamp = now;
3648
+ this[PRIVATE$4].playbackTime += delta;
3649
+ if (this[PRIVATE$4].playbackTime > this[PRIVATE$4].endingTimeStamp) {
3650
+ this.stop();
3651
+ return;
3652
+ }
3653
+ while (this[PRIVATE$4].frames[this[PRIVATE$4].recordedFramePointer + 1][0] < this[PRIVATE$4].playbackTime) {
3654
+ this[PRIVATE$4].recordedFramePointer++;
3655
+ }
3656
+ const lastFrameData = this[PRIVATE$4].frames[this[PRIVATE$4].recordedFramePointer];
3657
+ const nextFrameData = this[PRIVATE$4].frames[this[PRIVATE$4].recordedFramePointer + 1];
3658
+ const alpha = (this[PRIVATE$4].playbackTime - lastFrameData[0]) /
3659
+ (nextFrameData[0] - lastFrameData[0]);
3660
+ this.updateXRSpaceFromMergedFrames(this[PRIVATE$4].viewerSpace, lastFrameData.slice(1, 8), nextFrameData.slice(1, 8), alpha);
3661
+ const lastFrameInputs = new Map();
3662
+ for (let i = 8; i < lastFrameData.length; i++) {
3663
+ const { index, inputData } = this.processRawInputData(lastFrameData[i]);
3664
+ lastFrameInputs.set(index, inputData);
3665
+ }
3666
+ const nextFrameInputs = new Map();
3667
+ for (let i = 8; i < nextFrameData.length; i++) {
3668
+ const { index, inputData } = this.processRawInputData(nextFrameData[i]);
3669
+ nextFrameInputs.set(index, inputData);
3670
+ }
3671
+ this[PRIVATE$4].inputSources.forEach((sourceWrapper) => {
3672
+ sourceWrapper.active = false;
3673
+ });
3674
+ nextFrameInputs.forEach((inputData, index) => {
3675
+ this[PRIVATE$4].inputSources.get(index).active = true;
3676
+ const inputSource = this[PRIVATE$4].inputSources.get(index).source;
3677
+ const schema = this[PRIVATE$4].inputSchemas.get(index);
3678
+ this.updateInputSource(inputSource, schema, lastFrameInputs.has(index) ? lastFrameInputs.get(index) : inputData, inputData, alpha);
3679
+ });
3680
+ }
3681
+ updateInputSource(inputSource, schema, lastInputData, nextInputData, alpha) {
3682
+ this.updateXRSpaceFromMergedFrames(inputSource.targetRaySpace, lastInputData.targetRayTransform, nextInputData.targetRayTransform, alpha);
3683
+ if (schema.hasGrip) {
3684
+ this.updateXRSpaceFromMergedFrames(inputSource.gripSpace, lastInputData.gripTransform, nextInputData.gripTransform, alpha);
3685
+ }
3686
+ if (schema.hasHand) {
3687
+ for (let i = 0; i < 25; i++) {
3688
+ const lastTransformArray = lastInputData.handTransforms.slice(i * 8, i * 8 + 7);
3689
+ const nextTransformArray = nextInputData.handTransforms.slice(i * 8, i * 8 + 7);
3690
+ const lastRadius = lastInputData.handTransforms[i * 8 + 7];
3691
+ const nextRadius = nextInputData.handTransforms[i * 8 + 7];
3692
+ const jointSpace = inputSource.hand.get(schema.jointSequence[i]);
3693
+ this.updateXRSpaceFromMergedFrames(jointSpace, lastTransformArray, nextTransformArray, alpha);
3694
+ jointSpace[PRIVATE$f].radius =
3695
+ (nextRadius - lastRadius) * alpha + lastRadius;
3696
+ }
3697
+ }
3698
+ if (schema.hasGamepad) {
3699
+ const gamepad = inputSource.gamepad;
3700
+ nextInputData.buttons.forEach((states, index) => {
3701
+ const gamepadButton = gamepad.buttons[index];
3702
+ gamepadButton[PRIVATE$j].pressed = states[0] === 1 ? true : false;
3703
+ gamepadButton[PRIVATE$j].touched = states[1] === 1 ? true : false;
3704
+ const lastValue = lastInputData.buttons[index][2];
3705
+ const nextValue = states[2];
3706
+ gamepadButton[PRIVATE$j].value =
3707
+ (nextValue - lastValue) * alpha + lastValue;
3708
+ });
3709
+ nextInputData.axes.forEach((nextValue, index) => {
3710
+ const lastValue = lastInputData.axes[index];
3711
+ gamepad[PRIVATE$j].axesMap[index.toString()].x =
3712
+ (nextValue - lastValue) * alpha + lastValue;
3713
+ });
3714
+ }
3715
+ }
3716
+ updateXRSpaceFromMergedFrames(space, lastTransform, nextTransform, alpha) {
3717
+ const f1p = fromValues$2(lastTransform[0], lastTransform[1], lastTransform[2]);
3718
+ const f1q = fromValues(lastTransform[3], lastTransform[4], lastTransform[5], lastTransform[6]);
3719
+ const f2p = fromValues$2(nextTransform[0], nextTransform[1], nextTransform[2]);
3720
+ const f2q = fromValues(nextTransform[3], nextTransform[4], nextTransform[5], nextTransform[6]);
3721
+ lerp(this[PRIVATE$4].vec3, f1p, f2p, alpha);
3722
+ slerp(this[PRIVATE$4].quat, f1q, f2q, alpha);
3723
+ fromRotationTranslation(space[PRIVATE$k].offsetMatrix, this[PRIVATE$4].quat, this[PRIVATE$4].vec3);
3724
+ }
3725
+ processRawInputData(inputDataRaw) {
3726
+ const index = inputDataRaw[0];
3727
+ const schema = this[PRIVATE$4].inputSchemas.get(index);
3728
+ const targetRayTransform = inputDataRaw.slice(1, 8);
3729
+ const inputData = { targetRayTransform };
3730
+ let dataCounter = 8;
3731
+ if (schema.hasGrip) {
3732
+ inputData.gripTransform = inputDataRaw[dataCounter++];
3733
+ }
3734
+ if (schema.hasHand) {
3735
+ inputData.handTransforms = inputDataRaw[dataCounter++];
3736
+ }
3737
+ if (schema.hasGamepad) {
3738
+ const gamepadData = inputDataRaw[dataCounter];
3739
+ inputData.buttons = gamepadData.slice(0, schema.numButtons);
3740
+ inputData.axes = gamepadData.slice(schema.numButtons);
3741
+ }
3742
+ return { index, inputData };
3743
+ }
3744
+ }
3745
+
3746
+ const VERSION = "0.0.1";
3747
+
3748
+ class XRReferenceSpaceEvent extends Event {
3749
+ constructor(type, eventInitDict) {
3750
+ super(type, eventInitDict);
3751
+ if (!eventInitDict.referenceSpace) {
3752
+ throw new Error('XRReferenceSpaceEventInit.referenceSpace is required');
3753
+ }
3754
+ this.referenceSpace = eventInitDict.referenceSpace;
3755
+ this.transform = eventInitDict.transform;
3756
+ }
3757
+ }
3758
+
3759
+ const PRIVATE$3 = Symbol('@immersive-web-emulation-runtime/xr-system');
3760
+ class XRSystem extends EventTarget {
3761
+ constructor(device) {
3762
+ super();
3763
+ this[PRIVATE$3] = { device };
3764
+ // Initialize device change monitoring here if applicable
3765
+ }
3766
+ isSessionSupported(mode) {
3767
+ return new Promise((resolve, _reject) => {
3768
+ if (mode === XRSessionMode.Inline) {
3769
+ resolve(true);
3770
+ }
3771
+ else {
3772
+ // Check for spatial tracking permission if necessary
3773
+ resolve(this[PRIVATE$3].device.supportedSessionModes.includes(mode));
3774
+ }
3775
+ });
3776
+ }
3777
+ requestSession(mode, options = {}) {
3778
+ return new Promise((resolve, reject) => {
3779
+ this.isSessionSupported(mode)
3780
+ .then((isSupported) => {
3781
+ if (!isSupported) {
3782
+ reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
3783
+ return;
3784
+ }
3785
+ // Check for active sessions and other constraints here
3786
+ if (this[PRIVATE$3].activeSession) {
3787
+ reject(new DOMException('An active XRSession already exists.', 'InvalidStateError'));
3788
+ return;
3789
+ }
3790
+ // Handle required and optional features
3791
+ const { requiredFeatures = [], optionalFeatures = [] } = options;
3792
+ const { supportedFeatures } = this[PRIVATE$3].device;
3793
+ // Check if all required features are supported
3794
+ const allRequiredSupported = requiredFeatures.every((feature) => supportedFeatures.includes(feature));
3795
+ if (!allRequiredSupported) {
3796
+ reject(new Error('One or more required features are not supported by the device.'));
3797
+ return;
3798
+ }
3799
+ // Filter out unsupported optional features
3800
+ const supportedOptionalFeatures = optionalFeatures.filter((feature) => supportedFeatures.includes(feature));
3801
+ // Combine required and supported optional features into enabled features
3802
+ const enabledFeatures = Array.from(new Set([
3803
+ ...requiredFeatures,
3804
+ ...supportedOptionalFeatures,
3805
+ WebXRFeatures.Viewer,
3806
+ WebXRFeatures.Local,
3807
+ ]));
3808
+ // Proceed with session creation
3809
+ const session = new XRSession(this[PRIVATE$3].device, mode, enabledFeatures);
3810
+ this[PRIVATE$3].activeSession = session;
3811
+ // Listen for session end to clear the active session
3812
+ session.addEventListener('end', () => {
3813
+ this[PRIVATE$3].activeSession = undefined;
3814
+ });
3815
+ resolve(session);
3816
+ })
3817
+ .catch(reject);
3818
+ });
3819
+ }
3820
+ }
3821
+
3822
+ const PRIVATE$2 = Symbol('@immersive-web-emulation-runtime/xr-viewport');
3823
+ class XRViewport {
3824
+ constructor(x, y, width, height) {
3825
+ this[PRIVATE$2] = { x, y, width, height };
3826
+ }
3827
+ get x() {
3828
+ return this[PRIVATE$2].x;
3829
+ }
3830
+ get y() {
3831
+ return this[PRIVATE$2].y;
3832
+ }
3833
+ get width() {
3834
+ return this[PRIVATE$2].width;
3835
+ }
3836
+ get height() {
3837
+ return this[PRIVATE$2].height;
3838
+ }
3839
+ }
3840
+
3841
+ var WebXRFeatures;
3842
+ (function (WebXRFeatures) {
3843
+ WebXRFeatures["Viewer"] = "viewer";
3844
+ WebXRFeatures["Local"] = "local";
3845
+ WebXRFeatures["LocalFloor"] = "local-floor";
3846
+ WebXRFeatures["BoundedFloor"] = "bounded-floor";
3847
+ WebXRFeatures["Unbounded"] = "unbounded";
3848
+ WebXRFeatures["DomOverlay"] = "dom-overlay";
3849
+ WebXRFeatures["Anchors"] = "anchors";
3850
+ WebXRFeatures["PlaneDetection"] = "plane-detection";
3851
+ WebXRFeatures["MeshDetection"] = "mesh-detection";
3852
+ WebXRFeatures["HitTest"] = "hit-test";
3853
+ WebXRFeatures["HandTracking"] = "hand-tracking";
3854
+ WebXRFeatures["DepthSensing"] = "depth-sensing";
3855
+ })(WebXRFeatures || (WebXRFeatures = {}));
3856
+ const PRIVATE$1 = Symbol('@immersive-web-emulation-runtime/xr-device');
3857
+ const DEFAULTS = {
3858
+ ipd: 0.063,
3859
+ fovy: Math.PI / 2,
3860
+ headsetPosition: new Vector3(0, 1.6, 0),
3861
+ headsetQuaternion: new Quaternion(),
3862
+ stereoEnabled: false,
3863
+ };
3864
+ /**
3865
+ * XRDevice is not a standard API class outlined in the WebXR Device API Specifications
3866
+ * Instead, it serves as an user-facing interface to control the emulated XR Device
3867
+ */
3868
+ class XRDevice {
3869
+ constructor(deviceConfig, deviceOptions = {}) {
3870
+ var _a, _b, _c, _d, _e, _f;
3871
+ const globalSpace = new GlobalSpace();
3872
+ const viewerSpace = new XRReferenceSpace(XRReferenceSpaceType.Viewer, globalSpace);
3873
+ const viewSpaces = {
3874
+ [XREye.Left]: new XRSpace(viewerSpace),
3875
+ [XREye.Right]: new XRSpace(viewerSpace),
3876
+ [XREye.None]: new XRSpace(viewerSpace),
3877
+ };
3878
+ const controllerConfig = deviceConfig.controllerConfig;
3879
+ const controllers = {};
3880
+ if (controllerConfig) {
3881
+ Object.values(XRHandedness).forEach((handedness) => {
3882
+ if (controllerConfig.layout[handedness]) {
3883
+ controllers[handedness] = new XRController(controllerConfig, handedness, globalSpace);
3884
+ }
3885
+ });
3886
+ }
3887
+ const hands = {
3888
+ [XRHandedness.Left]: new XRHandInput(oculusHandConfig, XRHandedness.Left, globalSpace),
3889
+ [XRHandedness.Right]: new XRHandInput(oculusHandConfig, XRHandedness.Right, globalSpace),
3890
+ };
3891
+ const canvasContainer = (_a = deviceOptions.canvasContainer) !== null && _a !== void 0 ? _a : document.createElement('div');
3892
+ canvasContainer.dataset.webxr_runtime = `Immersive Web Emulation Runtime v${VERSION}`;
3893
+ canvasContainer.style.position = 'fixed';
3894
+ canvasContainer.style.width = '100%';
3895
+ canvasContainer.style.height = '100%';
3896
+ canvasContainer.style.top = '0';
3897
+ canvasContainer.style.left = '0';
3898
+ canvasContainer.style.display = 'flex';
3899
+ canvasContainer.style.justifyContent = 'center';
3900
+ canvasContainer.style.alignItems = 'center';
3901
+ canvasContainer.style.overflow = 'hidden';
3902
+ canvasContainer.style.zIndex = '999';
3903
+ this[PRIVATE$1] = {
3904
+ name: deviceConfig.name,
3905
+ supportedSessionModes: deviceConfig.supportedSessionModes,
3906
+ supportedFeatures: deviceConfig.supportedFeatures,
3907
+ supportedFrameRates: deviceConfig.supportedFrameRates,
3908
+ isSystemKeyboardSupported: deviceConfig.isSystemKeyboardSupported,
3909
+ internalNominalFrameRate: deviceConfig.internalNominalFrameRate,
3910
+ position: (_b = deviceOptions.headsetPosition) !== null && _b !== void 0 ? _b : DEFAULTS.headsetPosition.clone(),
3911
+ quaternion: (_c = deviceOptions.headsetQuaternion) !== null && _c !== void 0 ? _c : DEFAULTS.headsetQuaternion.clone(),
3912
+ stereoEnabled: (_d = deviceOptions.stereoEnabled) !== null && _d !== void 0 ? _d : DEFAULTS.stereoEnabled,
3913
+ ipd: (_e = deviceOptions.ipd) !== null && _e !== void 0 ? _e : DEFAULTS.ipd,
3914
+ fovy: (_f = deviceOptions.fovy) !== null && _f !== void 0 ? _f : DEFAULTS.fovy,
3915
+ controllers,
3916
+ hands,
3917
+ primaryInputMode: 'controller',
3918
+ pendingReferenceSpaceReset: false,
3919
+ visibilityState: XRVisibilityState.Visible,
3920
+ pendingVisibilityState: null,
3921
+ matrix: create$3(),
3922
+ globalSpace,
3923
+ viewerSpace,
3924
+ viewSpaces,
3925
+ canvasContainer,
3926
+ getViewport: (layer, view) => {
3927
+ const canvas = layer.context.canvas;
3928
+ const { width, height } = canvas;
3929
+ switch (view.eye) {
3930
+ case XREye.None:
3931
+ return new XRViewport(0, 0, width, height);
3932
+ case XREye.Left:
3933
+ return new XRViewport(0, 0, this[PRIVATE$1].stereoEnabled ? width / 2 : width, height);
3934
+ case XREye.Right:
3935
+ return new XRViewport(width / 2, 0, this[PRIVATE$1].stereoEnabled ? width / 2 : 0, height);
3936
+ }
3937
+ },
3938
+ updateViews: () => {
3939
+ // update viewerSpace
3940
+ const viewerSpace = this[PRIVATE$1].viewerSpace;
3941
+ fromRotationTranslation(viewerSpace[PRIVATE$k].offsetMatrix, this[PRIVATE$1].quaternion.quat, this[PRIVATE$1].position.vec3);
3942
+ // update viewSpaces
3943
+ fromTranslation(this[PRIVATE$1].viewSpaces[XREye.Left][PRIVATE$k].offsetMatrix, fromValues$2(-this[PRIVATE$1].ipd / 2, 0, 0));
3944
+ fromTranslation(this[PRIVATE$1].viewSpaces[XREye.Right][PRIVATE$k].offsetMatrix, fromValues$2(this[PRIVATE$1].ipd / 2, 0, 0));
3945
+ },
3946
+ onBaseLayerSet: (baseLayer) => {
3947
+ if (!baseLayer)
3948
+ return;
3949
+ // backup canvas data
3950
+ const canvas = baseLayer.context.canvas;
3951
+ if (canvas.parentElement !== this[PRIVATE$1].canvasContainer) {
3952
+ this[PRIVATE$1].canvasData = {
3953
+ canvas,
3954
+ parent: canvas.parentElement,
3955
+ width: canvas.width,
3956
+ height: canvas.height,
3957
+ };
3958
+ this[PRIVATE$1].canvasContainer.appendChild(canvas);
3959
+ document.body.appendChild(this[PRIVATE$1].canvasContainer);
3960
+ }
3961
+ canvas.width = window.innerWidth;
3962
+ canvas.height = window.innerHeight;
3963
+ },
3964
+ onSessionEnd: () => {
3965
+ if (this[PRIVATE$1].canvasData) {
3966
+ const { canvas, parent, width, height } = this[PRIVATE$1].canvasData;
3967
+ canvas.width = width;
3968
+ canvas.height = height;
3969
+ if (parent) {
3970
+ parent.appendChild(canvas);
3971
+ }
3972
+ else {
3973
+ this[PRIVATE$1].canvasContainer.removeChild(canvas);
3974
+ }
3975
+ document.body.removeChild(this[PRIVATE$1].canvasContainer);
3976
+ window.dispatchEvent(new Event('resize'));
3977
+ }
3978
+ },
3979
+ onFrameStart: (frame) => {
3980
+ var _a;
3981
+ if ((_a = this[PRIVATE$1].actionPlayer) === null || _a === void 0 ? void 0 : _a.playing) {
3982
+ this[PRIVATE$1].actionPlayer.playFrame();
3983
+ }
3984
+ else {
3985
+ const session = frame.session;
3986
+ this[PRIVATE$1].updateViews();
3987
+ if (this[PRIVATE$1].pendingVisibilityState) {
3988
+ this[PRIVATE$1].visibilityState =
3989
+ this[PRIVATE$1].pendingVisibilityState;
3990
+ this[PRIVATE$1].pendingVisibilityState = null;
3991
+ session.dispatchEvent(new XRSessionEvent('visibilitychange', { session }));
3992
+ }
3993
+ if (this[PRIVATE$1].visibilityState === XRVisibilityState.Visible) {
3994
+ this.activeInputs.forEach((activeInput) => {
3995
+ activeInput.onFrameStart(frame);
3996
+ });
3997
+ }
3998
+ if (this[PRIVATE$1].pendingReferenceSpaceReset) {
3999
+ session[PRIVATE$6].referenceSpaces.forEach((referenceSpace) => {
4000
+ switch (referenceSpace[PRIVATE$8].type) {
4001
+ case XRReferenceSpaceType.Local:
4002
+ case XRReferenceSpaceType.LocalFloor:
4003
+ case XRReferenceSpaceType.BoundedFloor:
4004
+ case XRReferenceSpaceType.Unbounded:
4005
+ referenceSpace.dispatchEvent(new XRReferenceSpaceEvent('reset', { referenceSpace }));
4006
+ break;
4007
+ }
4008
+ });
4009
+ this[PRIVATE$1].pendingReferenceSpaceReset = false;
4010
+ }
4011
+ }
4012
+ this[PRIVATE$1].updateViews();
4013
+ },
4014
+ };
4015
+ this[PRIVATE$1].updateViews();
4016
+ }
4017
+ installRuntime(globalObject = globalThis) {
4018
+ Object.defineProperty(WebGL2RenderingContext.prototype, 'makeXRCompatible', {
4019
+ value: function () {
4020
+ return new Promise((resolve, _reject) => {
4021
+ resolve(true);
4022
+ });
4023
+ },
4024
+ configurable: true,
4025
+ });
4026
+ Object.defineProperty(globalThis.navigator, 'xr', {
4027
+ value: new XRSystem(this),
4028
+ configurable: true,
4029
+ });
4030
+ globalObject['XRSystem'] = XRSystem;
4031
+ globalObject['XRSession'] = XRSession;
4032
+ globalObject['XRRenderState'] = XRRenderState;
4033
+ globalObject['XRFrame'] = XRFrame;
4034
+ globalObject['XRSpace'] = XRSpace;
4035
+ globalObject['XRReferenceSpace'] = XRReferenceSpace;
4036
+ globalObject['XRJointSpace'] = XRJointSpace;
4037
+ globalObject['XRView'] = XRView;
4038
+ globalObject['XRViewport'] = XRViewport;
4039
+ globalObject['XRRigidTransform'] = XRRigidTransform;
4040
+ globalObject['XRPose'] = XRPose;
4041
+ globalObject['XRViewerPose'] = XRViewerPose;
4042
+ globalObject['XRJointPose'] = XRJointPose;
4043
+ globalObject['XRInputSource'] = XRInputSource;
4044
+ globalObject['XRInputSourceArray'] = XRInputSourceArray;
4045
+ globalObject['XRHand'] = XRHand;
4046
+ globalObject['XRLayer'] = XRLayer;
4047
+ globalObject['XRWebGLLayer'] = XRWebGLLayer;
4048
+ globalObject['XRSessionEvent'] = XRSessionEvent;
4049
+ globalObject['XRInputSourceEvent'] = XRInputSourceEvent;
4050
+ globalObject['XRInputSourcesChangeEvent'] = XRInputSourcesChangeEvent;
4051
+ globalObject['XRReferenceSpaceEvent'] = XRReferenceSpaceEvent;
4052
+ }
4053
+ get supportedSessionModes() {
4054
+ return this[PRIVATE$1].supportedSessionModes;
4055
+ }
4056
+ get supportedFeatures() {
4057
+ return this[PRIVATE$1].supportedFeatures;
4058
+ }
4059
+ get supportedFrameRates() {
4060
+ return this[PRIVATE$1].supportedFrameRates;
4061
+ }
4062
+ get isSystemKeyboardSupported() {
4063
+ return this[PRIVATE$1].isSystemKeyboardSupported;
4064
+ }
4065
+ get internalNominalFrameRate() {
4066
+ return this[PRIVATE$1].internalNominalFrameRate;
4067
+ }
4068
+ get stereoEnabled() {
4069
+ return this[PRIVATE$1].stereoEnabled;
4070
+ }
4071
+ set stereoEnabled(value) {
4072
+ this[PRIVATE$1].stereoEnabled = value;
4073
+ }
4074
+ get ipd() {
4075
+ return this[PRIVATE$1].ipd;
4076
+ }
4077
+ set ipd(value) {
4078
+ this[PRIVATE$1].ipd = value;
4079
+ }
4080
+ get fovy() {
4081
+ return this[PRIVATE$1].fovy;
4082
+ }
4083
+ set fovy(value) {
4084
+ this[PRIVATE$1].fovy = value;
4085
+ }
4086
+ get position() {
4087
+ return this[PRIVATE$1].position;
4088
+ }
4089
+ get quaternion() {
4090
+ return this[PRIVATE$1].quaternion;
4091
+ }
4092
+ get viewerSpace() {
4093
+ var _a;
4094
+ if ((_a = this[PRIVATE$1].actionPlayer) === null || _a === void 0 ? void 0 : _a.playing) {
4095
+ return this[PRIVATE$1].actionPlayer.viewerSpace;
4096
+ }
4097
+ else {
4098
+ return this[PRIVATE$1].viewerSpace;
4099
+ }
4100
+ }
4101
+ get viewSpaces() {
4102
+ var _a;
4103
+ if ((_a = this[PRIVATE$1].actionPlayer) === null || _a === void 0 ? void 0 : _a.playing) {
4104
+ return this[PRIVATE$1].actionPlayer.viewSpaces;
4105
+ }
4106
+ else {
4107
+ return this[PRIVATE$1].viewSpaces;
4108
+ }
4109
+ }
4110
+ get controllers() {
4111
+ return this[PRIVATE$1].controllers;
4112
+ }
4113
+ get hands() {
4114
+ return this[PRIVATE$1].hands;
4115
+ }
4116
+ get primaryInputMode() {
4117
+ return this[PRIVATE$1].primaryInputMode;
4118
+ }
4119
+ set primaryInputMode(mode) {
4120
+ if (mode !== 'controller' && mode !== 'hand') {
4121
+ console.warn('primary input mode can only be "controller" or "hand"');
4122
+ return;
4123
+ }
4124
+ this[PRIVATE$1].primaryInputMode = mode;
4125
+ }
4126
+ get activeInputs() {
4127
+ if (this[PRIVATE$1].visibilityState !== XRVisibilityState.Visible) {
4128
+ return [];
4129
+ }
4130
+ const activeInputs = this[PRIVATE$1].primaryInputMode === 'controller'
4131
+ ? Object.values(this[PRIVATE$1].controllers)
4132
+ : Object.values(this[PRIVATE$1].hands);
4133
+ return activeInputs.filter((input) => input.connected);
4134
+ }
4135
+ get inputSources() {
4136
+ var _a;
4137
+ if ((_a = this[PRIVATE$1].actionPlayer) === null || _a === void 0 ? void 0 : _a.playing) {
4138
+ return this[PRIVATE$1].actionPlayer.inputSources;
4139
+ }
4140
+ else {
4141
+ return this.activeInputs.map((input) => input.inputSource);
4142
+ }
4143
+ }
4144
+ get canvasContainer() {
4145
+ return this[PRIVATE$1].canvasContainer;
4146
+ }
4147
+ recenter() {
4148
+ const deltaVec = new Vector3(-this.position.x, 0, -this.position.z);
4149
+ const forward = new Vector3(0, 0, -1).applyQuaternion(this.quaternion);
4150
+ forward.y = 0;
4151
+ forward.normalize();
4152
+ const angle = Math.atan2(forward.x, -forward.z);
4153
+ const deltaQuat = new Quaternion().setFromAxisAngle(new Vector3(0, 1, 0), angle);
4154
+ this.position.add(deltaVec);
4155
+ this.quaternion.multiply(deltaQuat);
4156
+ [
4157
+ ...Object.values(this[PRIVATE$1].controllers),
4158
+ ...Object.values(this[PRIVATE$1].hands),
4159
+ ].forEach((activeInput) => {
4160
+ activeInput.position.add(deltaVec);
4161
+ activeInput.quaternion.multiply(deltaQuat);
4162
+ activeInput.position.applyQuaternion(deltaQuat);
4163
+ });
4164
+ this[PRIVATE$1].pendingReferenceSpaceReset = true;
4165
+ }
4166
+ get visibilityState() {
4167
+ return this[PRIVATE$1].visibilityState;
4168
+ }
4169
+ // visibility state updates are queued until the XRSession produces frames
4170
+ updateVisibilityState(state) {
4171
+ if (!Object.values(XRVisibilityState).includes(state)) {
4172
+ throw new DOMException('Invalid XRVisibilityState value', 'NotSupportedError');
4173
+ }
4174
+ if (state !== this[PRIVATE$1].visibilityState) {
4175
+ this[PRIVATE$1].pendingVisibilityState = state;
4176
+ }
4177
+ }
4178
+ createActionPlayer(refSpace, recording) {
4179
+ this[PRIVATE$1].actionPlayer = new ActionPlayer(refSpace, recording, this[PRIVATE$1].ipd);
4180
+ return this[PRIVATE$1].actionPlayer;
4181
+ }
4182
+ }
4183
+
4184
+ // value pulled from https://felixtrz.github.io/webxr-device-config/
4185
+ const gamepadConfigLeft = {
4186
+ mapping: GamepadMappingType.XRStandard,
4187
+ buttons: [
4188
+ { id: 'trigger', type: 'analog', eventTrigger: 'select' },
4189
+ { id: 'squeeze', type: 'analog', eventTrigger: 'squeeze' },
4190
+ null,
4191
+ { id: 'thumbstick', type: 'binary' },
4192
+ { id: 'x-button', type: 'binary' },
4193
+ { id: 'y-button', type: 'binary' },
4194
+ { id: 'thumbrest', type: 'binary' },
4195
+ ],
4196
+ axes: [
4197
+ null,
4198
+ null,
4199
+ { id: 'thumbstick', type: 'x-axis' },
4200
+ { id: 'thumbstick', type: 'y-axis' },
4201
+ ],
4202
+ };
4203
+ const gamepadConfigRight = {
4204
+ mapping: GamepadMappingType.XRStandard,
4205
+ buttons: [
4206
+ { id: 'trigger', type: 'analog', eventTrigger: 'select' },
4207
+ { id: 'squeeze', type: 'analog', eventTrigger: 'squeeze' },
4208
+ null,
4209
+ { id: 'thumbstick', type: 'binary' },
4210
+ { id: 'a-button', type: 'binary' },
4211
+ { id: 'b-button', type: 'binary' },
4212
+ { id: 'thumbrest', type: 'binary' },
4213
+ ],
4214
+ axes: [
4215
+ null,
4216
+ null,
4217
+ { id: 'thumbstick', type: 'x-axis' },
4218
+ { id: 'thumbstick', type: 'y-axis' },
4219
+ ],
4220
+ };
4221
+ const oculusTouchV2 = {
4222
+ profileId: 'oculus-touch-v2',
4223
+ fallbackProfileIds: ['oculus-touch', 'generic-trigger-squeeze-thumbstick'],
4224
+ layout: {
4225
+ left: {
4226
+ gamepad: gamepadConfigLeft,
4227
+ gripOffsetMatrix: [
4228
+ 0.9925461411476135, 4.673031295254759e-9, -0.12186938524246216, 0,
4229
+ 0.08617470413446426, 0.7071065306663513, 0.7018362283706665, 0,
4230
+ 0.0861746296286583, -0.70710688829422, 0.7018358707427979, 0,
4231
+ -0.003979847766458988, -0.01585787907242775, 0.04964185878634453, 1,
4232
+ ],
4233
+ numHapticActuators: 1,
4234
+ },
4235
+ right: {
4236
+ gamepad: gamepadConfigRight,
4237
+ gripOffsetMatrix: [
4238
+ 0.9925461411476135, 3.688163374704345e-8, 0.12186937034130096, 0,
4239
+ -0.08617469668388367, 0.7071066498756409, 0.7018361687660217, 0,
4240
+ -0.0861746147274971, -0.7071068286895752, 0.7018359899520874, 0,
4241
+ 0.003979853354394436, -0.01585787907242775, 0.04964182525873184, 1,
4242
+ ],
4243
+ numHapticActuators: 1,
4244
+ },
4245
+ },
4246
+ };
4247
+ const oculusTouchV3 = {
4248
+ profileId: 'oculus-touch-v3',
4249
+ fallbackProfileIds: ['oculus-touch', 'generic-trigger-squeeze-thumbstick'],
4250
+ layout: {
4251
+ left: {
4252
+ gamepad: gamepadConfigLeft,
4253
+ gripOffsetMatrix: [
4254
+ 0.9925461411476135, 2.0823669899527886e-8, -0.12186937034130096, 0,
4255
+ 0.08617465198040009, 0.7071067094802856, 0.701836109161377, 0,
4256
+ 0.08617466688156128, -0.7071067690849304, 0.7018360495567322, 0,
4257
+ -0.003979838453233242, -0.015857907012104988, 0.04964181408286095, 1,
4258
+ ],
4259
+ numHapticActuators: 1,
4260
+ },
4261
+ right: {
4262
+ gamepad: gamepadConfigRight,
4263
+ gripOffsetMatrix: [
4264
+ 0.9925461411476135, -8.329467959811154e-8, 0.12186941504478455, 0,
4265
+ -0.08617465943098068, 0.7071066498756409, 0.7018361687660217, 0,
4266
+ -0.08617471158504486, -0.7071068286895752, 0.7018359303474426, 0,
4267
+ 0.003979798872023821, -0.015857888385653496, 0.049641866236925125, 1,
4268
+ ],
4269
+ numHapticActuators: 1,
4270
+ },
4271
+ },
4272
+ };
4273
+ const metaQuestTouchPro = {
4274
+ profileId: 'meta-quest-touch-pro',
4275
+ fallbackProfileIds: [
4276
+ 'oculus-touch-v2',
4277
+ 'oculus-touch',
4278
+ 'generic-trigger-squeeze-thumbstick',
4279
+ ],
4280
+ layout: {
4281
+ left: {
4282
+ gamepad: gamepadConfigLeft,
4283
+ gripOffsetMatrix: [
4284
+ 0.9925461411476135, -1.5779937356796836e-8, -0.12186935544013977, 0,
4285
+ 0.08617467433214188, 0.7071067094802856, 0.701836109161377, 0,
4286
+ 0.0861746296286583, -0.7071067690849304, 0.7018360495567322, 0,
4287
+ -0.003979836590588093, -0.015857847407460213, 0.049641840159893036, 1,
4288
+ ],
4289
+ numHapticActuators: 3,
4290
+ },
4291
+ right: {
4292
+ gamepad: gamepadConfigRight,
4293
+ gripOffsetMatrix: [
4294
+ 0.9925461411476135, 9.267653311439972e-11, 0.12186937034130096, 0,
4295
+ -0.08617467433214188, 0.7071067094802856, 0.7018361687660217, 0,
4296
+ -0.08617464452981949, -0.7071067690849304, 0.7018360495567322, 0,
4297
+ 0.003979847766458988, -0.01585782691836357, 0.04964186251163483, 1,
4298
+ ],
4299
+ numHapticActuators: 3,
4300
+ },
4301
+ },
4302
+ };
4303
+ const metaQuestTouchPlus = {
4304
+ profileId: 'meta-quest-touch-plus',
4305
+ fallbackProfileIds: [
4306
+ 'oculus-touch-v3',
4307
+ 'oculus-touch',
4308
+ 'generic-trigger-squeeze-thumbstick',
4309
+ ],
4310
+ layout: {
4311
+ left: {
4312
+ gamepad: gamepadConfigLeft,
4313
+ gripOffsetMatrix: [
4314
+ 0.9925461411476135, 1.0736208366779465e-8, -0.12186933308839798, 0,
4315
+ 0.08617459982633591, 0.70710688829422, 0.7018360495567322, 0,
4316
+ 0.08617466688156128, -0.7071067094802856, 0.7018362283706665, 0,
4317
+ -0.003979803062975407, -0.015857873484492302, 0.04964187368750572, 1,
4318
+ ],
4319
+ numHapticActuators: 1,
4320
+ },
4321
+ right: {
4322
+ gamepad: gamepadConfigRight,
4323
+ gripOffsetMatrix: [
4324
+ 0.9925461411476135, -2.6238110351073374e-8, 0.12186934053897858, 0,
4325
+ -0.0861746147274971, 0.7071067690849304, 0.7018360495567322, 0,
4326
+ -0.08617465943098068, -0.7071067094802856, 0.701836109161377, 0,
4327
+ 0.003979838453233242, -0.015857869759202003, 0.04964182525873184, 1,
4328
+ ],
4329
+ numHapticActuators: 1,
4330
+ },
4331
+ },
4332
+ };
4333
+
4334
+ const oculusQuest1 = {
4335
+ name: 'Oculus Quest 1',
4336
+ controllerConfig: oculusTouchV2,
4337
+ supportedSessionModes: [
4338
+ XRSessionMode.Inline,
4339
+ XRSessionMode.ImmersiveVR,
4340
+ XRSessionMode.ImmersiveAR,
4341
+ ],
4342
+ supportedFeatures: [
4343
+ WebXRFeatures.Viewer,
4344
+ WebXRFeatures.Local,
4345
+ WebXRFeatures.LocalFloor,
4346
+ WebXRFeatures.BoundedFloor,
4347
+ WebXRFeatures.Unbounded,
4348
+ WebXRFeatures.Anchors,
4349
+ WebXRFeatures.PlaneDetection,
4350
+ WebXRFeatures.HandTracking,
4351
+ ],
4352
+ supportedFrameRates: [72, 80, 90],
4353
+ isSystemKeyboardSupported: true,
4354
+ internalNominalFrameRate: 72,
4355
+ };
4356
+ const metaQuest2 = {
4357
+ name: 'Meta Quest 2',
4358
+ controllerConfig: oculusTouchV3,
4359
+ supportedSessionModes: [
4360
+ XRSessionMode.Inline,
4361
+ XRSessionMode.ImmersiveVR,
4362
+ XRSessionMode.ImmersiveAR,
4363
+ ],
4364
+ supportedFeatures: [
4365
+ WebXRFeatures.Viewer,
4366
+ WebXRFeatures.Local,
4367
+ WebXRFeatures.LocalFloor,
4368
+ WebXRFeatures.BoundedFloor,
4369
+ WebXRFeatures.Unbounded,
4370
+ WebXRFeatures.Anchors,
4371
+ WebXRFeatures.PlaneDetection,
4372
+ WebXRFeatures.MeshDetection,
4373
+ WebXRFeatures.HitTest,
4374
+ WebXRFeatures.HandTracking,
4375
+ ],
4376
+ supportedFrameRates: [72, 80, 90, 120],
4377
+ isSystemKeyboardSupported: true,
4378
+ internalNominalFrameRate: 72,
4379
+ };
4380
+ const metaQuestPro = {
4381
+ name: 'Meta Quest Pro',
4382
+ controllerConfig: metaQuestTouchPro,
4383
+ supportedSessionModes: [
4384
+ XRSessionMode.Inline,
4385
+ XRSessionMode.ImmersiveVR,
4386
+ XRSessionMode.ImmersiveAR,
4387
+ ],
4388
+ supportedFeatures: [
4389
+ WebXRFeatures.Viewer,
4390
+ WebXRFeatures.Local,
4391
+ WebXRFeatures.LocalFloor,
4392
+ WebXRFeatures.BoundedFloor,
4393
+ WebXRFeatures.Unbounded,
4394
+ WebXRFeatures.Anchors,
4395
+ WebXRFeatures.PlaneDetection,
4396
+ WebXRFeatures.MeshDetection,
4397
+ WebXRFeatures.HitTest,
4398
+ WebXRFeatures.HandTracking,
4399
+ ],
4400
+ supportedFrameRates: [72, 80, 90, 120],
4401
+ isSystemKeyboardSupported: true,
4402
+ internalNominalFrameRate: 90,
4403
+ };
4404
+ const metaQuest3 = {
4405
+ name: 'Meta Quest 3',
4406
+ controllerConfig: metaQuestTouchPlus,
4407
+ supportedSessionModes: [
4408
+ XRSessionMode.Inline,
4409
+ XRSessionMode.ImmersiveVR,
4410
+ XRSessionMode.ImmersiveAR,
4411
+ ],
4412
+ supportedFeatures: [
4413
+ WebXRFeatures.Viewer,
4414
+ WebXRFeatures.Local,
4415
+ WebXRFeatures.LocalFloor,
4416
+ WebXRFeatures.BoundedFloor,
4417
+ WebXRFeatures.Unbounded,
4418
+ WebXRFeatures.Anchors,
4419
+ WebXRFeatures.PlaneDetection,
4420
+ WebXRFeatures.MeshDetection,
4421
+ WebXRFeatures.HitTest,
4422
+ WebXRFeatures.HandTracking,
4423
+ WebXRFeatures.DepthSensing,
4424
+ ],
4425
+ supportedFrameRates: [72, 80, 90, 120],
4426
+ isSystemKeyboardSupported: true,
4427
+ internalNominalFrameRate: 90,
4428
+ };
4429
+
4430
+ const PRIVATE = Symbol('@immersive-web-emulation-runtime/action-recorder');
4431
+ const compress = (arr) => {
4432
+ const out = [];
4433
+ arr.forEach((num) => {
4434
+ out.push(parseFloat(num.toFixed(3)));
4435
+ });
4436
+ return out;
4437
+ };
4438
+ class ActionRecorder {
4439
+ constructor(session, refSpace) {
4440
+ this[PRIVATE] = {
4441
+ session,
4442
+ refSpace,
4443
+ inputMap: new Map(),
4444
+ schemaMap: new Map(),
4445
+ compressedFrames: [],
4446
+ jointRadii: new Float32Array(25),
4447
+ jointTransforms: new Float32Array(25 * 16),
4448
+ };
4449
+ }
4450
+ recordFrame(frame) {
4451
+ var _a;
4452
+ const timeStamp = performance.now();
4453
+ const viewerMatrix = (_a = frame.getViewerPose(this[PRIVATE].refSpace)) === null || _a === void 0 ? void 0 : _a.transform.matrix;
4454
+ if (!viewerMatrix)
4455
+ return;
4456
+ const position = getTranslation(create$2(), viewerMatrix);
4457
+ const quaternion = getRotation(create(), viewerMatrix);
4458
+ const actionFrame = {
4459
+ timeStamp,
4460
+ position,
4461
+ quaternion,
4462
+ inputFrames: [],
4463
+ };
4464
+ this[PRIVATE].session.inputSources.forEach((inputSource) => {
4465
+ var _a, _b;
4466
+ if (!this[PRIVATE].inputMap.has(inputSource)) {
4467
+ const schema = {
4468
+ handedness: inputSource.handedness,
4469
+ targetRayMode: inputSource.targetRayMode,
4470
+ profiles: inputSource.profiles,
4471
+ hasGrip: inputSource.gripSpace != null,
4472
+ hasHand: inputSource.hand != null,
4473
+ hasGamepad: inputSource.gamepad != null,
4474
+ };
4475
+ if (schema.hasHand) {
4476
+ schema.jointSequence = Array.from(inputSource.hand.values()).map((jointSpace) => jointSpace.jointName);
4477
+ }
4478
+ if (schema.hasGamepad) {
4479
+ schema.mapping = inputSource.gamepad.mapping;
4480
+ schema.numButtons = inputSource.gamepad.buttons.length;
4481
+ schema.numAxes = inputSource.gamepad.axes.length;
4482
+ }
4483
+ const index = this[PRIVATE].inputMap.size;
4484
+ this[PRIVATE].inputMap.set(inputSource, index);
4485
+ this[PRIVATE].schemaMap.set(index, schema);
4486
+ }
4487
+ const index = this[PRIVATE].inputMap.get(inputSource);
4488
+ const schema = this[PRIVATE].schemaMap.get(index);
4489
+ const targetRayMatrix = (_a = frame.getPose(inputSource.targetRaySpace, this[PRIVATE].refSpace)) === null || _a === void 0 ? void 0 : _a.transform.matrix;
4490
+ if (targetRayMatrix) {
4491
+ const targetRayPosition = getTranslation(create$2(), targetRayMatrix);
4492
+ const targetRayQuaternion = getRotation(create(), targetRayMatrix);
4493
+ const inputFrame = {
4494
+ index,
4495
+ targetRayTransform: {
4496
+ position: targetRayPosition,
4497
+ quaternion: targetRayQuaternion,
4498
+ },
4499
+ };
4500
+ if (schema.hasGrip) {
4501
+ const gripMatrix = (_b = frame.getPose(inputSource.gripSpace, this[PRIVATE].refSpace)) === null || _b === void 0 ? void 0 : _b.transform.matrix;
4502
+ if (gripMatrix) {
4503
+ const position = getTranslation(create$2(), gripMatrix);
4504
+ const quaternion = getRotation(create(), gripMatrix);
4505
+ inputFrame.gripTransform = {
4506
+ position,
4507
+ quaternion,
4508
+ };
4509
+ }
4510
+ }
4511
+ if (schema.hasHand) {
4512
+ const jointSpaces = Array.from(inputSource.hand.values());
4513
+ let allValid = true;
4514
+ // @ts-ignore
4515
+ allValid && (allValid = frame.fillPoses(jointSpaces, inputSource.targetRaySpace, this[PRIVATE].jointTransforms));
4516
+ // @ts-ignore
4517
+ allValid && (allValid = frame.fillJointRadii(jointSpaces, this[PRIVATE].jointRadii));
4518
+ if (allValid) {
4519
+ const hand = {};
4520
+ for (let offset = 0; offset < 25; offset++) {
4521
+ const jointMatrix = this[PRIVATE].jointTransforms.slice(offset * 16, (offset + 1) * 16);
4522
+ const radius = this[PRIVATE].jointRadii[offset];
4523
+ const position = getTranslation(create$2(), jointMatrix);
4524
+ const quaternion = getRotation(create(), jointMatrix);
4525
+ const jointName = jointSpaces[offset].jointName;
4526
+ hand[jointName] = { position, quaternion, radius };
4527
+ }
4528
+ inputFrame.hand = hand;
4529
+ }
4530
+ }
4531
+ if (schema.hasGamepad) {
4532
+ const gamepad = {
4533
+ buttons: inputSource.gamepad.buttons.map((button) => button
4534
+ ? [button.pressed ? 1 : 0, button.touched ? 1 : 0, button.value]
4535
+ : null),
4536
+ axes: Array.from(inputSource.gamepad.axes),
4537
+ };
4538
+ inputFrame.gamepad = gamepad;
4539
+ }
4540
+ actionFrame.inputFrames.push(inputFrame);
4541
+ }
4542
+ });
4543
+ this[PRIVATE].compressedFrames.push(this.compressActionFrame(actionFrame));
4544
+ }
4545
+ compressActionFrame(af) {
4546
+ const out = [
4547
+ Math.round(af.timeStamp * 10) / 10,
4548
+ ...compress(af.position),
4549
+ ...compress(af.quaternion),
4550
+ ];
4551
+ af.inputFrames.forEach((inputFrame) => {
4552
+ const index = inputFrame.index;
4553
+ const schema = this[PRIVATE].schemaMap.get(index);
4554
+ const inputOut = [
4555
+ index,
4556
+ ...compress(inputFrame.targetRayTransform.position),
4557
+ ...compress(inputFrame.targetRayTransform.quaternion),
4558
+ ];
4559
+ if (schema.hasGrip) {
4560
+ inputOut.push([
4561
+ ...compress(inputFrame.gripTransform.position),
4562
+ ...compress(inputFrame.gripTransform.quaternion),
4563
+ ]);
4564
+ }
4565
+ if (schema.hasHand) {
4566
+ const handArr = [];
4567
+ Object.values(inputFrame.hand).forEach(({ position, quaternion, radius }) => {
4568
+ handArr.push(...compress(position), ...compress(quaternion), parseFloat(radius.toFixed(3)));
4569
+ });
4570
+ inputOut.push(handArr);
4571
+ }
4572
+ if (schema.hasGamepad) {
4573
+ inputOut.push([
4574
+ ...inputFrame.gamepad.buttons,
4575
+ ...inputFrame.gamepad.axes,
4576
+ ]);
4577
+ }
4578
+ out.push(inputOut);
4579
+ });
4580
+ return out;
4581
+ }
4582
+ log() {
4583
+ const out = {
4584
+ schema: Array.from(this[PRIVATE].schemaMap.entries()),
4585
+ frames: this[PRIVATE].compressedFrames,
4586
+ };
4587
+ console.log(JSON.stringify(out));
4588
+ }
4589
+ }
4590
+
4591
+ export { ActionRecorder, XRDevice, XRFrame, XRHand, XRInputSource, XRInputSourceArray, XRInputSourceEvent, XRInputSourcesChangeEvent, XRJointPose, XRJointSpace, XRLayer, XRPose, XRReferenceSpace, XRReferenceSpaceEvent, XRRenderState, XRRigidTransform, XRSession, XRSessionEvent, XRSpace, XRSystem, XRView, XRViewerPose, XRViewport, XRWebGLLayer, metaQuest2, metaQuest3, metaQuestPro, oculusQuest1 };