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