@shopware-ag/dive 1.18.5-beta.1 → 1.18.5-beta.3

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.
@@ -0,0 +1,722 @@
1
+ import { O as p, t as y, u as w, M as S, e as d, V as o, v as E, Q as c, w as h, x as u, y as H } from "./dive-Dk0rFfvA.js";
2
+ function T(r, t) {
3
+ return r ? t in r : !1;
4
+ }
5
+ function m(r, t) {
6
+ if (r)
7
+ return T(r, t) ? r : m(r.parent, t);
8
+ }
9
+ class v {
10
+ static Launch(t, e) {
11
+ const s = this.findARQuickLookSrc(t);
12
+ return this.launchARQuickLook(s, e);
13
+ }
14
+ static launchARQuickLook(t, e) {
15
+ return new Promise((s) => {
16
+ (e == null ? void 0 : e.arScale) === "fixed" && (t = t.concat("#allowsContentScaling=0"));
17
+ const i = document.createElement("a");
18
+ i.innerHTML = "<picture></picture>", i.rel = "ar", i.href = t, i.download = "scene.usdz", s(), i.click();
19
+ });
20
+ }
21
+ static findARQuickLookSrc(t) {
22
+ let e = null;
23
+ if (t.traverse((s) => {
24
+ e || s.userData.uri && (e = s.userData.uri);
25
+ }), !e)
26
+ throw new Error("No model found in scene");
27
+ return e;
28
+ }
29
+ // private static extractModels(scene: DIVEScene): Object3D[] {
30
+ // // extract models
31
+ // return scene.Root.children;
32
+ // }
33
+ // private static launchARFromNode(
34
+ // node: Object3D,
35
+ // options?: DIVEAROptions,
36
+ // ): Promise<void> {
37
+ // // bundle USDZ
38
+ // return this._usdzExporter
39
+ // .parse(node, {
40
+ // quickLookCompatible: true,
41
+ // ar: {
42
+ // anchoring: { type: 'plane' },
43
+ // planeAnchoring: {
44
+ // alignment:
45
+ // options?.arPlacement === 'vertical'
46
+ // ? 'vertical'
47
+ // : 'horizontal',
48
+ // },
49
+ // },
50
+ // })
51
+ // .then((usdz: Uint8Array) => {
52
+ // // create blob
53
+ // const blob = new Blob([usdz], { type: 'model/vnd.usdz+zip' });
54
+ // let url = URL.createObjectURL(blob);
55
+ // if (options?.arScale === 'fixed') {
56
+ // url = url.concat('#allowsContentScaling=0');
57
+ // }
58
+ // // launch ARQuickLook
59
+ // const a = document.createElement('a');
60
+ // a.innerHTML = '<picture></picture>'; // This is actually needed so the viewer opens instantly
61
+ // a.rel = 'ar';
62
+ // a.href = url;
63
+ // a.download = 'scene.usdz';
64
+ // a.click();
65
+ // });
66
+ // }
67
+ }
68
+ class P {
69
+ get Element() {
70
+ return this._element;
71
+ }
72
+ get CloseButton() {
73
+ return this._closeButton;
74
+ }
75
+ constructor() {
76
+ this._element = document.createElement("div"), this._closeButton = this.createCloseButton(), this._element.appendChild(this._closeButton), document.body.appendChild(this._element);
77
+ }
78
+ createCloseButton() {
79
+ const t = document.createElementNS(
80
+ "http://www.w3.org/2000/svg",
81
+ "path"
82
+ );
83
+ t.setAttribute("d", "M 12,12 L 28,28 M 28,12 12,28"), t.setAttribute("stroke", "#fff"), t.setAttribute("stroke-width", "2");
84
+ const e = document.createElementNS(
85
+ "http://www.w3.org/2000/svg",
86
+ "svg"
87
+ );
88
+ return e.setAttribute("width", "38"), e.setAttribute("height", "38"), e.style.position = "absolute", e.style.right = "20px", e.style.top = "20px", e.appendChild(t), e;
89
+ }
90
+ }
91
+ class x extends p {
92
+ set mesh(t) {
93
+ this.clear(), t && this.add(t);
94
+ }
95
+ constructor(t) {
96
+ return super(), t ? this.mesh = t : this.UseDefaultMesh(), this.matrixAutoUpdate = !1, this;
97
+ }
98
+ UseDefaultMesh() {
99
+ const t = new y(0.08, 0.1, 32).rotateX(-Math.PI / 2), e = new w();
100
+ this.mesh = new S(t, e);
101
+ }
102
+ UpdateFromPose(t) {
103
+ this.matrix.fromArray(t.transform.matrix);
104
+ }
105
+ }
106
+ class C {
107
+ constructor(t, e) {
108
+ this._referenceSpaceBuffer = null, this._requesting = !1, this._initialized = !1, this._session = t, this._renderer = e, this._hitMatrixBuffer = new d();
109
+ }
110
+ Dispose() {
111
+ var t;
112
+ (t = this._transientHitTestSource) == null || t.cancel(), this._transientHitTestSource = void 0, this._initialized = !1;
113
+ }
114
+ async Init() {
115
+ return this._session ? this._requesting ? (console.error(
116
+ "DIVEWebXRRaycaster: Currently initializing! Aborting initialization..."
117
+ ), Promise.reject()) : this._initialized ? (console.error(
118
+ "DIVEWebXRRaycaster: Already initialized! Aborting initialization..."
119
+ ), Promise.reject()) : (this._requesting = !0, this._transientHitTestSource = await this._session.requestHitTestSourceForTransientInput({
120
+ profile: "generic-touchscreen"
121
+ }), this._referenceSpaceBuffer = this._renderer.xr.getReferenceSpace(), this._requesting = !1, this._transientHitTestSource ? (this._initialized = !0, console.log("DIVEWebXRRaycasterAR: Initialized"), Promise.resolve(this)) : Promise.reject()) : (console.error(
122
+ "DIVEWebXRRaycaster: No session set in Init()! Aborting initialization..."
123
+ ), Promise.reject());
124
+ }
125
+ GetIntersections(t) {
126
+ if (!this._transientHitTestSource) return [];
127
+ const e = t.getHitTestResultsForTransientInput(
128
+ this._transientHitTestSource
129
+ );
130
+ return e.length === 0 ? [] : e.map((i) => {
131
+ if (!this._referenceSpaceBuffer || !i.results[0] || !i.results[0].getPose) return;
132
+ const a = i.results[0].getPose(this._referenceSpaceBuffer);
133
+ return a ? (this._hitMatrixBuffer.fromArray(a.transform.matrix), {
134
+ point: new o().setFromMatrixPosition(
135
+ this._hitMatrixBuffer
136
+ ),
137
+ matrix: this._hitMatrixBuffer,
138
+ object: void 0
139
+ }) : void 0;
140
+ }).filter((i) => i !== void 0);
141
+ }
142
+ }
143
+ class A {
144
+ constructor(t, e) {
145
+ this._raycaster = new E(), this._renderer = t, this._scene = e, this._controller = this._renderer.xr.getController(0);
146
+ }
147
+ async Init() {
148
+ return console.log("DIVEWebXRRaycasterTHREE: Initialized"), Promise.resolve(this);
149
+ }
150
+ GetIntersections() {
151
+ this._controller.updateMatrixWorld(), this._raycaster.setFromXRController(this._controller);
152
+ const t = this._raycaster.intersectObjects(
153
+ this._scene.XRRoot.XRModelRoot.children
154
+ );
155
+ return t.length === 0 ? [] : t.map((e) => ({
156
+ point: e.point,
157
+ matrix: e.object.matrixWorld,
158
+ object: e.object
159
+ }));
160
+ }
161
+ }
162
+ class g {
163
+ constructor() {
164
+ this._listeners = /* @__PURE__ */ new Map();
165
+ }
166
+ Subscribe(t, e) {
167
+ return this._listeners.get(t) || this._listeners.set(t, []), this._listeners.get(t).push(e), () => {
168
+ const s = this._listeners.get(t);
169
+ if (!s) return !1;
170
+ const i = s.findIndex(
171
+ (a) => a === e
172
+ );
173
+ return i === -1 ? !1 : (s.splice(i, 1), !0);
174
+ };
175
+ }
176
+ dispatch(t, e) {
177
+ const s = this._listeners.get(t);
178
+ s && s.forEach((i) => i(e));
179
+ }
180
+ }
181
+ class I extends g {
182
+ constructor(t, e, s) {
183
+ super(), this._initialized = !1, this._arHitResultBuffer = [], this._sceneHitResultBuffer = [], this._hasHit = !1, this._session = t, this._threeRaycaster = new A(e, s), this._arRaycaster = new C(t, e);
184
+ }
185
+ Dispose() {
186
+ this._initialized = !1;
187
+ }
188
+ async Init() {
189
+ return this._session ? this._initialized ? (console.error(
190
+ "DIVEWebXRRaycaster: Already initialized! Aborting initialization..."
191
+ ), Promise.reject()) : (await this._threeRaycaster.Init(), await this._arRaycaster.Init(), console.log("DIVEWebXRRaycaster: Initialized"), this._initialized = !0, Promise.resolve(this)) : (console.error(
192
+ "DIVEWebXRRaycaster: No session set in Init()! Aborting initialization..."
193
+ ), Promise.reject());
194
+ }
195
+ GetARIntersections(t) {
196
+ return this._arHitResultBuffer = this._arRaycaster.GetIntersections(t), this._arHitResultBuffer.length > 0 ? this.onARHitFound(this._arHitResultBuffer[0]) : this.onARHitLost(), this._arHitResultBuffer;
197
+ }
198
+ GetSceneIntersections() {
199
+ return this._sceneHitResultBuffer = this._threeRaycaster.GetIntersections(), this._sceneHitResultBuffer.length > 0 ? this.onSceneHitFound(this._sceneHitResultBuffer[0]) : this.onSceneHitLost(), this._sceneHitResultBuffer;
200
+ }
201
+ onARHitFound(t) {
202
+ this._hasHit = !0, this.dispatch("AR_HIT_FOUND", { hit: t });
203
+ }
204
+ onARHitLost() {
205
+ this._hasHit && (this._hasHit = !1, this.dispatch("AR_HIT_LOST"));
206
+ }
207
+ onSceneHitFound(t) {
208
+ this._hasHit = !0, this.dispatch("SCENE_HIT_FOUND", { hit: t });
209
+ }
210
+ onSceneHitLost() {
211
+ this._hasHit && (this._hasHit = !1, this.dispatch("SCENE_HIT_LOST"));
212
+ }
213
+ }
214
+ class D {
215
+ constructor(t, e, s) {
216
+ this._raycastHitCounter = 0, this._originSetResolve = () => {
217
+ }, this._renderer = e, this._session = t, this._originSet = new Promise((i) => {
218
+ this._originSetResolve = i;
219
+ }), this._requesting = !1, this._initialized = !1, this._referenceSpaceBuffer = null, this._hitTestSource = null, this._entityTypes = s || ["plane"], this._hitTestResultBuffer = [], this._matrix = new d(), this._position = new o(), this._quaternion = new c(), this._scale = new o(), this._originSet.then(() => {
220
+ this._matrix.decompose(
221
+ this._position,
222
+ this._quaternion,
223
+ this._scale
224
+ );
225
+ });
226
+ }
227
+ get originSet() {
228
+ return this._originSet;
229
+ }
230
+ get matrix() {
231
+ return this._matrix;
232
+ }
233
+ set matrix(t) {
234
+ this._matrix = t, this._matrix.decompose(this._position, this._quaternion, this._scale);
235
+ }
236
+ get position() {
237
+ return this._position;
238
+ }
239
+ get quaternion() {
240
+ return this._quaternion;
241
+ }
242
+ get scale() {
243
+ return this._scale;
244
+ }
245
+ async Init() {
246
+ if (this._initialized)
247
+ return Promise.resolve(this);
248
+ if (!this._session)
249
+ return console.error(
250
+ "DIVEWebXROrigin: No session set in Init()! Aborting initialization..."
251
+ ), Promise.reject();
252
+ if (this._requesting)
253
+ return console.error(
254
+ "DIVEWebXROrigin: Currently initializing! Aborting initialization..."
255
+ ), Promise.reject();
256
+ this._requesting = !0;
257
+ const t = await this._session.requestReferenceSpace("viewer");
258
+ return this._hitTestSource = await this._session.requestHitTestSource({
259
+ space: t,
260
+ entityTypes: this._entityTypes
261
+ }) || null, this._requesting = !1, this._hitTestSource ? (this._initialized = !0, Promise.resolve(this)) : Promise.reject();
262
+ }
263
+ Dispose() {
264
+ var t;
265
+ this._initialized = !1, this._requesting = !1, (t = this._hitTestSource) == null || t.cancel(), this._hitTestSource = null, this._hitTestResultBuffer = [], this._matrix = new d(), this._position = new o(), this._quaternion = new c(), this._scale = new o();
266
+ }
267
+ Update(t) {
268
+ if (this._initialized) {
269
+ if (!this._hitTestSource)
270
+ throw new Error(
271
+ "DIVEWebXRRaycaster: Critical Error: HitTestSource not available but WebXROrigin is initialized!"
272
+ );
273
+ if (this._hitTestResultBuffer = t.getHitTestResults(
274
+ this._hitTestSource
275
+ ), this._hitTestResultBuffer.length > 0) {
276
+ if (this._referenceSpaceBuffer = this._renderer.xr.getReferenceSpace(), !this._referenceSpaceBuffer) {
277
+ this.onHitLost();
278
+ return;
279
+ }
280
+ const e = this._hitTestResultBuffer[0].getPose(
281
+ this._referenceSpaceBuffer
282
+ );
283
+ if (!e) {
284
+ this.onHitLost();
285
+ return;
286
+ }
287
+ this.onHitFound(e);
288
+ } else
289
+ this.onHitLost();
290
+ }
291
+ }
292
+ onHitFound(t) {
293
+ this._raycastHitCounter++, this.matrix.fromArray(t.transform.matrix), this._raycastHitCounter > 50 && this._originSetResolve();
294
+ }
295
+ onHitLost() {
296
+ this._raycastHitCounter = 0;
297
+ }
298
+ }
299
+ class X extends g {
300
+ constructor(t) {
301
+ super(), this._touchCount = 0, this._touches = [], this._handleRotateStarted = !1, this._handleRotateMoved = !1, this._handleRotateEnded = !1, this._startAngle = 0, this._lastAngle = 0, this._angleDelta = 0, this._handlePinchStarted = !1, this._handlePinchMoved = !1, this._handlePinchEnded = !1, this._scaleDistanceStart = 0, this._currentDistance = 1, this._deltaDistance = 0, this._session = t, this._touches = [
302
+ {
303
+ start: new h(),
304
+ current: new h(),
305
+ delta: new h()
306
+ },
307
+ {
308
+ start: new h(),
309
+ current: new h(),
310
+ delta: new h()
311
+ }
312
+ ], this._handleRotateStarted = !1, window.addEventListener(
313
+ "touchstart",
314
+ (e) => this.onTouchStart(e)
315
+ ), window.addEventListener(
316
+ "touchmove",
317
+ (e) => this.onTouchMove(e)
318
+ ), window.addEventListener(
319
+ "touchend",
320
+ (e) => this.onTouchEnd(e)
321
+ ), this._session.addEventListener(
322
+ "selectstart",
323
+ () => this.onSessionSelectStart()
324
+ ), this._session.addEventListener(
325
+ "selectend",
326
+ () => this.onSessionSelectEnd()
327
+ );
328
+ }
329
+ Dispose() {
330
+ window.removeEventListener(
331
+ "touchstart",
332
+ (t) => this.onTouchStart(t)
333
+ ), window.removeEventListener(
334
+ "touchmove",
335
+ (t) => this.onTouchMove(t)
336
+ ), window.removeEventListener(
337
+ "touchend",
338
+ (t) => this.onTouchEnd(t)
339
+ ), this._session.removeEventListener(
340
+ "selectstart",
341
+ () => this.onSessionSelectStart()
342
+ ), this._session.removeEventListener(
343
+ "selectend",
344
+ () => this.onSessionSelectEnd()
345
+ );
346
+ }
347
+ onTouchStart(t) {
348
+ this._touchCount = t.touches.length, this._touches[0].start.set(
349
+ t.touches[0].clientX,
350
+ t.touches[0].clientY
351
+ ), this._touches[0].current.set(
352
+ t.touches[0].clientX,
353
+ t.touches[0].clientY
354
+ ), this._touches[0].delta.set(0, 0), this._touchCount > 1 && (this._touches[1].start.set(
355
+ t.touches[1].clientX,
356
+ t.touches[1].clientY
357
+ ), this._touches[1].current.set(
358
+ t.touches[1].clientX,
359
+ t.touches[1].clientY
360
+ ), this._touches[1].delta.set(0, 0)), this._touchCount === 2 && (this.handleRotateStart(), this.handlePinchStart()), this._handleRotateStarted && (this.dispatch("ROTATE_START", {
361
+ current: 0
362
+ }), this._handleRotateStarted = !1), this._handlePinchStarted && (this.dispatch("PINCH_START", {
363
+ current: 0
364
+ }), this._handlePinchStarted = !1);
365
+ }
366
+ onTouchMove(t) {
367
+ this._touchCount = t.touches.length, this._touches[0].start.set(
368
+ t.touches[0].clientX,
369
+ t.touches[0].clientY
370
+ ), this._touches[0].current.set(
371
+ t.touches[0].clientX,
372
+ t.touches[0].clientY
373
+ ), this._touches[0].delta.copy(
374
+ this._touches[0].current.clone().sub(this._touches[0].start)
375
+ ), this._touchCount > 1 && (this._touches[1].start.set(
376
+ t.touches[1].clientX,
377
+ t.touches[1].clientY
378
+ ), this._touches[1].current.set(
379
+ t.touches[1].clientX,
380
+ t.touches[1].clientY
381
+ ), this._touches[1].delta.copy(
382
+ this._touches[1].current.clone().sub(this._touches[1].start)
383
+ )), this._touchCount === 2 && (this.handleRotateMoved(), this.handlePinchMoved()), this._touchCount === 1 && this.dispatch("TOUCH_MOVE", {
384
+ touches: [
385
+ {
386
+ current: this._touches[0].current.clone(),
387
+ delta: this._touches[0].delta.clone()
388
+ },
389
+ {
390
+ current: this._touches[1].current.clone(),
391
+ delta: this._touches[1].delta.clone()
392
+ }
393
+ ],
394
+ touchCount: this._touchCount
395
+ }), this._touchCount === 2 && (this._handleRotateMoved && (this.dispatch("ROTATE_MOVE", {
396
+ current: this._lastAngle,
397
+ delta: this._angleDelta
398
+ }), this._handleRotateMoved = !1), this._handlePinchMoved && (this.dispatch("PINCH_MOVE", {
399
+ current: this._currentDistance,
400
+ delta: this._deltaDistance
401
+ }), this._handlePinchMoved = !1));
402
+ }
403
+ onTouchEnd(t) {
404
+ this._touchCount = t.touches.length, this._touchCount === 0 && (this._touches[0].start.set(0, 0), this._touches[0].current.set(0, 0), this._touches[0].delta.set(0, 0)), this._touchCount === 1 && (this.handleRotateEnded(), this.handlePinchEnded(), this._touches[1].start.set(0, 0), this._touches[1].current.set(0, 0), this._touches[1].delta.set(0, 0)), this._handleRotateEnded && (this.dispatch("ROTATE_END", {
405
+ current: this._lastAngle
406
+ }), this._handleRotateEnded = !1), this._handlePinchEnded && (this.dispatch("PINCH_END", {
407
+ current: this._currentDistance
408
+ }), this._handlePinchEnded = !1);
409
+ }
410
+ onSessionSelectStart() {
411
+ this.dispatch("TOUCH_START", {
412
+ touches: [
413
+ {
414
+ current: this._touches[0].current.clone()
415
+ },
416
+ {
417
+ current: this._touches[1].current.clone()
418
+ }
419
+ ],
420
+ touchCount: this._touchCount
421
+ });
422
+ }
423
+ onSessionSelectEnd() {
424
+ this.dispatch("TOUCH_END", {
425
+ touches: [
426
+ {
427
+ current: this._touches[0].current.clone()
428
+ },
429
+ {
430
+ current: this._touches[1].current.clone()
431
+ }
432
+ ],
433
+ touchCount: this._touchCount
434
+ });
435
+ }
436
+ // rotation handler
437
+ handleRotateStart() {
438
+ this._handleRotateStarted = !0, this._startAngle = this._touches[1].start.clone().sub(this._touches[0].current).angle();
439
+ }
440
+ handleRotateMoved() {
441
+ this._handleRotateMoved = !0;
442
+ const t = this._touches[1].current.clone().sub(this._touches[0].current).angle();
443
+ this._angleDelta = t - this._startAngle, this._lastAngle = this._angleDelta * -1;
444
+ }
445
+ handleRotateEnded() {
446
+ this._handleRotateEnded = !0;
447
+ }
448
+ // pinch handler
449
+ handlePinchStart() {
450
+ this._handlePinchStarted = !0, this._scaleDistanceStart = this._touches[1].start.distanceTo(
451
+ this._touches[0].current
452
+ );
453
+ }
454
+ handlePinchMoved() {
455
+ this._handlePinchMoved = !0;
456
+ const t = this._currentDistance, e = this._touches[1].current.distanceTo(
457
+ this._touches[0].current
458
+ );
459
+ this._currentDistance = e / this._scaleDistanceStart, this._deltaDistance = this._currentDistance - t;
460
+ }
461
+ handlePinchEnded() {
462
+ this._handlePinchEnded = !0;
463
+ }
464
+ }
465
+ class O extends p {
466
+ constructor(t, e, s) {
467
+ super(), this._frameBuffer = null, this._handNodeInitialPosition = new o(), this._placed = !1, this._grabbedObject = null, this._arHitPosition = new o(), this._arHitQuaternion = new c(), this._arHitScale = new o(1, 1, 1), this._initialObjectPosition = null, this._initialRaycastHit = null, this._deltaRaycastHit = new o(), this._touchQuaterion = new c(), this._touchScale = 1, this._scaleThreshold = 0.1, this._startTouchQuaternion = new c(), this._startTouchScale = 1, this._renderer = e, this._scene = s, this._session = t, this._xrRaycaster = new I(t, e, s), this._origin = new D(this._session, this._renderer, [
468
+ "plane"
469
+ ]), this._crosshair = new x(), this._crosshair.visible = !1, this._xrCamera = this._renderer.xr.getCamera(), this._scene.XRRoot.XRHandNode.position.set(0, -0.05, -0.25), this._handNodeInitialPosition = this._scene.XRRoot.XRHandNode.position.clone(), this._touchscreenControls = new X(
470
+ this._session
471
+ ), this._touchscreenControls.Subscribe(
472
+ "TOUCH_START",
473
+ () => this.onTouchStart()
474
+ ), this._touchscreenControls.Subscribe(
475
+ "TOUCH_MOVE",
476
+ () => this.onTouchMove()
477
+ ), this._touchscreenControls.Subscribe(
478
+ "TOUCH_END",
479
+ (i) => this.onTouchEnd(i)
480
+ ), this._touchscreenControls.Subscribe(
481
+ "ROTATE_START",
482
+ () => this.onRotateStart()
483
+ ), this._touchscreenControls.Subscribe(
484
+ "ROTATE_MOVE",
485
+ (i) => this.onRotateMove(i)
486
+ ), this._touchscreenControls.Subscribe(
487
+ "PINCH_START",
488
+ () => this.onPinchStart()
489
+ ), this._touchscreenControls.Subscribe(
490
+ "PINCH_MOVE",
491
+ (i) => this.onPinchMove(i)
492
+ );
493
+ }
494
+ async Init() {
495
+ return this.prepareScene(), await this.initOrigin(), await this.initRaycaster(), Promise.resolve(this);
496
+ }
497
+ Dispose() {
498
+ this.restoreScene(), this._origin.Dispose(), this._xrRaycaster.Dispose(), this._placed = !1;
499
+ }
500
+ Update(t) {
501
+ this._frameBuffer = t, this._placed || (this.updateHandNode(), this._origin && this._origin.Update(t));
502
+ }
503
+ updateHandNode() {
504
+ this._xrCamera.updateMatrixWorld(), this._scene.XRRoot.XRHandNode.position.copy(
505
+ this._handNodeInitialPosition.clone().applyMatrix4(this._xrCamera.matrixWorld)
506
+ ), this._scene.XRRoot.XRHandNode.quaternion.setFromRotationMatrix(
507
+ this._xrCamera.matrixWorld
508
+ );
509
+ }
510
+ // placement
511
+ async initOrigin() {
512
+ this._origin = await this._origin.Init(), this._origin.originSet.then(() => {
513
+ this.placeObjects(this._origin.matrix);
514
+ });
515
+ }
516
+ placeObjects(t) {
517
+ this._scene.XRRoot.XRModelRoot.matrix.copy(t), [...this._scene.XRRoot.XRHandNode.children].forEach((e) => {
518
+ this._scene.XRRoot.XRModelRoot.add(e);
519
+ }), this._placed = !0;
520
+ }
521
+ // grabbing
522
+ updateObject() {
523
+ this._grabbedObject && (this._grabbedObject.position.copy(this._arHitPosition), this._grabbedObject.quaternion.copy(
524
+ this._arHitQuaternion.clone().multiply(this._touchQuaterion)
525
+ ), this._grabbedObject.scale.copy(
526
+ new o(
527
+ this._touchScale,
528
+ this._touchScale,
529
+ this._touchScale
530
+ ).multiply(this._arHitScale)
531
+ ));
532
+ }
533
+ onTouchStart() {
534
+ const t = this._xrRaycaster.GetSceneIntersections();
535
+ if (console.log("sceneHits", t), t.length === 0 || !t[0].object) return;
536
+ const e = m(
537
+ t[0].object,
538
+ "isMovable"
539
+ );
540
+ e && (this._grabbedObject = e);
541
+ }
542
+ onTouchMove() {
543
+ if (!this._frameBuffer || !this._grabbedObject) return;
544
+ const t = this._xrRaycaster.GetARIntersections(
545
+ this._frameBuffer
546
+ );
547
+ if (t.length === 0) {
548
+ this._crosshair.visible = !1;
549
+ return;
550
+ }
551
+ const e = t[0];
552
+ this._crosshair.visible = !0, this._crosshair.matrix.copy(e.matrix), this._grabbedObject && ((!this._initialObjectPosition || !this._initialRaycastHit) && (this._initialObjectPosition = this._grabbedObject.position.clone(), this._initialRaycastHit = e.point.clone()), e.matrix.decompose(
553
+ this._arHitPosition,
554
+ this._arHitQuaternion,
555
+ this._arHitScale
556
+ ), this._deltaRaycastHit.copy(
557
+ e.point.clone().sub(this._initialRaycastHit)
558
+ ), this._arHitPosition.copy(
559
+ this._initialObjectPosition.clone().add(this._deltaRaycastHit)
560
+ ), console.log("arHitPosition", this._arHitPosition), this.updateObject());
561
+ }
562
+ onTouchEnd(t) {
563
+ t.touchCount === 0 && (this._crosshair.visible = !1, this._initialObjectPosition = null, this._initialRaycastHit = null, this._grabbedObject = null);
564
+ }
565
+ onRotateStart() {
566
+ this._startTouchQuaternion = this._touchQuaterion.clone();
567
+ }
568
+ onRotateMove(t) {
569
+ this._touchQuaterion.setFromAxisAngle(
570
+ new o(0, -1, 0),
571
+ t.delta * 3
572
+ ), this._touchQuaterion.multiply(this._startTouchQuaternion), this.updateObject();
573
+ }
574
+ onPinchStart() {
575
+ this._startTouchScale = this._touchScale;
576
+ }
577
+ onPinchMove(t) {
578
+ this._touchScale = this._startTouchScale * t.current, this.updateObject();
579
+ }
580
+ // prepare & cleanup scene
581
+ prepareScene() {
582
+ this._scene.XRRoot.XRModelRoot.matrixAutoUpdate = !1, this._scene.add(this._crosshair);
583
+ const t = [];
584
+ this._scene.Root.children.forEach((e) => {
585
+ const s = e.clone();
586
+ s.layers.enableAll(), s.traverse((i) => {
587
+ i.layers.enableAll(), i instanceof S && i.scale.set(0.1, 0.1, 0.1);
588
+ }), s.position.set(0, 0, 0), t.push(s);
589
+ }), this._scene.XRRoot.XRHandNode.add(...t);
590
+ }
591
+ restoreScene() {
592
+ this._scene.remove(this._crosshair), this._scene.XRRoot.XRHandNode.clear(), this._scene.XRRoot.XRModelRoot.clear(), this._scene.XRRoot.XRModelRoot.matrixAutoUpdate = !0;
593
+ }
594
+ // raycast
595
+ async initRaycaster() {
596
+ if (await this._xrRaycaster.Init(), !this._xrRaycaster)
597
+ return console.error(
598
+ "Raycaster not initialized successfully. Aborting WebXR..."
599
+ ), this.Dispose(), Promise.reject();
600
+ }
601
+ }
602
+ const n = class n {
603
+ static async Launch(t, e, s) {
604
+ if (this._renderer = t, this._scene = e, this._controller = s, this._cameraPosition = this._controller.object.position.clone(), this._cameraTarget = this._controller.target.clone(), !navigator.xr)
605
+ return console.error("WebXR not supported"), Promise.reject();
606
+ if (this._renderer.xr.enabled = !0, this._scene.InitXR(t), !n._overlay) {
607
+ const a = new P();
608
+ n._overlay = a;
609
+ }
610
+ n._options.domOverlay = { root: n._overlay.Element };
611
+ const i = await navigator.xr.requestSession(
612
+ "immersive-ar",
613
+ this._options
614
+ );
615
+ return i.addEventListener("end", () => {
616
+ this._onSessionEnded();
617
+ }), t.xr.setReferenceSpaceType(this._referenceSpaceType), await t.xr.setSession(i), n._overlay.Element.style.display = "", this._session = i, n._overlay.CloseButton.addEventListener(
618
+ "click",
619
+ () => this.End()
620
+ ), await this._onSessionStarted(), Promise.resolve();
621
+ }
622
+ static Update(t, e) {
623
+ this._session && this._xrController && this._xrController.Update(e);
624
+ }
625
+ static End() {
626
+ this._session && this._session.end();
627
+ }
628
+ static async _onSessionStarted() {
629
+ if (this._session)
630
+ return this._renderCallbackId = this._renderer.AddPreRenderCallback(
631
+ (t, e) => {
632
+ this.Update(t, e);
633
+ }
634
+ ), this._xrController = new O(
635
+ this._session,
636
+ this._renderer,
637
+ this._scene
638
+ ), await this._xrController.Init().catch(() => {
639
+ this.End();
640
+ }), Promise.resolve();
641
+ }
642
+ static _onSessionEnded() {
643
+ if (!this._session) return;
644
+ this._xrController && this._xrController.Dispose(), this._renderCallbackId && (this._renderer.RemovePreRenderCallback(this._renderCallbackId), this._renderCallbackId = null), this._renderer.xr.enabled = !1;
645
+ const t = this._renderer.domElement.parentElement;
646
+ if (t) {
647
+ const { clientWidth: e, clientHeight: s } = t;
648
+ this._renderer.OnResize(e, s), this._controller.object.OnResize(e, s);
649
+ }
650
+ this._controller.object.position.copy(this._cameraPosition), this._controller.target.copy(this._cameraTarget), this._cameraPosition.set(0, 0, 0), this._cameraTarget.set(0, 0, 0), this._scene.DisposeXR(), this._session.removeEventListener("end", this._onSessionEnded), n._overlay.Element.style.display = "none", this._session = null;
651
+ }
652
+ };
653
+ n._renderCallbackId = null, n._session = null, n._referenceSpaceType = "local", n._overlay = null, n._options = {
654
+ requiredFeatures: [
655
+ "local",
656
+ "hit-test"
657
+ ],
658
+ optionalFeatures: [
659
+ "light-estimation",
660
+ "local-floor",
661
+ "dom-overlay",
662
+ "depth-sensing"
663
+ ],
664
+ depthSensing: {
665
+ usagePreference: ["gpu-optimized"],
666
+ dataFormatPreference: []
667
+ },
668
+ domOverlay: { root: {} }
669
+ }, n._xrController = null;
670
+ let f = n;
671
+ class M {
672
+ static Launch(t, e) {
673
+ const s = this.findSceneViewerSrc(t);
674
+ this.launchSceneViewer(s, e);
675
+ }
676
+ static launchSceneViewer(t, e) {
677
+ const s = document.createElement("a"), i = "#model-viewer-no-ar-fallback", a = self.location.toString(), _ = new URL(a), R = new URL(t, a), l = new URLSearchParams(R.search);
678
+ _.hash = i, l.set("mode", "ar_only"), (e == null ? void 0 : e.arScale) === "fixed" && l.set("resizable", "false"), (e == null ? void 0 : e.arPlacement) === "vertical" && l.set("enable_vertical_placement", "true");
679
+ const b = `intent://arvr.google.com/scene-viewer/1.2?${l.toString() + "&file=" + R.toString()}#Intent;scheme=https;package=com.google.android.googlequicksearchbox;action=android.intent.action.VIEW;S.browser_fallback_url=${encodeURIComponent(
680
+ _.toString()
681
+ )};end;`;
682
+ s.setAttribute("href", b), s.click();
683
+ }
684
+ static findSceneViewerSrc(t) {
685
+ let e = null;
686
+ if (t.traverse((s) => {
687
+ e || s.userData.uri && (e = s.userData.uri);
688
+ }), !e)
689
+ throw new Error("No model found in scene");
690
+ return e;
691
+ }
692
+ }
693
+ class V {
694
+ constructor(t, e, s) {
695
+ this._renderer = t, this._scene = e, this._controller = s;
696
+ }
697
+ async Launch(t) {
698
+ const e = u.GetSystem();
699
+ if (e === "iOS")
700
+ return this.tryARQuickLook();
701
+ if (e === "Android")
702
+ return t != null && t.useWebXR ? (console.warn("DIVE: WebXR is experimental on Android."), this.tryWebXR()) : this.trySceneViewer();
703
+ console.log(
704
+ "DIVE: AR not supported. Not a mobile system. (System is " + e + ")"
705
+ );
706
+ }
707
+ async tryARQuickLook(t) {
708
+ return u.GetSupportsARQuickLook() ? (console.log("DIVE: Launching AR with ARQuickLook ..."), await v.Launch(this._scene, t), Promise.resolve()) : (console.log("ARQuickLook not supported"), Promise.reject());
709
+ }
710
+ async tryWebXR() {
711
+ return await u.GetSupportsWebXR() ? (console.log("DIVE: Launching AR with WebXR ..."), await f.Launch(this._renderer, this._scene, this._controller), Promise.resolve()) : (console.log(
712
+ "WebXR not supported. Reason: " + H[u.GetWebXRUnsupportedReason()]
713
+ ), Promise.reject());
714
+ }
715
+ async trySceneViewer(t) {
716
+ return console.log("DIVE: Launching AR with SceneViewer ..."), M.Launch(this._scene, t), Promise.resolve();
717
+ }
718
+ }
719
+ export {
720
+ V as DIVEAR
721
+ };
722
+ //# sourceMappingURL=AR-BzVanQ-t.js.map