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