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