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