@galacean/engine-xr 1.3.0-alpha.2 → 1.3.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +217 -159
- package/dist/browser.js.map +1 -1
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +1 -1
- package/dist/main.js +217 -159
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +217 -159
- package/dist/module.js +217 -161
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/XRManagerExtended.d.ts +7 -64
- package/types/feature/trackable/XRTrackableFeature.d.ts +1 -2
- package/types/index.d.ts +4 -0
- package/types/loader/XRReferenceImageDecoder.d.ts +5 -0
- package/types/loader/XRReferenceImageLoader.d.ts +5 -0
- package/types/session/XRSessionManager.d.ts +11 -0
- package/types/session/XRSessionState.d.ts +5 -3
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CameraType, Matrix, CameraClearFlags, Vector3, Quaternion, Rect, XRManager, Ray, Plane, Vector2 } from '@galacean/engine';
|
|
1
|
+
import { CameraType, Matrix, CameraClearFlags, Vector3, Quaternion, Rect, SafeLoopArray, XRManager, Ray, Plane, Vector2, decoder, resourceLoader, AssetPromise, decode, Loader } from '@galacean/engine';
|
|
2
2
|
|
|
3
3
|
function _is_native_reflect_construct() {
|
|
4
4
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
@@ -95,9 +95,10 @@ function _instanceof(left, right) {
|
|
|
95
95
|
*/ var XRSessionState;
|
|
96
96
|
(function(XRSessionState) {
|
|
97
97
|
XRSessionState[XRSessionState[/** Not initialized. */ "None"] = 0] = "None";
|
|
98
|
-
XRSessionState[XRSessionState[/**
|
|
99
|
-
XRSessionState[XRSessionState[/**
|
|
100
|
-
XRSessionState[XRSessionState[/**
|
|
98
|
+
XRSessionState[XRSessionState[/** Initializing session. */ "Initializing"] = 1] = "Initializing";
|
|
99
|
+
XRSessionState[XRSessionState[/** Initialized but not started. */ "Initialized"] = 2] = "Initialized";
|
|
100
|
+
XRSessionState[XRSessionState[/** Running. */ "Running"] = 3] = "Running";
|
|
101
|
+
XRSessionState[XRSessionState[/** Paused. */ "Paused"] = 4] = "Paused";
|
|
101
102
|
})(XRSessionState || (XRSessionState = {}));
|
|
102
103
|
|
|
103
104
|
/**
|
|
@@ -180,7 +181,7 @@ function _instanceof(left, right) {
|
|
|
180
181
|
*/ _proto._onSessionExit = function _onSessionExit() {};
|
|
181
182
|
/**
|
|
182
183
|
* @internal
|
|
183
|
-
*/ _proto.
|
|
184
|
+
*/ _proto._getIgnoreClearFlags = function _getIgnoreClearFlags(cameraType) {
|
|
184
185
|
if (cameraType === CameraType.XRCenterCamera) {
|
|
185
186
|
if (this._xrManager.sessionManager.state === XRSessionState.Running) {
|
|
186
187
|
return CameraClearFlags.Color;
|
|
@@ -340,7 +341,7 @@ var XRTargetRayMode;
|
|
|
340
341
|
this._removed = [];
|
|
341
342
|
this._trackedDevices = [];
|
|
342
343
|
this._statusSnapshot = [];
|
|
343
|
-
this._listeners =
|
|
344
|
+
this._listeners = new SafeLoopArray();
|
|
344
345
|
var _this = this, trackedDevices = _this._trackedDevices, controllers = _this._controllers, cameras = _this._cameras;
|
|
345
346
|
for(var i = 0; i < 6; i++){
|
|
346
347
|
switch(i){
|
|
@@ -370,22 +371,22 @@ var XRTargetRayMode;
|
|
|
370
371
|
* Add a listener for tracked device changes.
|
|
371
372
|
* @param listener - The listener to add
|
|
372
373
|
*/ _proto.addTrackedDeviceChangedListener = function addTrackedDeviceChangedListener(listener) {
|
|
373
|
-
this._listeners.push(
|
|
374
|
+
this._listeners.push({
|
|
375
|
+
fn: listener
|
|
376
|
+
});
|
|
374
377
|
};
|
|
375
378
|
/**
|
|
376
379
|
* Remove a listener of tracked device changes.
|
|
377
380
|
* @param listener - The listener to remove
|
|
378
381
|
*/ _proto.removeTrackedDeviceChangedListener = function removeTrackedDeviceChangedListener(listener) {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
listeners.splice(index, 1);
|
|
383
|
-
}
|
|
382
|
+
this._listeners.findAndRemove(function(value) {
|
|
383
|
+
return value.fn === listener ? value.destroyed = true : false;
|
|
384
|
+
});
|
|
384
385
|
};
|
|
385
386
|
/**
|
|
386
387
|
* @internal
|
|
387
388
|
*/ _proto._onUpdate = function _onUpdate() {
|
|
388
|
-
var _this = this, added = _this._added, removed = _this._removed,
|
|
389
|
+
var _this = this, added = _this._added, removed = _this._removed, statusSnapshot = _this._statusSnapshot;
|
|
389
390
|
var _this1 = this, trackedDevices = _this1._trackedDevices, controllers = _this1._controllers;
|
|
390
391
|
// Reset data
|
|
391
392
|
added.length = removed.length = 0;
|
|
@@ -418,15 +419,19 @@ var XRTargetRayMode;
|
|
|
418
419
|
}
|
|
419
420
|
// Dispatch change event
|
|
420
421
|
if (added.length > 0 || removed.length > 0) {
|
|
422
|
+
var listeners = this._listeners.getLoopArray();
|
|
421
423
|
for(var i3 = 0, n3 = listeners.length; i3 < n3; i3++){
|
|
422
|
-
listeners[i3]
|
|
424
|
+
var listener = listeners[i3];
|
|
425
|
+
!listener.destroyed && listener.fn(added, removed);
|
|
423
426
|
}
|
|
424
427
|
}
|
|
425
428
|
};
|
|
426
429
|
/**
|
|
427
430
|
* @internal
|
|
428
431
|
*/ _proto._onDestroy = function _onDestroy() {
|
|
429
|
-
this._listeners.
|
|
432
|
+
this._listeners.findAndRemove(function(value) {
|
|
433
|
+
return value.destroyed = true;
|
|
434
|
+
});
|
|
430
435
|
};
|
|
431
436
|
_proto._handleEvent = function _handleEvent(event) {
|
|
432
437
|
var input = this._trackedDevices[event.input];
|
|
@@ -522,6 +527,7 @@ var XRTargetRayMode;
|
|
|
522
527
|
this._engine = _engine;
|
|
523
528
|
this._mode = XRSessionMode.None;
|
|
524
529
|
this._state = XRSessionState.None;
|
|
530
|
+
this._listeners = new SafeLoopArray();
|
|
525
531
|
// @ts-ignore
|
|
526
532
|
this._rhi = _engine._hardwareRenderer;
|
|
527
533
|
this._raf = requestAnimationFrame.bind(window);
|
|
@@ -544,7 +550,7 @@ var XRTargetRayMode;
|
|
|
544
550
|
throw new Error("Without session to run.");
|
|
545
551
|
}
|
|
546
552
|
platformSession.start();
|
|
547
|
-
this.
|
|
553
|
+
this._setState(XRSessionState.Running);
|
|
548
554
|
this._xrManager._onSessionStart();
|
|
549
555
|
if (!engine.isPaused) {
|
|
550
556
|
engine.pause();
|
|
@@ -564,7 +570,7 @@ var XRTargetRayMode;
|
|
|
564
570
|
rhi._mainFrameBuffer = null;
|
|
565
571
|
rhi._mainFrameWidth = rhi._mainFrameHeight = 0;
|
|
566
572
|
platformSession.stop();
|
|
567
|
-
this.
|
|
573
|
+
this._setState(XRSessionState.Paused);
|
|
568
574
|
this._xrManager._onSessionStop();
|
|
569
575
|
if (!engine.isPaused) {
|
|
570
576
|
engine.pause();
|
|
@@ -572,6 +578,32 @@ var XRTargetRayMode;
|
|
|
572
578
|
}
|
|
573
579
|
};
|
|
574
580
|
/**
|
|
581
|
+
* Add a listening function for session state changes.
|
|
582
|
+
* @param listener - The listening function
|
|
583
|
+
*/ _proto.addStateChangedListener = function addStateChangedListener(listener) {
|
|
584
|
+
this._listeners.push({
|
|
585
|
+
fn: listener
|
|
586
|
+
});
|
|
587
|
+
};
|
|
588
|
+
/**
|
|
589
|
+
* Remove a listening function of session state changes.
|
|
590
|
+
* @param listener - The listening function
|
|
591
|
+
*/ _proto.removeStateChangedListener = function removeStateChangedListener(listener) {
|
|
592
|
+
this._listeners.findAndRemove(function(value) {
|
|
593
|
+
return value.fn === listener ? value.destroyed = true : false;
|
|
594
|
+
});
|
|
595
|
+
};
|
|
596
|
+
/**
|
|
597
|
+
* @internal
|
|
598
|
+
*/ _proto._setState = function _setState(value) {
|
|
599
|
+
this._state = value;
|
|
600
|
+
var listeners = this._listeners.getLoopArray();
|
|
601
|
+
for(var i = 0, n = listeners.length; i < n; i++){
|
|
602
|
+
var listener = listeners[i];
|
|
603
|
+
!listener.destroyed && listener.fn(value);
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
/**
|
|
575
607
|
* @internal
|
|
576
608
|
*/ _proto._initialize = function _initialize(mode, features) {
|
|
577
609
|
var _this = this;
|
|
@@ -586,7 +618,7 @@ var XRTargetRayMode;
|
|
|
586
618
|
xrManager._platformDevice.requestSession(_this._rhi, mode, platformFeatures).then(function(platformSession) {
|
|
587
619
|
_this._mode = mode;
|
|
588
620
|
_this._platformSession = platformSession;
|
|
589
|
-
_this.
|
|
621
|
+
_this._setState(XRSessionState.Initialized);
|
|
590
622
|
platformSession.setSessionExitCallBack(_this._onSessionExit);
|
|
591
623
|
platformSession.addEventListener();
|
|
592
624
|
xrManager._onSessionInit();
|
|
@@ -635,7 +667,7 @@ var XRTargetRayMode;
|
|
|
635
667
|
rhi._mainFrameWidth = rhi._mainFrameHeight = 0;
|
|
636
668
|
platformSession.removeEventListener();
|
|
637
669
|
this._platformSession = null;
|
|
638
|
-
this.
|
|
670
|
+
this._setState(XRSessionState.None);
|
|
639
671
|
this._xrManager._onSessionExit();
|
|
640
672
|
if (!engine.isPaused) {
|
|
641
673
|
engine.pause();
|
|
@@ -644,7 +676,12 @@ var XRTargetRayMode;
|
|
|
644
676
|
};
|
|
645
677
|
/**
|
|
646
678
|
* @internal
|
|
647
|
-
*/ _proto._onDestroy = function _onDestroy() {
|
|
679
|
+
*/ _proto._onDestroy = function _onDestroy() {
|
|
680
|
+
this._listeners.findAndRemove(function(value) {
|
|
681
|
+
return value.destroyed = true;
|
|
682
|
+
});
|
|
683
|
+
this._raf = this._caf = null;
|
|
684
|
+
};
|
|
648
685
|
_create_class(XRSessionManager, [
|
|
649
686
|
{
|
|
650
687
|
key: "mode",
|
|
@@ -683,47 +720,36 @@ var XRTargetRayMode;
|
|
|
683
720
|
}();
|
|
684
721
|
|
|
685
722
|
/**
|
|
686
|
-
*
|
|
723
|
+
* @internal
|
|
687
724
|
*/ var XRManagerExtended = /*#__PURE__*/ function(XRManager1) {
|
|
688
725
|
_inherits(XRManagerExtended, XRManager1);
|
|
689
726
|
function XRManagerExtended() {
|
|
690
727
|
return XRManager1.apply(this, arguments);
|
|
691
728
|
}
|
|
692
729
|
var _proto = XRManagerExtended.prototype;
|
|
693
|
-
|
|
694
|
-
* Check if the specified feature is supported.
|
|
695
|
-
* @param type - The type of the feature
|
|
696
|
-
* @returns If the feature is supported
|
|
697
|
-
*/ _proto.isSupportedFeature = function isSupportedFeature(feature) {
|
|
730
|
+
_proto.isSupportedFeature = function isSupportedFeature(feature) {
|
|
698
731
|
return this._platformDevice.isSupportedFeature(XRManagerExtended._featureMap.get(feature));
|
|
699
732
|
};
|
|
700
|
-
|
|
701
|
-
* Add feature based on the xr feature type.
|
|
702
|
-
* @param type - The type of the feature
|
|
703
|
-
* @param args - The constructor params of the feature
|
|
704
|
-
* @returns The feature which has been added
|
|
705
|
-
*/ _proto.addFeature = function addFeature(type) {
|
|
733
|
+
_proto.addFeature = function addFeature(type) {
|
|
706
734
|
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
707
735
|
args[_key - 1] = arguments[_key];
|
|
708
736
|
}
|
|
709
737
|
if (this.sessionManager._platformSession) {
|
|
710
738
|
throw new Error("Cannot add feature when the session is initialized.");
|
|
711
739
|
}
|
|
712
|
-
|
|
740
|
+
if (!this._platformDevice.isSupportedFeature(XRManagerExtended._featureMap.get(type))) {
|
|
741
|
+
throw new Error("The feature is not supported");
|
|
742
|
+
}
|
|
743
|
+
var features = this.features;
|
|
713
744
|
for(var i = 0, n = features.length; i < n; i++){
|
|
714
|
-
|
|
715
|
-
if (_instanceof(feature, type)) throw new Error("The feature has been added");
|
|
745
|
+
if (_instanceof(features[i], type)) throw new Error("The feature has been added");
|
|
716
746
|
}
|
|
717
|
-
var
|
|
718
|
-
|
|
719
|
-
return
|
|
747
|
+
var feature = _construct(type, [].concat(this, args));
|
|
748
|
+
features.push(feature);
|
|
749
|
+
return feature;
|
|
720
750
|
};
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
* @param type - The type of the feature
|
|
724
|
-
* @returns The feature which match type
|
|
725
|
-
*/ _proto.getFeature = function getFeature(type) {
|
|
726
|
-
var _this = this, features = _this._features;
|
|
751
|
+
_proto.getFeature = function getFeature(type) {
|
|
752
|
+
var features = this.features;
|
|
727
753
|
for(var i = 0, n = features.length; i < n; i++){
|
|
728
754
|
var feature = features[i];
|
|
729
755
|
if (_instanceof(feature, type)) {
|
|
@@ -731,25 +757,7 @@ var XRTargetRayMode;
|
|
|
731
757
|
}
|
|
732
758
|
}
|
|
733
759
|
};
|
|
734
|
-
_proto.
|
|
735
|
-
if (out) {
|
|
736
|
-
out.length = 0;
|
|
737
|
-
} else {
|
|
738
|
-
out = [];
|
|
739
|
-
}
|
|
740
|
-
var _this = this, features = _this._features;
|
|
741
|
-
for(var i = 0, n = features.length; i < n; i--){
|
|
742
|
-
var feature = features[i];
|
|
743
|
-
_instanceof(feature, type) && out.push(feature);
|
|
744
|
-
}
|
|
745
|
-
return out;
|
|
746
|
-
};
|
|
747
|
-
/**
|
|
748
|
-
* Enter XR immersive mode, when you call this method, it will initialize and display the XR virtual world.
|
|
749
|
-
* @param sessionMode - The mode of the session
|
|
750
|
-
* @param autoRun - Whether to automatically run the session, when `autoRun` is set to true, xr will start working immediately after initialization. Otherwise, you need to call `sessionManager.run` later to work.
|
|
751
|
-
* @returns A promise that resolves if the XR virtual world is entered, otherwise rejects
|
|
752
|
-
*/ _proto.enterXR = function enterXR(sessionMode, autoRun) {
|
|
760
|
+
_proto.enterXR = function enterXR(sessionMode, autoRun) {
|
|
753
761
|
if (autoRun === void 0) autoRun = true;
|
|
754
762
|
var _this = this;
|
|
755
763
|
var sessionManager = this.sessionManager;
|
|
@@ -762,18 +770,16 @@ var XRTargetRayMode;
|
|
|
762
770
|
return new Promise(function(resolve, reject) {
|
|
763
771
|
// 1. Check if this xr mode is supported
|
|
764
772
|
sessionManager.isSupportedMode(sessionMode).then(function() {
|
|
773
|
+
sessionManager._setState(XRSessionState.Initializing);
|
|
765
774
|
// 2. Initialize session
|
|
766
|
-
sessionManager._initialize(sessionMode, _this.
|
|
775
|
+
sessionManager._initialize(sessionMode, _this.features).then(function() {
|
|
767
776
|
autoRun && sessionManager.run();
|
|
768
777
|
resolve();
|
|
769
778
|
}, reject);
|
|
770
779
|
}, reject);
|
|
771
780
|
});
|
|
772
781
|
};
|
|
773
|
-
|
|
774
|
-
* Exit XR immersive mode, when you call this method, it will destroy the XR virtual world.
|
|
775
|
-
* @returns A promise that resolves if the XR virtual world is destroyed, otherwise rejects
|
|
776
|
-
*/ _proto.exitXR = function exitXR() {
|
|
782
|
+
_proto.exitXR = function exitXR() {
|
|
777
783
|
var _this = this;
|
|
778
784
|
return new Promise(function(resolve, reject) {
|
|
779
785
|
_this.sessionManager._exit().then(function() {
|
|
@@ -781,32 +787,26 @@ var XRTargetRayMode;
|
|
|
781
787
|
}, reject);
|
|
782
788
|
});
|
|
783
789
|
};
|
|
784
|
-
|
|
785
|
-
* @internal
|
|
786
|
-
*/ _proto._initialize = function _initialize(engine, xrDevice) {
|
|
790
|
+
_proto._initialize = function _initialize(engine, xrDevice) {
|
|
787
791
|
this._features = [];
|
|
788
792
|
this._platformDevice = xrDevice;
|
|
789
793
|
this.sessionManager = new XRSessionManager(this, engine);
|
|
790
794
|
this.inputManager = new XRInputManager(this, engine);
|
|
791
795
|
this.cameraManager = new XRCameraManager(this);
|
|
792
796
|
};
|
|
793
|
-
|
|
794
|
-
* @internal
|
|
795
|
-
*/ _proto._update = function _update() {
|
|
797
|
+
_proto._update = function _update() {
|
|
796
798
|
var sessionManager = this.sessionManager;
|
|
797
799
|
if (sessionManager.state !== XRSessionState.Running) return;
|
|
798
800
|
sessionManager._onUpdate();
|
|
799
801
|
this.inputManager._onUpdate();
|
|
800
802
|
this.cameraManager._onUpdate();
|
|
801
|
-
var
|
|
803
|
+
var features = this.features;
|
|
802
804
|
for(var i = 0, n = features.length; i < n; i++){
|
|
803
805
|
var feature = features[i];
|
|
804
806
|
feature.enabled && feature._onUpdate();
|
|
805
807
|
}
|
|
806
808
|
};
|
|
807
|
-
|
|
808
|
-
* @internal
|
|
809
|
-
*/ _proto._destroy = function _destroy() {
|
|
809
|
+
_proto._destroy = function _destroy() {
|
|
810
810
|
var _this = this;
|
|
811
811
|
if (this.sessionManager._platformSession) {
|
|
812
812
|
this.exitXR().then(function() {
|
|
@@ -820,25 +820,19 @@ var XRTargetRayMode;
|
|
|
820
820
|
this.cameraManager._onDestroy();
|
|
821
821
|
}
|
|
822
822
|
};
|
|
823
|
-
|
|
824
|
-
* @internal
|
|
825
|
-
*/ _proto._getRequestAnimationFrame = function _getRequestAnimationFrame() {
|
|
823
|
+
_proto._getRequestAnimationFrame = function _getRequestAnimationFrame() {
|
|
826
824
|
return this.sessionManager._getRequestAnimationFrame();
|
|
827
825
|
};
|
|
828
|
-
|
|
829
|
-
* @internal
|
|
830
|
-
*/ _proto._getCancelAnimationFrame = function _getCancelAnimationFrame() {
|
|
826
|
+
_proto._getCancelAnimationFrame = function _getCancelAnimationFrame() {
|
|
831
827
|
return this.sessionManager._getCancelAnimationFrame();
|
|
832
828
|
};
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
*/ _proto._getCameraClearFlagsMask = function _getCameraClearFlagsMask(type) {
|
|
836
|
-
return this.cameraManager._getCameraClearFlagsMask(type);
|
|
829
|
+
_proto._getCameraIgnoreClearFlags = function _getCameraIgnoreClearFlags(type) {
|
|
830
|
+
return this.cameraManager._getIgnoreClearFlags(type);
|
|
837
831
|
};
|
|
838
832
|
/**
|
|
839
833
|
* @internal
|
|
840
834
|
*/ _proto._onSessionStop = function _onSessionStop() {
|
|
841
|
-
var
|
|
835
|
+
var features = this.features;
|
|
842
836
|
for(var i = 0, n = features.length; i < n; i++){
|
|
843
837
|
var feature = features[i];
|
|
844
838
|
feature.enabled && feature._onSessionStop();
|
|
@@ -847,7 +841,7 @@ var XRTargetRayMode;
|
|
|
847
841
|
/**
|
|
848
842
|
* @internal
|
|
849
843
|
*/ _proto._onSessionInit = function _onSessionInit() {
|
|
850
|
-
var
|
|
844
|
+
var features = this.features;
|
|
851
845
|
for(var i = 0, n = features.length; i < n; i++){
|
|
852
846
|
var feature = features[i];
|
|
853
847
|
feature.enabled && feature._onSessionInit();
|
|
@@ -857,7 +851,7 @@ var XRTargetRayMode;
|
|
|
857
851
|
* @internal
|
|
858
852
|
*/ _proto._onSessionStart = function _onSessionStart() {
|
|
859
853
|
this.cameraManager._onSessionStart();
|
|
860
|
-
var
|
|
854
|
+
var features = this.features;
|
|
861
855
|
for(var i = 0, n = features.length; i < n; i++){
|
|
862
856
|
var feature = features[i];
|
|
863
857
|
feature.enabled && feature._onSessionStart();
|
|
@@ -867,7 +861,7 @@ var XRTargetRayMode;
|
|
|
867
861
|
* @internal
|
|
868
862
|
*/ _proto._onSessionExit = function _onSessionExit() {
|
|
869
863
|
this.cameraManager._onSessionExit();
|
|
870
|
-
var
|
|
864
|
+
var features = this.features;
|
|
871
865
|
for(var i = 0, n = features.length; i < n; i++){
|
|
872
866
|
var feature = features[i];
|
|
873
867
|
feature.enabled && feature._onSessionExit();
|
|
@@ -876,12 +870,15 @@ var XRTargetRayMode;
|
|
|
876
870
|
features.length = 0;
|
|
877
871
|
};
|
|
878
872
|
_create_class(XRManagerExtended, [
|
|
873
|
+
{
|
|
874
|
+
key: "features",
|
|
875
|
+
get: function get() {
|
|
876
|
+
return this._features;
|
|
877
|
+
}
|
|
878
|
+
},
|
|
879
879
|
{
|
|
880
880
|
key: "origin",
|
|
881
|
-
get:
|
|
882
|
-
* The current origin of XR space.
|
|
883
|
-
* @remarks The connection point between the virtual world and the real world ( XR Space )
|
|
884
|
-
*/ function get() {
|
|
881
|
+
get: function get() {
|
|
885
882
|
return this._origin;
|
|
886
883
|
},
|
|
887
884
|
set: function set(value) {
|
|
@@ -974,50 +971,6 @@ ApplyMixins(XRManager, [
|
|
|
974
971
|
return XRFeature;
|
|
975
972
|
}();
|
|
976
973
|
|
|
977
|
-
/**
|
|
978
|
-
* Enum for the types of hit test that can be performed.
|
|
979
|
-
* Note: currently only supports plane.
|
|
980
|
-
*/ var TrackableType;
|
|
981
|
-
(function(TrackableType) {
|
|
982
|
-
TrackableType[TrackableType[/** Tracked plane. */ "Plane"] = 0x1] = "Plane";
|
|
983
|
-
TrackableType[TrackableType[/** All tracked objects. */ "All"] = 0x1] = "All";
|
|
984
|
-
})(TrackableType || (TrackableType = {}));
|
|
985
|
-
|
|
986
|
-
/**
|
|
987
|
-
* XR hit result.
|
|
988
|
-
* It is the detection result returned by using XR HitTest feature.
|
|
989
|
-
*/ var XRHitResult = function XRHitResult() {
|
|
990
|
-
/** The position of the hit point. */ this.point = new Vector3();
|
|
991
|
-
/** The normal of the hit point. */ this.normal = new Vector3();
|
|
992
|
-
};
|
|
993
|
-
|
|
994
|
-
/******************************************************************************
|
|
995
|
-
Copyright (c) Microsoft Corporation.
|
|
996
|
-
|
|
997
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
998
|
-
purpose with or without fee is hereby granted.
|
|
999
|
-
|
|
1000
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1001
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1002
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1003
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1004
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1005
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1006
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
1007
|
-
***************************************************************************** */
|
|
1008
|
-
|
|
1009
|
-
function __decorate(decorators, target, key, desc) {
|
|
1010
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1011
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1012
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1013
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
1017
|
-
var e = new Error(message);
|
|
1018
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1019
|
-
};
|
|
1020
|
-
|
|
1021
974
|
var XRFeatureType;
|
|
1022
975
|
(function(XRFeatureType) {
|
|
1023
976
|
XRFeatureType[XRFeatureType["AnchorTracking"] = 0] = "AnchorTracking";
|
|
@@ -1049,7 +1002,7 @@ var XRRequestTrackingState;
|
|
|
1049
1002
|
_this._updated = [];
|
|
1050
1003
|
_this._removed = [];
|
|
1051
1004
|
_this._statusSnapshot = {};
|
|
1052
|
-
_this._listeners =
|
|
1005
|
+
_this._listeners = new SafeLoopArray();
|
|
1053
1006
|
return _this;
|
|
1054
1007
|
}
|
|
1055
1008
|
var _proto = XRTrackableFeature.prototype;
|
|
@@ -1057,22 +1010,22 @@ var XRRequestTrackingState;
|
|
|
1057
1010
|
* Add a listening function for tracked object changes.
|
|
1058
1011
|
* @param listener - The listening function
|
|
1059
1012
|
*/ _proto.addChangedListener = function addChangedListener(listener) {
|
|
1060
|
-
this._listeners.push(
|
|
1013
|
+
this._listeners.push({
|
|
1014
|
+
fn: listener
|
|
1015
|
+
});
|
|
1061
1016
|
};
|
|
1062
1017
|
/**
|
|
1063
1018
|
* Remove a listening function of tracked object changes.
|
|
1064
1019
|
* @param listener - The listening function
|
|
1065
1020
|
*/ _proto.removeChangedListener = function removeChangedListener(listener) {
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
listeners.splice(index, 1);
|
|
1070
|
-
}
|
|
1021
|
+
this._listeners.findAndRemove(function(value) {
|
|
1022
|
+
return value.fn === listener ? value.destroyed = true : false;
|
|
1023
|
+
});
|
|
1071
1024
|
};
|
|
1072
1025
|
_proto._onUpdate = function _onUpdate() {
|
|
1073
1026
|
var _this__xrManager_sessionManager = this._xrManager.sessionManager, platformSession = _this__xrManager_sessionManager._platformSession;
|
|
1074
1027
|
var platformFrame = platformSession.frame;
|
|
1075
|
-
var _this = this, platformFeature = _this._platformFeature,
|
|
1028
|
+
var _this = this, platformFeature = _this._platformFeature, requestTrackings = _this._requestTrackings, statusSnapshot = _this._statusSnapshot, allTracked = _this._tracked, added = _this._added, updated = _this._updated, removed = _this._removed;
|
|
1076
1029
|
if (!platformFrame || !requestTrackings.length) {
|
|
1077
1030
|
return;
|
|
1078
1031
|
}
|
|
@@ -1124,8 +1077,10 @@ var XRRequestTrackingState;
|
|
|
1124
1077
|
requestTrackings[i1].state === XRRequestTrackingState.Destroyed && requestTrackings.splice(i1, 1);
|
|
1125
1078
|
}
|
|
1126
1079
|
if (added.length > 0 || updated.length > 0 || removed.length > 0) {
|
|
1080
|
+
var listeners = this._listeners.getLoopArray();
|
|
1127
1081
|
for(var i2 = 0, n3 = listeners.length; i2 < n3; i2++){
|
|
1128
|
-
listeners[i2]
|
|
1082
|
+
var listener = listeners[i2];
|
|
1083
|
+
!listener.destroyed && listener.fn(added, updated, removed);
|
|
1129
1084
|
}
|
|
1130
1085
|
}
|
|
1131
1086
|
};
|
|
@@ -1135,10 +1090,9 @@ var XRRequestTrackingState;
|
|
|
1135
1090
|
_proto._onSessionExit = function _onSessionExit() {
|
|
1136
1091
|
// prettier-ignore
|
|
1137
1092
|
this._requestTrackings.length = this._tracked.length = this._added.length = this._updated.length = this._removed.length = 0;
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
this._requestTrackings.length = this._tracked.length = this._added.length = this._updated.length = this._removed.length = 0;
|
|
1093
|
+
this._listeners.findAndRemove(function(value) {
|
|
1094
|
+
return value.destroyed = true;
|
|
1095
|
+
});
|
|
1142
1096
|
};
|
|
1143
1097
|
_proto._addRequestTracking = function _addRequestTracking(requestTracking) {
|
|
1144
1098
|
var _this = this, platformFeature = _this._platformFeature;
|
|
@@ -1171,6 +1125,57 @@ var XRRequestTrackingState;
|
|
|
1171
1125
|
XRTrackableFeature._uuid = 0;
|
|
1172
1126
|
})();
|
|
1173
1127
|
|
|
1128
|
+
/**
|
|
1129
|
+
* The base class of XR tracked object.
|
|
1130
|
+
*/ var XRTracked = function XRTracked() {
|
|
1131
|
+
/** The pose of the trackable in XR space. */ this.pose = new XRPose();
|
|
1132
|
+
/** The tracking state of the trackable. */ this.state = XRTrackingState.NotTracking;
|
|
1133
|
+
};
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* Enum for the types of hit test that can be performed.
|
|
1137
|
+
* Note: currently only supports plane.
|
|
1138
|
+
*/ var TrackableType;
|
|
1139
|
+
(function(TrackableType) {
|
|
1140
|
+
TrackableType[TrackableType[/** Tracked plane. */ "Plane"] = 0x1] = "Plane";
|
|
1141
|
+
TrackableType[TrackableType[/** All tracked objects. */ "All"] = 0x1] = "All";
|
|
1142
|
+
})(TrackableType || (TrackableType = {}));
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* XR hit result.
|
|
1146
|
+
* It is the detection result returned by using XR HitTest feature.
|
|
1147
|
+
*/ var XRHitResult = function XRHitResult() {
|
|
1148
|
+
/** The position of the hit point. */ this.point = new Vector3();
|
|
1149
|
+
/** The normal of the hit point. */ this.normal = new Vector3();
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1152
|
+
/******************************************************************************
|
|
1153
|
+
Copyright (c) Microsoft Corporation.
|
|
1154
|
+
|
|
1155
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
1156
|
+
purpose with or without fee is hereby granted.
|
|
1157
|
+
|
|
1158
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1159
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1160
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1161
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1162
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1163
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1164
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
1165
|
+
***************************************************************************** */
|
|
1166
|
+
|
|
1167
|
+
function __decorate(decorators, target, key, desc) {
|
|
1168
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1169
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1170
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1171
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
1175
|
+
var e = new Error(message);
|
|
1176
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1174
1179
|
/**
|
|
1175
1180
|
* Enumerates modes of plane in XR.
|
|
1176
1181
|
*/ var XRPlaneMode;
|
|
@@ -1201,13 +1206,6 @@ var XRRequestTrackingState;
|
|
|
1201
1206
|
return XRRequestPlane;
|
|
1202
1207
|
}(XRRequestTracking);
|
|
1203
1208
|
|
|
1204
|
-
/**
|
|
1205
|
-
* The base class of XR tracked object.
|
|
1206
|
-
*/ var XRTracked = function XRTracked() {
|
|
1207
|
-
/** The pose of the trackable in XR space. */ this.pose = new XRPose();
|
|
1208
|
-
/** The tracking state of the trackable. */ this.state = XRTrackingState.NotTracking;
|
|
1209
|
-
};
|
|
1210
|
-
|
|
1211
1209
|
/**
|
|
1212
1210
|
* The tracked plane in XR space.
|
|
1213
1211
|
*/ var XRTrackedPlane = /*#__PURE__*/ function(XRTracked1) {
|
|
@@ -1555,5 +1553,63 @@ XRImageTracking = __decorate([
|
|
|
1555
1553
|
this.physicalWidth = physicalWidth;
|
|
1556
1554
|
};
|
|
1557
1555
|
|
|
1558
|
-
|
|
1556
|
+
var XRReferenceImageDecoder = /*#__PURE__*/ function() {
|
|
1557
|
+
function XRReferenceImageDecoder() {}
|
|
1558
|
+
XRReferenceImageDecoder.decode = function decode(engine, bufferReader) {
|
|
1559
|
+
return new Promise(function(resolve, reject) {
|
|
1560
|
+
var physicalWidth = bufferReader.nextFloat32();
|
|
1561
|
+
bufferReader.nextUint8();
|
|
1562
|
+
var img = new Image();
|
|
1563
|
+
img.onload = function() {
|
|
1564
|
+
resolve(new XRReferenceImage("", img, physicalWidth));
|
|
1565
|
+
};
|
|
1566
|
+
img.src = URL.createObjectURL(new window.Blob([
|
|
1567
|
+
bufferReader.nextImagesData(1)[0]
|
|
1568
|
+
]));
|
|
1569
|
+
});
|
|
1570
|
+
};
|
|
1571
|
+
return XRReferenceImageDecoder;
|
|
1572
|
+
}();
|
|
1573
|
+
XRReferenceImageDecoder = __decorate([
|
|
1574
|
+
decoder("XRReferenceImage")
|
|
1575
|
+
], XRReferenceImageDecoder);
|
|
1576
|
+
|
|
1577
|
+
function _extends() {
|
|
1578
|
+
_extends = Object.assign || function assign(target) {
|
|
1579
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
1580
|
+
var source = arguments[i];
|
|
1581
|
+
for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
return target;
|
|
1585
|
+
};
|
|
1586
|
+
|
|
1587
|
+
return _extends.apply(this, arguments);
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
var XRReferenceImageLoader = /*#__PURE__*/ function(Loader1) {
|
|
1591
|
+
_inherits(XRReferenceImageLoader, Loader1);
|
|
1592
|
+
function XRReferenceImageLoader() {
|
|
1593
|
+
return Loader1.apply(this, arguments);
|
|
1594
|
+
}
|
|
1595
|
+
var _proto = XRReferenceImageLoader.prototype;
|
|
1596
|
+
_proto.load = function load(item, resourceManager) {
|
|
1597
|
+
var _this = this;
|
|
1598
|
+
return new AssetPromise(function(resolve, reject) {
|
|
1599
|
+
_this.request(item.url, _extends({}, item, {
|
|
1600
|
+
type: "arraybuffer"
|
|
1601
|
+
})).then(function(data) {
|
|
1602
|
+
decode(data, resourceManager.engine).then(function(referenceImage) {
|
|
1603
|
+
resolve(referenceImage);
|
|
1604
|
+
});
|
|
1605
|
+
}).catch(reject);
|
|
1606
|
+
});
|
|
1607
|
+
};
|
|
1608
|
+
return XRReferenceImageLoader;
|
|
1609
|
+
}(Loader);
|
|
1610
|
+
XRReferenceImageLoader = __decorate([
|
|
1611
|
+
resourceLoader("XRReferenceImage", [])
|
|
1612
|
+
], XRReferenceImageLoader);
|
|
1613
|
+
|
|
1614
|
+
export { TrackableType, XRAnchor, XRAnchorTracking, XRCamera, XRCameraManager, XRController, XRFeature, XRFeatureType, XRHitResult, XRHitTest, XRImageTracking, XRInputButton, XRInputEventType, XRInputManager, XRPlaneMode, XRPlaneTracking, XRPose, XRReferenceImage, XRReferenceImageDecoder, XRReferenceImageLoader, XRRequestTrackingState, XRSessionManager, XRSessionMode, XRSessionState, XRTargetRayMode, XRTrackableFeature, XRTracked, XRTrackedImage, XRTrackedInputDevice, XRTrackedPlane, XRTrackingState };
|
|
1559
1615
|
//# sourceMappingURL=module.js.map
|