@galacean/engine-xr 0.0.0-experimental-1.3-xr.5 → 0.0.0-experimental-1.3-xr.8
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 +61 -308
- 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 +61 -308
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +61 -308
- package/dist/module.js +63 -310
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/XRManagerExtended.d.ts +6 -51
- package/types/index.d.ts +0 -1
- package/types/session/XRSessionManager.d.ts +2 -2
- package/types/session/XRSessionState.d.ts +2 -2
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CameraType, Matrix, CameraClearFlags, Vector3, Quaternion, Rect, XRManager, Ray, Plane, Vector2, decoder, resourceLoader, AssetPromise, decode, Loader
|
|
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,7 +95,7 @@ function _instanceof(left, right) {
|
|
|
95
95
|
*/ var XRSessionState;
|
|
96
96
|
(function(XRSessionState) {
|
|
97
97
|
XRSessionState[XRSessionState[/** Not initialized. */ "None"] = 0] = "None";
|
|
98
|
-
XRSessionState[XRSessionState[/**
|
|
98
|
+
XRSessionState[XRSessionState[/** Initializing session. */ "Initializing"] = 1] = "Initializing";
|
|
99
99
|
XRSessionState[XRSessionState[/** Initialized but not started. */ "Initialized"] = 2] = "Initialized";
|
|
100
100
|
XRSessionState[XRSessionState[/** Running. */ "Running"] = 3] = "Running";
|
|
101
101
|
XRSessionState[XRSessionState[/** Paused. */ "Paused"] = 4] = "Paused";
|
|
@@ -523,7 +523,7 @@ var XRTargetRayMode;
|
|
|
523
523
|
this._engine = _engine;
|
|
524
524
|
this._mode = XRSessionMode.None;
|
|
525
525
|
this._state = XRSessionState.None;
|
|
526
|
-
this._listeners =
|
|
526
|
+
this._listeners = new SafeLoopArray();
|
|
527
527
|
// @ts-ignore
|
|
528
528
|
this._rhi = _engine._hardwareRenderer;
|
|
529
529
|
this._raf = requestAnimationFrame.bind(window);
|
|
@@ -546,7 +546,7 @@ var XRTargetRayMode;
|
|
|
546
546
|
throw new Error("Without session to run.");
|
|
547
547
|
}
|
|
548
548
|
platformSession.start();
|
|
549
|
-
this.
|
|
549
|
+
this._setState(XRSessionState.Running);
|
|
550
550
|
this._xrManager._onSessionStart();
|
|
551
551
|
if (!engine.isPaused) {
|
|
552
552
|
engine.pause();
|
|
@@ -566,7 +566,7 @@ var XRTargetRayMode;
|
|
|
566
566
|
rhi._mainFrameBuffer = null;
|
|
567
567
|
rhi._mainFrameWidth = rhi._mainFrameHeight = 0;
|
|
568
568
|
platformSession.stop();
|
|
569
|
-
this.
|
|
569
|
+
this._setState(XRSessionState.Paused);
|
|
570
570
|
this._xrManager._onSessionStop();
|
|
571
571
|
if (!engine.isPaused) {
|
|
572
572
|
engine.pause();
|
|
@@ -576,17 +576,27 @@ var XRTargetRayMode;
|
|
|
576
576
|
/**
|
|
577
577
|
* Add a listening function for session state changes.
|
|
578
578
|
* @param listener - The listening function
|
|
579
|
-
*/ _proto.
|
|
580
|
-
this._listeners.push(
|
|
579
|
+
*/ _proto.addStateChangedListener = function addStateChangedListener(listener) {
|
|
580
|
+
this._listeners.push({
|
|
581
|
+
fn: listener
|
|
582
|
+
});
|
|
581
583
|
};
|
|
582
584
|
/**
|
|
583
585
|
* Remove a listening function of session state changes.
|
|
584
586
|
* @param listener - The listening function
|
|
585
|
-
*/ _proto.
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
587
|
+
*/ _proto.removeStateChangedListener = function removeStateChangedListener(listener) {
|
|
588
|
+
this._listeners.findAndRemove(function(value) {
|
|
589
|
+
return value.fn === listener ? value.destroyed = true : false;
|
|
590
|
+
});
|
|
591
|
+
};
|
|
592
|
+
/**
|
|
593
|
+
* @internal
|
|
594
|
+
*/ _proto._setState = function _setState(value) {
|
|
595
|
+
this._state = value;
|
|
596
|
+
var listeners = this._listeners.getLoopArray();
|
|
597
|
+
for(var i = 0, n = listeners.length; i < n; i++){
|
|
598
|
+
var listener = listeners[i];
|
|
599
|
+
!listener.destroyed && listener.fn(value);
|
|
590
600
|
}
|
|
591
601
|
};
|
|
592
602
|
/**
|
|
@@ -604,7 +614,7 @@ var XRTargetRayMode;
|
|
|
604
614
|
xrManager._platformDevice.requestSession(_this._rhi, mode, platformFeatures).then(function(platformSession) {
|
|
605
615
|
_this._mode = mode;
|
|
606
616
|
_this._platformSession = platformSession;
|
|
607
|
-
_this.
|
|
617
|
+
_this._setState(XRSessionState.Initialized);
|
|
608
618
|
platformSession.setSessionExitCallBack(_this._onSessionExit);
|
|
609
619
|
platformSession.addEventListener();
|
|
610
620
|
xrManager._onSessionInit();
|
|
@@ -653,7 +663,7 @@ var XRTargetRayMode;
|
|
|
653
663
|
rhi._mainFrameWidth = rhi._mainFrameHeight = 0;
|
|
654
664
|
platformSession.removeEventListener();
|
|
655
665
|
this._platformSession = null;
|
|
656
|
-
this.
|
|
666
|
+
this._setState(XRSessionState.None);
|
|
657
667
|
this._xrManager._onSessionExit();
|
|
658
668
|
if (!engine.isPaused) {
|
|
659
669
|
engine.pause();
|
|
@@ -662,7 +672,12 @@ var XRTargetRayMode;
|
|
|
662
672
|
};
|
|
663
673
|
/**
|
|
664
674
|
* @internal
|
|
665
|
-
*/ _proto._onDestroy = function _onDestroy() {
|
|
675
|
+
*/ _proto._onDestroy = function _onDestroy() {
|
|
676
|
+
this._listeners.findAndRemove(function(value) {
|
|
677
|
+
return value.destroyed = true;
|
|
678
|
+
});
|
|
679
|
+
this._raf = this._caf = null;
|
|
680
|
+
};
|
|
666
681
|
_create_class(XRSessionManager, [
|
|
667
682
|
{
|
|
668
683
|
key: "mode",
|
|
@@ -678,15 +693,6 @@ var XRTargetRayMode;
|
|
|
678
693
|
* Return the current session state.
|
|
679
694
|
*/ function get() {
|
|
680
695
|
return this._state;
|
|
681
|
-
},
|
|
682
|
-
set: /**
|
|
683
|
-
* @internal
|
|
684
|
-
*/ function set(value) {
|
|
685
|
-
this._state = value;
|
|
686
|
-
var listeners = this._listeners;
|
|
687
|
-
for(var i = 0, n = listeners.length; i < n; i++){
|
|
688
|
-
listeners[i](value);
|
|
689
|
-
}
|
|
690
696
|
}
|
|
691
697
|
},
|
|
692
698
|
{
|
|
@@ -710,26 +716,20 @@ var XRTargetRayMode;
|
|
|
710
716
|
}();
|
|
711
717
|
|
|
712
718
|
/**
|
|
713
|
-
*
|
|
719
|
+
* @internal
|
|
714
720
|
*/ var XRManagerExtended = /*#__PURE__*/ function(XRManager1) {
|
|
715
721
|
_inherits(XRManagerExtended, XRManager1);
|
|
716
722
|
function XRManagerExtended() {
|
|
717
|
-
|
|
723
|
+
var _this;
|
|
724
|
+
_this = XRManager1.apply(this, arguments) || this;
|
|
725
|
+
_this.features = [];
|
|
726
|
+
return _this;
|
|
718
727
|
}
|
|
719
728
|
var _proto = XRManagerExtended.prototype;
|
|
720
|
-
|
|
721
|
-
* Check if the specified feature is supported.
|
|
722
|
-
* @param type - The type of the feature
|
|
723
|
-
* @returns If the feature is supported
|
|
724
|
-
*/ _proto.isSupportedFeature = function isSupportedFeature(feature) {
|
|
729
|
+
_proto.isSupportedFeature = function isSupportedFeature(feature) {
|
|
725
730
|
return this._platformDevice.isSupportedFeature(XRManagerExtended._featureMap.get(feature));
|
|
726
731
|
};
|
|
727
|
-
|
|
728
|
-
* Add feature based on the xr feature type.
|
|
729
|
-
* @param type - The type of the feature
|
|
730
|
-
* @param args - The constructor params of the feature
|
|
731
|
-
* @returns The feature which has been added
|
|
732
|
-
*/ _proto.addFeature = function addFeature(type) {
|
|
732
|
+
_proto.addFeature = function addFeature(type) {
|
|
733
733
|
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
734
734
|
args[_key - 1] = arguments[_key];
|
|
735
735
|
}
|
|
@@ -747,11 +747,7 @@ var XRTargetRayMode;
|
|
|
747
747
|
features.push(feature);
|
|
748
748
|
return feature;
|
|
749
749
|
};
|
|
750
|
-
|
|
751
|
-
* Get feature which match the type.
|
|
752
|
-
* @param type - The type of the feature
|
|
753
|
-
* @returns The feature which match type
|
|
754
|
-
*/ _proto.getFeature = function getFeature(type) {
|
|
750
|
+
_proto.getFeature = function getFeature(type) {
|
|
755
751
|
var features = this.features;
|
|
756
752
|
for(var i = 0, n = features.length; i < n; i++){
|
|
757
753
|
var feature = features[i];
|
|
@@ -760,12 +756,7 @@ var XRTargetRayMode;
|
|
|
760
756
|
}
|
|
761
757
|
}
|
|
762
758
|
};
|
|
763
|
-
|
|
764
|
-
* Enter XR immersive mode, when you call this method, it will initialize and display the XR virtual world.
|
|
765
|
-
* @param sessionMode - The mode of the session
|
|
766
|
-
* @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.
|
|
767
|
-
* @returns A promise that resolves if the XR virtual world is entered, otherwise rejects
|
|
768
|
-
*/ _proto.enterXR = function enterXR(sessionMode, autoRun) {
|
|
759
|
+
_proto.enterXR = function enterXR(sessionMode, autoRun) {
|
|
769
760
|
if (autoRun === void 0) autoRun = true;
|
|
770
761
|
var _this = this;
|
|
771
762
|
var sessionManager = this.sessionManager;
|
|
@@ -778,7 +769,7 @@ var XRTargetRayMode;
|
|
|
778
769
|
return new Promise(function(resolve, reject) {
|
|
779
770
|
// 1. Check if this xr mode is supported
|
|
780
771
|
sessionManager.isSupportedMode(sessionMode).then(function() {
|
|
781
|
-
sessionManager.
|
|
772
|
+
sessionManager._setState(XRSessionState.Initializing);
|
|
782
773
|
// 2. Initialize session
|
|
783
774
|
sessionManager._initialize(sessionMode, _this.features).then(function() {
|
|
784
775
|
autoRun && sessionManager.run();
|
|
@@ -787,10 +778,7 @@ var XRTargetRayMode;
|
|
|
787
778
|
}, reject);
|
|
788
779
|
});
|
|
789
780
|
};
|
|
790
|
-
|
|
791
|
-
* Exit XR immersive mode, when you call this method, it will destroy the XR virtual world.
|
|
792
|
-
* @returns A promise that resolves if the XR virtual world is destroyed, otherwise rejects
|
|
793
|
-
*/ _proto.exitXR = function exitXR() {
|
|
781
|
+
_proto.exitXR = function exitXR() {
|
|
794
782
|
var _this = this;
|
|
795
783
|
return new Promise(function(resolve, reject) {
|
|
796
784
|
_this.sessionManager._exit().then(function() {
|
|
@@ -798,18 +786,13 @@ var XRTargetRayMode;
|
|
|
798
786
|
}, reject);
|
|
799
787
|
});
|
|
800
788
|
};
|
|
801
|
-
|
|
802
|
-
* @internal
|
|
803
|
-
*/ _proto._initialize = function _initialize(engine, xrDevice) {
|
|
804
|
-
this.features.length = 0;
|
|
789
|
+
_proto._initialize = function _initialize(engine, xrDevice) {
|
|
805
790
|
this._platformDevice = xrDevice;
|
|
806
791
|
this.sessionManager = new XRSessionManager(this, engine);
|
|
807
792
|
this.inputManager = new XRInputManager(this, engine);
|
|
808
793
|
this.cameraManager = new XRCameraManager(this);
|
|
809
794
|
};
|
|
810
|
-
|
|
811
|
-
* @internal
|
|
812
|
-
*/ _proto._update = function _update() {
|
|
795
|
+
_proto._update = function _update() {
|
|
813
796
|
var sessionManager = this.sessionManager;
|
|
814
797
|
if (sessionManager.state !== XRSessionState.Running) return;
|
|
815
798
|
sessionManager._onUpdate();
|
|
@@ -821,9 +804,7 @@ var XRTargetRayMode;
|
|
|
821
804
|
feature.enabled && feature._onUpdate();
|
|
822
805
|
}
|
|
823
806
|
};
|
|
824
|
-
|
|
825
|
-
* @internal
|
|
826
|
-
*/ _proto._destroy = function _destroy() {
|
|
807
|
+
_proto._destroy = function _destroy() {
|
|
827
808
|
var _this = this;
|
|
828
809
|
if (this.sessionManager._platformSession) {
|
|
829
810
|
this.exitXR().then(function() {
|
|
@@ -837,19 +818,13 @@ var XRTargetRayMode;
|
|
|
837
818
|
this.cameraManager._onDestroy();
|
|
838
819
|
}
|
|
839
820
|
};
|
|
840
|
-
|
|
841
|
-
* @internal
|
|
842
|
-
*/ _proto._getRequestAnimationFrame = function _getRequestAnimationFrame() {
|
|
821
|
+
_proto._getRequestAnimationFrame = function _getRequestAnimationFrame() {
|
|
843
822
|
return this.sessionManager._getRequestAnimationFrame();
|
|
844
823
|
};
|
|
845
|
-
|
|
846
|
-
* @internal
|
|
847
|
-
*/ _proto._getCancelAnimationFrame = function _getCancelAnimationFrame() {
|
|
824
|
+
_proto._getCancelAnimationFrame = function _getCancelAnimationFrame() {
|
|
848
825
|
return this.sessionManager._getCancelAnimationFrame();
|
|
849
826
|
};
|
|
850
|
-
|
|
851
|
-
* @internal
|
|
852
|
-
*/ _proto._getCameraClearFlagsMask = function _getCameraClearFlagsMask(type) {
|
|
827
|
+
_proto._getCameraClearFlagsMask = function _getCameraClearFlagsMask(type) {
|
|
853
828
|
return this.cameraManager._getCameraClearFlagsMask(type);
|
|
854
829
|
};
|
|
855
830
|
/**
|
|
@@ -895,10 +870,7 @@ var XRTargetRayMode;
|
|
|
895
870
|
_create_class(XRManagerExtended, [
|
|
896
871
|
{
|
|
897
872
|
key: "origin",
|
|
898
|
-
get:
|
|
899
|
-
* The current origin of XR space.
|
|
900
|
-
* @remarks The connection point between the virtual world and the real world ( XR Space )
|
|
901
|
-
*/ function get() {
|
|
873
|
+
get: function get() {
|
|
902
874
|
return this._origin;
|
|
903
875
|
},
|
|
904
876
|
set: function set(value) {
|
|
@@ -1022,7 +994,7 @@ var XRRequestTrackingState;
|
|
|
1022
994
|
_this._updated = [];
|
|
1023
995
|
_this._removed = [];
|
|
1024
996
|
_this._statusSnapshot = {};
|
|
1025
|
-
_this._listeners =
|
|
997
|
+
_this._listeners = new SafeLoopArray();
|
|
1026
998
|
return _this;
|
|
1027
999
|
}
|
|
1028
1000
|
var _proto = XRTrackableFeature.prototype;
|
|
@@ -1030,22 +1002,22 @@ var XRRequestTrackingState;
|
|
|
1030
1002
|
* Add a listening function for tracked object changes.
|
|
1031
1003
|
* @param listener - The listening function
|
|
1032
1004
|
*/ _proto.addChangedListener = function addChangedListener(listener) {
|
|
1033
|
-
this._listeners.push(
|
|
1005
|
+
this._listeners.push({
|
|
1006
|
+
fn: listener
|
|
1007
|
+
});
|
|
1034
1008
|
};
|
|
1035
1009
|
/**
|
|
1036
1010
|
* Remove a listening function of tracked object changes.
|
|
1037
1011
|
* @param listener - The listening function
|
|
1038
1012
|
*/ _proto.removeChangedListener = function removeChangedListener(listener) {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
listeners.splice(index, 1);
|
|
1043
|
-
}
|
|
1013
|
+
this._listeners.findAndRemove(function(value) {
|
|
1014
|
+
return value.fn === listener ? value.destroyed = true : false;
|
|
1015
|
+
});
|
|
1044
1016
|
};
|
|
1045
1017
|
_proto._onUpdate = function _onUpdate() {
|
|
1046
1018
|
var _this__xrManager_sessionManager = this._xrManager.sessionManager, platformSession = _this__xrManager_sessionManager._platformSession;
|
|
1047
1019
|
var platformFrame = platformSession.frame;
|
|
1048
|
-
var _this = this, platformFeature = _this._platformFeature,
|
|
1020
|
+
var _this = this, platformFeature = _this._platformFeature, requestTrackings = _this._requestTrackings, statusSnapshot = _this._statusSnapshot, allTracked = _this._tracked, added = _this._added, updated = _this._updated, removed = _this._removed;
|
|
1049
1021
|
if (!platformFrame || !requestTrackings.length) {
|
|
1050
1022
|
return;
|
|
1051
1023
|
}
|
|
@@ -1097,8 +1069,10 @@ var XRRequestTrackingState;
|
|
|
1097
1069
|
requestTrackings[i1].state === XRRequestTrackingState.Destroyed && requestTrackings.splice(i1, 1);
|
|
1098
1070
|
}
|
|
1099
1071
|
if (added.length > 0 || updated.length > 0 || removed.length > 0) {
|
|
1072
|
+
var listeners = this._listeners.getLoopArray();
|
|
1100
1073
|
for(var i2 = 0, n3 = listeners.length; i2 < n3; i2++){
|
|
1101
|
-
listeners[i2]
|
|
1074
|
+
var listener = listeners[i2];
|
|
1075
|
+
!listener.destroyed && listener.fn(added, updated, removed);
|
|
1102
1076
|
}
|
|
1103
1077
|
}
|
|
1104
1078
|
};
|
|
@@ -1108,6 +1082,9 @@ var XRRequestTrackingState;
|
|
|
1108
1082
|
_proto._onSessionExit = function _onSessionExit() {
|
|
1109
1083
|
// prettier-ignore
|
|
1110
1084
|
this._requestTrackings.length = this._tracked.length = this._added.length = this._updated.length = this._removed.length = 0;
|
|
1085
|
+
this._listeners.findAndRemove(function(value) {
|
|
1086
|
+
return value.destroyed = true;
|
|
1087
|
+
});
|
|
1111
1088
|
};
|
|
1112
1089
|
_proto._addRequestTracking = function _addRequestTracking(requestTracking) {
|
|
1113
1090
|
var _this = this, platformFeature = _this._platformFeature;
|
|
@@ -1186,34 +1163,6 @@ function __decorate(decorators, target, key, desc) {
|
|
|
1186
1163
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1187
1164
|
}
|
|
1188
1165
|
|
|
1189
|
-
function __generator(thisArg, body) {
|
|
1190
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
1191
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
1192
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
1193
|
-
function step(op) {
|
|
1194
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
1195
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
1196
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
1197
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
1198
|
-
switch (op[0]) {
|
|
1199
|
-
case 0: case 1: t = op; break;
|
|
1200
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
1201
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
1202
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
1203
|
-
default:
|
|
1204
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
1205
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
1206
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
1207
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
1208
|
-
if (t[2]) _.ops.pop();
|
|
1209
|
-
_.trys.pop(); continue;
|
|
1210
|
-
}
|
|
1211
|
-
op = body.call(thisArg, _);
|
|
1212
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
1213
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
1166
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
1218
1167
|
var e = new Error(message);
|
|
1219
1168
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
@@ -1654,201 +1603,5 @@ XRReferenceImageLoader = __decorate([
|
|
|
1654
1603
|
resourceLoader("XRReferenceImage", [])
|
|
1655
1604
|
], XRReferenceImageLoader);
|
|
1656
1605
|
|
|
1657
|
-
|
|
1658
|
-
try {
|
|
1659
|
-
var info = gen[key](arg);
|
|
1660
|
-
var value = info.value;
|
|
1661
|
-
} catch (error) {
|
|
1662
|
-
reject(error);
|
|
1663
|
-
return;
|
|
1664
|
-
}
|
|
1665
|
-
if (info.done) resolve(value);
|
|
1666
|
-
else Promise.resolve(value).then(_next, _throw);
|
|
1667
|
-
}
|
|
1668
|
-
function _async_to_generator(fn) {
|
|
1669
|
-
return function() {
|
|
1670
|
-
var self = this, args = arguments;
|
|
1671
|
-
|
|
1672
|
-
return new Promise(function(resolve, reject) {
|
|
1673
|
-
var gen = fn.apply(self, args);
|
|
1674
|
-
|
|
1675
|
-
function _next(value) {
|
|
1676
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
|
-
function _throw(err) {
|
|
1680
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
_next(undefined);
|
|
1684
|
-
});
|
|
1685
|
-
};
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
var XRSceneExtendParser = /*#__PURE__*/ function() {
|
|
1689
|
-
function XRSceneExtendParser() {}
|
|
1690
|
-
XRSceneExtendParser.parse = function parse(engine, context, data) {
|
|
1691
|
-
return _async_to_generator(function() {
|
|
1692
|
-
var xrManager, xr, origin, camera, leftCamera, rightCamera, features, entityMap, cameraManager, i, n, feature, _;
|
|
1693
|
-
return __generator(this, function(_state) {
|
|
1694
|
-
switch(_state.label){
|
|
1695
|
-
case 0:
|
|
1696
|
-
xrManager = engine.xrManager;
|
|
1697
|
-
if (!xrManager) {
|
|
1698
|
-
Logger.error("XRManager is not found in the engine.");
|
|
1699
|
-
return [
|
|
1700
|
-
2
|
|
1701
|
-
];
|
|
1702
|
-
}
|
|
1703
|
-
xr = data.scene.xr;
|
|
1704
|
-
origin = xr.origin, camera = xr.camera, leftCamera = xr.leftCamera, rightCamera = xr.rightCamera, features = xr.features;
|
|
1705
|
-
entityMap = context.entityMap;
|
|
1706
|
-
origin && (xrManager.origin = entityMap.get(origin));
|
|
1707
|
-
cameraManager = xrManager.cameraManager;
|
|
1708
|
-
setCamera(cameraManager, XRTrackedInputDevice.Camera, entityMap.get(camera));
|
|
1709
|
-
setCamera(cameraManager, XRTrackedInputDevice.LeftCamera, entityMap.get(leftCamera));
|
|
1710
|
-
setCamera(cameraManager, XRTrackedInputDevice.RightCamera, entityMap.get(rightCamera));
|
|
1711
|
-
i = 0, n = features.length;
|
|
1712
|
-
_state.label = 1;
|
|
1713
|
-
case 1:
|
|
1714
|
-
if (!(i < n)) return [
|
|
1715
|
-
3,
|
|
1716
|
-
9
|
|
1717
|
-
];
|
|
1718
|
-
feature = features[i];
|
|
1719
|
-
if (!feature.enable) return [
|
|
1720
|
-
3,
|
|
1721
|
-
8
|
|
1722
|
-
];
|
|
1723
|
-
_ = feature.type;
|
|
1724
|
-
switch(_){
|
|
1725
|
-
case XRFeatureType.ImageTracking:
|
|
1726
|
-
return [
|
|
1727
|
-
3,
|
|
1728
|
-
2
|
|
1729
|
-
];
|
|
1730
|
-
case XRFeatureType.PlaneTracking:
|
|
1731
|
-
return [
|
|
1732
|
-
3,
|
|
1733
|
-
4
|
|
1734
|
-
];
|
|
1735
|
-
case XRFeatureType.AnchorTracking:
|
|
1736
|
-
return [
|
|
1737
|
-
3,
|
|
1738
|
-
5
|
|
1739
|
-
];
|
|
1740
|
-
case XRFeatureType.HitTest:
|
|
1741
|
-
return [
|
|
1742
|
-
3,
|
|
1743
|
-
6
|
|
1744
|
-
];
|
|
1745
|
-
}
|
|
1746
|
-
return [
|
|
1747
|
-
3,
|
|
1748
|
-
7
|
|
1749
|
-
];
|
|
1750
|
-
case 2:
|
|
1751
|
-
return [
|
|
1752
|
-
4,
|
|
1753
|
-
addImageTracking(engine, xrManager, feature)
|
|
1754
|
-
];
|
|
1755
|
-
case 3:
|
|
1756
|
-
_state.sent();
|
|
1757
|
-
return [
|
|
1758
|
-
3,
|
|
1759
|
-
8
|
|
1760
|
-
];
|
|
1761
|
-
case 4:
|
|
1762
|
-
addPlaneTracking(xrManager, feature);
|
|
1763
|
-
return [
|
|
1764
|
-
3,
|
|
1765
|
-
8
|
|
1766
|
-
];
|
|
1767
|
-
case 5:
|
|
1768
|
-
addAnchorTracking(xrManager, feature);
|
|
1769
|
-
return [
|
|
1770
|
-
3,
|
|
1771
|
-
8
|
|
1772
|
-
];
|
|
1773
|
-
case 6:
|
|
1774
|
-
addHitTest(xrManager);
|
|
1775
|
-
return [
|
|
1776
|
-
3,
|
|
1777
|
-
8
|
|
1778
|
-
];
|
|
1779
|
-
case 7:
|
|
1780
|
-
return [
|
|
1781
|
-
3,
|
|
1782
|
-
8
|
|
1783
|
-
];
|
|
1784
|
-
case 8:
|
|
1785
|
-
i++;
|
|
1786
|
-
return [
|
|
1787
|
-
3,
|
|
1788
|
-
1
|
|
1789
|
-
];
|
|
1790
|
-
case 9:
|
|
1791
|
-
return [
|
|
1792
|
-
2
|
|
1793
|
-
];
|
|
1794
|
-
}
|
|
1795
|
-
});
|
|
1796
|
-
})();
|
|
1797
|
-
};
|
|
1798
|
-
return XRSceneExtendParser;
|
|
1799
|
-
}();
|
|
1800
|
-
XRSceneExtendParser = __decorate([
|
|
1801
|
-
registerSceneExtendParser("XR")
|
|
1802
|
-
], XRSceneExtendParser);
|
|
1803
|
-
function addImageTracking(engine, xrManager, schema) {
|
|
1804
|
-
if (!xrManager.isSupportedFeature(XRImageTracking)) {
|
|
1805
|
-
Logger.error("Image Tracking is not supported.");
|
|
1806
|
-
return;
|
|
1807
|
-
}
|
|
1808
|
-
var promises = [];
|
|
1809
|
-
var images = schema.images;
|
|
1810
|
-
var resourceManager = engine.resourceManager;
|
|
1811
|
-
for(var i = 0, n = images.length; i < n; i++){
|
|
1812
|
-
// @ts-ignore
|
|
1813
|
-
promises.push(resourceManager.getResourceByRef(images[i]));
|
|
1814
|
-
}
|
|
1815
|
-
return Promise.all(promises).then(function(xrReferenceImages) {
|
|
1816
|
-
xrManager.addFeature(XRImageTracking, xrReferenceImages);
|
|
1817
|
-
});
|
|
1818
|
-
}
|
|
1819
|
-
function addPlaneTracking(xrManager, schema) {
|
|
1820
|
-
if (!xrManager.isSupportedFeature(XRPlaneTracking)) {
|
|
1821
|
-
Logger.error("Plane Tracking is not supported.");
|
|
1822
|
-
return;
|
|
1823
|
-
}
|
|
1824
|
-
xrManager.addFeature(XRPlaneTracking, schema.detectionMode);
|
|
1825
|
-
}
|
|
1826
|
-
function addAnchorTracking(xrManager, schema) {
|
|
1827
|
-
if (!xrManager.isSupportedFeature(XRAnchorTracking)) {
|
|
1828
|
-
Logger.error("Anchor Tracking is not supported.");
|
|
1829
|
-
return;
|
|
1830
|
-
}
|
|
1831
|
-
var anchorTracking = xrManager.addFeature(XRAnchorTracking);
|
|
1832
|
-
var anchors = schema.anchors;
|
|
1833
|
-
for(var i = 0, n = anchors.length; i < n; i++){
|
|
1834
|
-
var anchor = anchors[i];
|
|
1835
|
-
var position = new Vector3().copyFrom(anchor.position);
|
|
1836
|
-
var rotation = new Quaternion().copyFrom(anchor.rotation);
|
|
1837
|
-
anchorTracking.addAnchor(position, rotation);
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
function addHitTest(xrManager, schema) {
|
|
1841
|
-
if (!xrManager.isSupportedFeature(XRHitTest)) {
|
|
1842
|
-
Logger.error("Hit Test is not supported.");
|
|
1843
|
-
return;
|
|
1844
|
-
}
|
|
1845
|
-
xrManager.addFeature(XRHitTest);
|
|
1846
|
-
}
|
|
1847
|
-
function setCamera(cameraManager, device, entity) {
|
|
1848
|
-
var _entity;
|
|
1849
|
-
var camera = (_entity = entity) == null ? void 0 : _entity.getComponent(Camera);
|
|
1850
|
-
camera && cameraManager.attachCamera(device, camera);
|
|
1851
|
-
}
|
|
1852
|
-
|
|
1853
|
-
export { TrackableType, XRAnchor, XRAnchorTracking, XRCamera, XRCameraManager, XRController, XRFeature, XRFeatureType, XRHitResult, XRHitTest, XRImageTracking, XRInputButton, XRInputEventType, XRInputManager, XRPlaneMode, XRPlaneTracking, XRPose, XRReferenceImage, XRReferenceImageDecoder, XRReferenceImageLoader, XRRequestTrackingState, XRSceneExtendParser, XRSessionManager, XRSessionMode, XRSessionState, XRTargetRayMode, XRTrackableFeature, XRTracked, XRTrackedImage, XRTrackedInputDevice, XRTrackedPlane, XRTrackingState };
|
|
1606
|
+
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 };
|
|
1854
1607
|
//# sourceMappingURL=module.js.map
|