@galacean/engine-xr-webxr 0.0.0-experimental-1.3-xr.4 → 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 +64 -370
- package/dist/browser.js.map +1 -1
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +1 -1
- package/package.json +4 -4
package/dist/browser.js
CHANGED
|
@@ -159,9 +159,10 @@
|
|
|
159
159
|
*/ var XRSessionState;
|
|
160
160
|
(function(XRSessionState) {
|
|
161
161
|
XRSessionState[XRSessionState[/** Not initialized. */ "None"] = 0] = "None";
|
|
162
|
-
XRSessionState[XRSessionState[/**
|
|
163
|
-
XRSessionState[XRSessionState[/**
|
|
164
|
-
XRSessionState[XRSessionState[/**
|
|
162
|
+
XRSessionState[XRSessionState[/** Initializing session. */ "Initializing"] = 1] = "Initializing";
|
|
163
|
+
XRSessionState[XRSessionState[/** Initialized but not started. */ "Initialized"] = 2] = "Initialized";
|
|
164
|
+
XRSessionState[XRSessionState[/** Running. */ "Running"] = 3] = "Running";
|
|
165
|
+
XRSessionState[XRSessionState[/** Paused. */ "Paused"] = 4] = "Paused";
|
|
165
166
|
})(XRSessionState || (XRSessionState = {}));
|
|
166
167
|
/**
|
|
167
168
|
* The manager of XR camera.
|
|
@@ -574,7 +575,7 @@
|
|
|
574
575
|
this._engine = _engine;
|
|
575
576
|
this._mode = XRSessionMode.None;
|
|
576
577
|
this._state = XRSessionState.None;
|
|
577
|
-
this._listeners =
|
|
578
|
+
this._listeners = new engine.SafeLoopArray();
|
|
578
579
|
// @ts-ignore
|
|
579
580
|
this._rhi = _engine._hardwareRenderer;
|
|
580
581
|
this._raf = requestAnimationFrame.bind(window);
|
|
@@ -597,7 +598,7 @@
|
|
|
597
598
|
throw new Error("Without session to run.");
|
|
598
599
|
}
|
|
599
600
|
platformSession.start();
|
|
600
|
-
this.
|
|
601
|
+
this._setState(XRSessionState.Running);
|
|
601
602
|
this._xrManager._onSessionStart();
|
|
602
603
|
if (!engine.isPaused) {
|
|
603
604
|
engine.pause();
|
|
@@ -617,7 +618,7 @@
|
|
|
617
618
|
rhi._mainFrameBuffer = null;
|
|
618
619
|
rhi._mainFrameWidth = rhi._mainFrameHeight = 0;
|
|
619
620
|
platformSession.stop();
|
|
620
|
-
this.
|
|
621
|
+
this._setState(XRSessionState.Paused);
|
|
621
622
|
this._xrManager._onSessionStop();
|
|
622
623
|
if (!engine.isPaused) {
|
|
623
624
|
engine.pause();
|
|
@@ -627,17 +628,27 @@
|
|
|
627
628
|
/**
|
|
628
629
|
* Add a listening function for session state changes.
|
|
629
630
|
* @param listener - The listening function
|
|
630
|
-
*/ _proto.
|
|
631
|
-
this._listeners.push(
|
|
631
|
+
*/ _proto.addStateChangedListener = function addStateChangedListener(listener) {
|
|
632
|
+
this._listeners.push({
|
|
633
|
+
fn: listener
|
|
634
|
+
});
|
|
632
635
|
};
|
|
633
636
|
/**
|
|
634
637
|
* Remove a listening function of session state changes.
|
|
635
638
|
* @param listener - The listening function
|
|
636
|
-
*/ _proto.
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
639
|
+
*/ _proto.removeStateChangedListener = function removeStateChangedListener(listener) {
|
|
640
|
+
this._listeners.findAndRemove(function(value) {
|
|
641
|
+
return value.fn === listener ? value.destroyed = true : false;
|
|
642
|
+
});
|
|
643
|
+
};
|
|
644
|
+
/**
|
|
645
|
+
* @internal
|
|
646
|
+
*/ _proto._setState = function _setState(value) {
|
|
647
|
+
this._state = value;
|
|
648
|
+
var listeners = this._listeners.getLoopArray();
|
|
649
|
+
for(var i = 0, n = listeners.length; i < n; i++){
|
|
650
|
+
var listener = listeners[i];
|
|
651
|
+
!listener.destroyed && listener.fn(value);
|
|
641
652
|
}
|
|
642
653
|
};
|
|
643
654
|
/**
|
|
@@ -655,7 +666,7 @@
|
|
|
655
666
|
xrManager._platformDevice.requestSession(_this._rhi, mode, platformFeatures).then(function(platformSession) {
|
|
656
667
|
_this._mode = mode;
|
|
657
668
|
_this._platformSession = platformSession;
|
|
658
|
-
_this.
|
|
669
|
+
_this._setState(XRSessionState.Initialized);
|
|
659
670
|
platformSession.setSessionExitCallBack(_this._onSessionExit);
|
|
660
671
|
platformSession.addEventListener();
|
|
661
672
|
xrManager._onSessionInit();
|
|
@@ -704,7 +715,7 @@
|
|
|
704
715
|
rhi._mainFrameWidth = rhi._mainFrameHeight = 0;
|
|
705
716
|
platformSession.removeEventListener();
|
|
706
717
|
this._platformSession = null;
|
|
707
|
-
this.
|
|
718
|
+
this._setState(XRSessionState.None);
|
|
708
719
|
this._xrManager._onSessionExit();
|
|
709
720
|
if (!engine.isPaused) {
|
|
710
721
|
engine.pause();
|
|
@@ -713,7 +724,12 @@
|
|
|
713
724
|
};
|
|
714
725
|
/**
|
|
715
726
|
* @internal
|
|
716
|
-
*/ _proto._onDestroy = function _onDestroy() {
|
|
727
|
+
*/ _proto._onDestroy = function _onDestroy() {
|
|
728
|
+
this._listeners.findAndRemove(function(value) {
|
|
729
|
+
return value.destroyed = true;
|
|
730
|
+
});
|
|
731
|
+
this._raf = this._caf = null;
|
|
732
|
+
};
|
|
717
733
|
_create_class$1(XRSessionManager, [
|
|
718
734
|
{
|
|
719
735
|
key: "mode",
|
|
@@ -729,15 +745,6 @@
|
|
|
729
745
|
* Return the current session state.
|
|
730
746
|
*/ function get() {
|
|
731
747
|
return this._state;
|
|
732
|
-
},
|
|
733
|
-
set: /**
|
|
734
|
-
* @internal
|
|
735
|
-
*/ function set(value) {
|
|
736
|
-
this._state = value;
|
|
737
|
-
var listeners = this._listeners;
|
|
738
|
-
for(var i = 0, n = listeners.length; i < n; i++){
|
|
739
|
-
listeners[i](value);
|
|
740
|
-
}
|
|
741
748
|
}
|
|
742
749
|
},
|
|
743
750
|
{
|
|
@@ -760,26 +767,20 @@
|
|
|
760
767
|
return XRSessionManager;
|
|
761
768
|
}();
|
|
762
769
|
/**
|
|
763
|
-
*
|
|
770
|
+
* @internal
|
|
764
771
|
*/ var XRManagerExtended = /*#__PURE__*/ function(XRManager1) {
|
|
765
772
|
var XRManagerExtended = function XRManagerExtended() {
|
|
766
|
-
|
|
773
|
+
var _this;
|
|
774
|
+
_this = XRManager1.apply(this, arguments) || this;
|
|
775
|
+
_this.features = [];
|
|
776
|
+
return _this;
|
|
767
777
|
};
|
|
768
778
|
_inherits(XRManagerExtended, XRManager1);
|
|
769
779
|
var _proto = XRManagerExtended.prototype;
|
|
770
|
-
|
|
771
|
-
* Check if the specified feature is supported.
|
|
772
|
-
* @param type - The type of the feature
|
|
773
|
-
* @returns If the feature is supported
|
|
774
|
-
*/ _proto.isSupportedFeature = function isSupportedFeature(feature) {
|
|
780
|
+
_proto.isSupportedFeature = function isSupportedFeature(feature) {
|
|
775
781
|
return this._platformDevice.isSupportedFeature(XRManagerExtended._featureMap.get(feature));
|
|
776
782
|
};
|
|
777
|
-
|
|
778
|
-
* Add feature based on the xr feature type.
|
|
779
|
-
* @param type - The type of the feature
|
|
780
|
-
* @param args - The constructor params of the feature
|
|
781
|
-
* @returns The feature which has been added
|
|
782
|
-
*/ _proto.addFeature = function addFeature(type) {
|
|
783
|
+
_proto.addFeature = function addFeature(type) {
|
|
783
784
|
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
784
785
|
args[_key - 1] = arguments[_key];
|
|
785
786
|
}
|
|
@@ -797,11 +798,7 @@
|
|
|
797
798
|
features.push(feature);
|
|
798
799
|
return feature;
|
|
799
800
|
};
|
|
800
|
-
|
|
801
|
-
* Get feature which match the type.
|
|
802
|
-
* @param type - The type of the feature
|
|
803
|
-
* @returns The feature which match type
|
|
804
|
-
*/ _proto.getFeature = function getFeature(type) {
|
|
801
|
+
_proto.getFeature = function getFeature(type) {
|
|
805
802
|
var features = this.features;
|
|
806
803
|
for(var i = 0, n = features.length; i < n; i++){
|
|
807
804
|
var feature = features[i];
|
|
@@ -810,12 +807,7 @@
|
|
|
810
807
|
}
|
|
811
808
|
}
|
|
812
809
|
};
|
|
813
|
-
|
|
814
|
-
* Enter XR immersive mode, when you call this method, it will initialize and display the XR virtual world.
|
|
815
|
-
* @param sessionMode - The mode of the session
|
|
816
|
-
* @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.
|
|
817
|
-
* @returns A promise that resolves if the XR virtual world is entered, otherwise rejects
|
|
818
|
-
*/ _proto.enterXR = function enterXR(sessionMode, autoRun) {
|
|
810
|
+
_proto.enterXR = function enterXR(sessionMode, autoRun) {
|
|
819
811
|
if (autoRun === void 0) autoRun = true;
|
|
820
812
|
var _this = this;
|
|
821
813
|
var sessionManager = this.sessionManager;
|
|
@@ -828,6 +820,7 @@
|
|
|
828
820
|
return new Promise(function(resolve, reject) {
|
|
829
821
|
// 1. Check if this xr mode is supported
|
|
830
822
|
sessionManager.isSupportedMode(sessionMode).then(function() {
|
|
823
|
+
sessionManager._setState(XRSessionState.Initializing);
|
|
831
824
|
// 2. Initialize session
|
|
832
825
|
sessionManager._initialize(sessionMode, _this.features).then(function() {
|
|
833
826
|
autoRun && sessionManager.run();
|
|
@@ -836,10 +829,7 @@
|
|
|
836
829
|
}, reject);
|
|
837
830
|
});
|
|
838
831
|
};
|
|
839
|
-
|
|
840
|
-
* Exit XR immersive mode, when you call this method, it will destroy the XR virtual world.
|
|
841
|
-
* @returns A promise that resolves if the XR virtual world is destroyed, otherwise rejects
|
|
842
|
-
*/ _proto.exitXR = function exitXR() {
|
|
832
|
+
_proto.exitXR = function exitXR() {
|
|
843
833
|
var _this = this;
|
|
844
834
|
return new Promise(function(resolve, reject) {
|
|
845
835
|
_this.sessionManager._exit().then(function() {
|
|
@@ -847,18 +837,13 @@
|
|
|
847
837
|
}, reject);
|
|
848
838
|
});
|
|
849
839
|
};
|
|
850
|
-
|
|
851
|
-
* @internal
|
|
852
|
-
*/ _proto._initialize = function _initialize(engine, xrDevice) {
|
|
853
|
-
this.features.length = 0;
|
|
840
|
+
_proto._initialize = function _initialize(engine, xrDevice) {
|
|
854
841
|
this._platformDevice = xrDevice;
|
|
855
842
|
this.sessionManager = new XRSessionManager(this, engine);
|
|
856
843
|
this.inputManager = new XRInputManager(this, engine);
|
|
857
844
|
this.cameraManager = new XRCameraManager(this);
|
|
858
845
|
};
|
|
859
|
-
|
|
860
|
-
* @internal
|
|
861
|
-
*/ _proto._update = function _update() {
|
|
846
|
+
_proto._update = function _update() {
|
|
862
847
|
var sessionManager = this.sessionManager;
|
|
863
848
|
if (sessionManager.state !== XRSessionState.Running) return;
|
|
864
849
|
sessionManager._onUpdate();
|
|
@@ -870,9 +855,7 @@
|
|
|
870
855
|
feature.enabled && feature._onUpdate();
|
|
871
856
|
}
|
|
872
857
|
};
|
|
873
|
-
|
|
874
|
-
* @internal
|
|
875
|
-
*/ _proto._destroy = function _destroy() {
|
|
858
|
+
_proto._destroy = function _destroy() {
|
|
876
859
|
var _this = this;
|
|
877
860
|
if (this.sessionManager._platformSession) {
|
|
878
861
|
this.exitXR().then(function() {
|
|
@@ -886,19 +869,13 @@
|
|
|
886
869
|
this.cameraManager._onDestroy();
|
|
887
870
|
}
|
|
888
871
|
};
|
|
889
|
-
|
|
890
|
-
* @internal
|
|
891
|
-
*/ _proto._getRequestAnimationFrame = function _getRequestAnimationFrame() {
|
|
872
|
+
_proto._getRequestAnimationFrame = function _getRequestAnimationFrame() {
|
|
892
873
|
return this.sessionManager._getRequestAnimationFrame();
|
|
893
874
|
};
|
|
894
|
-
|
|
895
|
-
* @internal
|
|
896
|
-
*/ _proto._getCancelAnimationFrame = function _getCancelAnimationFrame() {
|
|
875
|
+
_proto._getCancelAnimationFrame = function _getCancelAnimationFrame() {
|
|
897
876
|
return this.sessionManager._getCancelAnimationFrame();
|
|
898
877
|
};
|
|
899
|
-
|
|
900
|
-
* @internal
|
|
901
|
-
*/ _proto._getCameraClearFlagsMask = function _getCameraClearFlagsMask(type) {
|
|
878
|
+
_proto._getCameraClearFlagsMask = function _getCameraClearFlagsMask(type) {
|
|
902
879
|
return this.cameraManager._getCameraClearFlagsMask(type);
|
|
903
880
|
};
|
|
904
881
|
/**
|
|
@@ -944,10 +921,7 @@
|
|
|
944
921
|
_create_class$1(XRManagerExtended, [
|
|
945
922
|
{
|
|
946
923
|
key: "origin",
|
|
947
|
-
get:
|
|
948
|
-
* The current origin of XR space.
|
|
949
|
-
* @remarks The connection point between the virtual world and the real world ( XR Space )
|
|
950
|
-
*/ function get() {
|
|
924
|
+
get: function get() {
|
|
951
925
|
return this._origin;
|
|
952
926
|
},
|
|
953
927
|
set: function set(value) {
|
|
@@ -1066,7 +1040,7 @@
|
|
|
1066
1040
|
_this._updated = [];
|
|
1067
1041
|
_this._removed = [];
|
|
1068
1042
|
_this._statusSnapshot = {};
|
|
1069
|
-
_this._listeners =
|
|
1043
|
+
_this._listeners = new engine.SafeLoopArray();
|
|
1070
1044
|
return _this;
|
|
1071
1045
|
};
|
|
1072
1046
|
_inherits(XRTrackableFeature, XRFeature1);
|
|
@@ -1075,22 +1049,22 @@
|
|
|
1075
1049
|
* Add a listening function for tracked object changes.
|
|
1076
1050
|
* @param listener - The listening function
|
|
1077
1051
|
*/ _proto.addChangedListener = function addChangedListener(listener) {
|
|
1078
|
-
this._listeners.push(
|
|
1052
|
+
this._listeners.push({
|
|
1053
|
+
fn: listener
|
|
1054
|
+
});
|
|
1079
1055
|
};
|
|
1080
1056
|
/**
|
|
1081
1057
|
* Remove a listening function of tracked object changes.
|
|
1082
1058
|
* @param listener - The listening function
|
|
1083
1059
|
*/ _proto.removeChangedListener = function removeChangedListener(listener) {
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
listeners.splice(index, 1);
|
|
1088
|
-
}
|
|
1060
|
+
this._listeners.findAndRemove(function(value) {
|
|
1061
|
+
return value.fn === listener ? value.destroyed = true : false;
|
|
1062
|
+
});
|
|
1089
1063
|
};
|
|
1090
1064
|
_proto._onUpdate = function _onUpdate() {
|
|
1091
1065
|
var _this__xrManager_sessionManager = this._xrManager.sessionManager, platformSession = _this__xrManager_sessionManager._platformSession;
|
|
1092
1066
|
var platformFrame = platformSession.frame;
|
|
1093
|
-
var _this = this, platformFeature = _this._platformFeature,
|
|
1067
|
+
var _this = this, platformFeature = _this._platformFeature, requestTrackings = _this._requestTrackings, statusSnapshot = _this._statusSnapshot, allTracked = _this._tracked, added = _this._added, updated = _this._updated, removed = _this._removed;
|
|
1094
1068
|
if (!platformFrame || !requestTrackings.length) {
|
|
1095
1069
|
return;
|
|
1096
1070
|
}
|
|
@@ -1142,8 +1116,10 @@
|
|
|
1142
1116
|
requestTrackings[i1].state === XRRequestTrackingState.Destroyed && requestTrackings.splice(i1, 1);
|
|
1143
1117
|
}
|
|
1144
1118
|
if (added.length > 0 || updated.length > 0 || removed.length > 0) {
|
|
1119
|
+
var listeners = this._listeners.getLoopArray();
|
|
1145
1120
|
for(var i2 = 0, n3 = listeners.length; i2 < n3; i2++){
|
|
1146
|
-
listeners[i2]
|
|
1121
|
+
var listener = listeners[i2];
|
|
1122
|
+
!listener.destroyed && listener.fn(added, updated, removed);
|
|
1147
1123
|
}
|
|
1148
1124
|
}
|
|
1149
1125
|
};
|
|
@@ -1153,6 +1129,9 @@
|
|
|
1153
1129
|
_proto._onSessionExit = function _onSessionExit() {
|
|
1154
1130
|
// prettier-ignore
|
|
1155
1131
|
this._requestTrackings.length = this._tracked.length = this._added.length = this._updated.length = this._removed.length = 0;
|
|
1132
|
+
this._listeners.findAndRemove(function(value) {
|
|
1133
|
+
return value.destroyed = true;
|
|
1134
|
+
});
|
|
1156
1135
|
};
|
|
1157
1136
|
_proto._addRequestTracking = function _addRequestTracking(requestTracking) {
|
|
1158
1137
|
var _this = this, platformFeature = _this._platformFeature;
|
|
@@ -1224,101 +1203,6 @@
|
|
|
1224
1203
|
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1225
1204
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1226
1205
|
}
|
|
1227
|
-
function __generator(thisArg, body) {
|
|
1228
|
-
var verb = function verb(n) {
|
|
1229
|
-
return function(v) {
|
|
1230
|
-
return step([
|
|
1231
|
-
n,
|
|
1232
|
-
v
|
|
1233
|
-
]);
|
|
1234
|
-
};
|
|
1235
|
-
};
|
|
1236
|
-
var step = function step(op) {
|
|
1237
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
1238
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
1239
|
-
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;
|
|
1240
|
-
if (y = 0, t) op = [
|
|
1241
|
-
op[0] & 2,
|
|
1242
|
-
t.value
|
|
1243
|
-
];
|
|
1244
|
-
switch(op[0]){
|
|
1245
|
-
case 0:
|
|
1246
|
-
case 1:
|
|
1247
|
-
t = op;
|
|
1248
|
-
break;
|
|
1249
|
-
case 4:
|
|
1250
|
-
_.label++;
|
|
1251
|
-
return {
|
|
1252
|
-
value: op[1],
|
|
1253
|
-
done: false
|
|
1254
|
-
};
|
|
1255
|
-
case 5:
|
|
1256
|
-
_.label++;
|
|
1257
|
-
y = op[1];
|
|
1258
|
-
op = [
|
|
1259
|
-
0
|
|
1260
|
-
];
|
|
1261
|
-
continue;
|
|
1262
|
-
case 7:
|
|
1263
|
-
op = _.ops.pop();
|
|
1264
|
-
_.trys.pop();
|
|
1265
|
-
continue;
|
|
1266
|
-
default:
|
|
1267
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
1268
|
-
_ = 0;
|
|
1269
|
-
continue;
|
|
1270
|
-
}
|
|
1271
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
1272
|
-
_.label = op[1];
|
|
1273
|
-
break;
|
|
1274
|
-
}
|
|
1275
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
1276
|
-
_.label = t[1];
|
|
1277
|
-
t = op;
|
|
1278
|
-
break;
|
|
1279
|
-
}
|
|
1280
|
-
if (t && _.label < t[2]) {
|
|
1281
|
-
_.label = t[2];
|
|
1282
|
-
_.ops.push(op);
|
|
1283
|
-
break;
|
|
1284
|
-
}
|
|
1285
|
-
if (t[2]) _.ops.pop();
|
|
1286
|
-
_.trys.pop();
|
|
1287
|
-
continue;
|
|
1288
|
-
}
|
|
1289
|
-
op = body.call(thisArg, _);
|
|
1290
|
-
} catch (e) {
|
|
1291
|
-
op = [
|
|
1292
|
-
6,
|
|
1293
|
-
e
|
|
1294
|
-
];
|
|
1295
|
-
y = 0;
|
|
1296
|
-
} finally{
|
|
1297
|
-
f = t = 0;
|
|
1298
|
-
}
|
|
1299
|
-
if (op[0] & 5) throw op[1];
|
|
1300
|
-
return {
|
|
1301
|
-
value: op[0] ? op[1] : void 0,
|
|
1302
|
-
done: true
|
|
1303
|
-
};
|
|
1304
|
-
};
|
|
1305
|
-
var _ = {
|
|
1306
|
-
label: 0,
|
|
1307
|
-
sent: function sent() {
|
|
1308
|
-
if (t[0] & 1) throw t[1];
|
|
1309
|
-
return t[1];
|
|
1310
|
-
},
|
|
1311
|
-
trys: [],
|
|
1312
|
-
ops: []
|
|
1313
|
-
}, f, y, t, g;
|
|
1314
|
-
return g = {
|
|
1315
|
-
next: verb(0),
|
|
1316
|
-
"throw": verb(1),
|
|
1317
|
-
"return": verb(2)
|
|
1318
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
1319
|
-
return this;
|
|
1320
|
-
}), g;
|
|
1321
|
-
}
|
|
1322
1206
|
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
1323
1207
|
var e = new Error(message);
|
|
1324
1208
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
@@ -1740,196 +1624,6 @@
|
|
|
1740
1624
|
XRReferenceImageLoader = __decorate([
|
|
1741
1625
|
engine.resourceLoader("XRReferenceImage", [])
|
|
1742
1626
|
], XRReferenceImageLoader);
|
|
1743
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1744
|
-
try {
|
|
1745
|
-
var info = gen[key](arg);
|
|
1746
|
-
var value = info.value;
|
|
1747
|
-
} catch (error) {
|
|
1748
|
-
reject(error);
|
|
1749
|
-
return;
|
|
1750
|
-
}
|
|
1751
|
-
if (info.done) resolve(value);
|
|
1752
|
-
else Promise.resolve(value).then(_next, _throw);
|
|
1753
|
-
}
|
|
1754
|
-
function _async_to_generator(fn) {
|
|
1755
|
-
return function() {
|
|
1756
|
-
var self = this, args = arguments;
|
|
1757
|
-
return new Promise(function(resolve, reject) {
|
|
1758
|
-
var gen = fn.apply(self, args);
|
|
1759
|
-
function _next(value) {
|
|
1760
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
1761
|
-
}
|
|
1762
|
-
function _throw(err) {
|
|
1763
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1764
|
-
}
|
|
1765
|
-
_next(undefined);
|
|
1766
|
-
});
|
|
1767
|
-
};
|
|
1768
|
-
}
|
|
1769
|
-
var XRSceneExtendParser = /*#__PURE__*/ function() {
|
|
1770
|
-
var XRSceneExtendParser = function XRSceneExtendParser() {};
|
|
1771
|
-
XRSceneExtendParser.parse = function parse(engine$1, context, data) {
|
|
1772
|
-
return _async_to_generator(function() {
|
|
1773
|
-
var xrManager, xr, origin, camera, leftCamera, rightCamera, features, entityMap, cameraManager, i, n, feature, _;
|
|
1774
|
-
return __generator(this, function(_state) {
|
|
1775
|
-
switch(_state.label){
|
|
1776
|
-
case 0:
|
|
1777
|
-
xrManager = engine$1.xrManager;
|
|
1778
|
-
if (!xrManager) {
|
|
1779
|
-
engine.Logger.error("XRManager is not found in the engine.");
|
|
1780
|
-
return [
|
|
1781
|
-
2
|
|
1782
|
-
];
|
|
1783
|
-
}
|
|
1784
|
-
xr = data.scene.xr;
|
|
1785
|
-
origin = xr.origin, camera = xr.camera, leftCamera = xr.leftCamera, rightCamera = xr.rightCamera, features = xr.features;
|
|
1786
|
-
entityMap = context.entityMap;
|
|
1787
|
-
origin && (xrManager.origin = entityMap.get(origin));
|
|
1788
|
-
cameraManager = xrManager.cameraManager;
|
|
1789
|
-
setCamera(cameraManager, XRTrackedInputDevice.Camera, entityMap.get(camera));
|
|
1790
|
-
setCamera(cameraManager, XRTrackedInputDevice.LeftCamera, entityMap.get(leftCamera));
|
|
1791
|
-
setCamera(cameraManager, XRTrackedInputDevice.RightCamera, entityMap.get(rightCamera));
|
|
1792
|
-
i = 0, n = features.length;
|
|
1793
|
-
_state.label = 1;
|
|
1794
|
-
case 1:
|
|
1795
|
-
if (!(i < n)) return [
|
|
1796
|
-
3,
|
|
1797
|
-
9
|
|
1798
|
-
];
|
|
1799
|
-
feature = features[i];
|
|
1800
|
-
if (!feature.enable) return [
|
|
1801
|
-
3,
|
|
1802
|
-
8
|
|
1803
|
-
];
|
|
1804
|
-
_ = feature.type;
|
|
1805
|
-
switch(_){
|
|
1806
|
-
case XRFeatureType.ImageTracking:
|
|
1807
|
-
return [
|
|
1808
|
-
3,
|
|
1809
|
-
2
|
|
1810
|
-
];
|
|
1811
|
-
case XRFeatureType.PlaneTracking:
|
|
1812
|
-
return [
|
|
1813
|
-
3,
|
|
1814
|
-
4
|
|
1815
|
-
];
|
|
1816
|
-
case XRFeatureType.AnchorTracking:
|
|
1817
|
-
return [
|
|
1818
|
-
3,
|
|
1819
|
-
5
|
|
1820
|
-
];
|
|
1821
|
-
case XRFeatureType.HitTest:
|
|
1822
|
-
return [
|
|
1823
|
-
3,
|
|
1824
|
-
6
|
|
1825
|
-
];
|
|
1826
|
-
}
|
|
1827
|
-
return [
|
|
1828
|
-
3,
|
|
1829
|
-
7
|
|
1830
|
-
];
|
|
1831
|
-
case 2:
|
|
1832
|
-
return [
|
|
1833
|
-
4,
|
|
1834
|
-
addImageTracking(engine$1, xrManager, feature)
|
|
1835
|
-
];
|
|
1836
|
-
case 3:
|
|
1837
|
-
_state.sent();
|
|
1838
|
-
return [
|
|
1839
|
-
3,
|
|
1840
|
-
8
|
|
1841
|
-
];
|
|
1842
|
-
case 4:
|
|
1843
|
-
addPlaneTracking(xrManager, feature);
|
|
1844
|
-
return [
|
|
1845
|
-
3,
|
|
1846
|
-
8
|
|
1847
|
-
];
|
|
1848
|
-
case 5:
|
|
1849
|
-
addAnchorTracking(xrManager, feature);
|
|
1850
|
-
return [
|
|
1851
|
-
3,
|
|
1852
|
-
8
|
|
1853
|
-
];
|
|
1854
|
-
case 6:
|
|
1855
|
-
addHitTest(xrManager);
|
|
1856
|
-
return [
|
|
1857
|
-
3,
|
|
1858
|
-
8
|
|
1859
|
-
];
|
|
1860
|
-
case 7:
|
|
1861
|
-
return [
|
|
1862
|
-
3,
|
|
1863
|
-
8
|
|
1864
|
-
];
|
|
1865
|
-
case 8:
|
|
1866
|
-
i++;
|
|
1867
|
-
return [
|
|
1868
|
-
3,
|
|
1869
|
-
1
|
|
1870
|
-
];
|
|
1871
|
-
case 9:
|
|
1872
|
-
return [
|
|
1873
|
-
2
|
|
1874
|
-
];
|
|
1875
|
-
}
|
|
1876
|
-
});
|
|
1877
|
-
})();
|
|
1878
|
-
};
|
|
1879
|
-
return XRSceneExtendParser;
|
|
1880
|
-
}();
|
|
1881
|
-
XRSceneExtendParser = __decorate([
|
|
1882
|
-
engine.registerSceneExtendParser("XR")
|
|
1883
|
-
], XRSceneExtendParser);
|
|
1884
|
-
function addImageTracking(engine$1, xrManager, schema) {
|
|
1885
|
-
if (!xrManager.isSupportedFeature(XRImageTracking)) {
|
|
1886
|
-
engine.Logger.error("Image Tracking is not supported.");
|
|
1887
|
-
return;
|
|
1888
|
-
}
|
|
1889
|
-
var promises = [];
|
|
1890
|
-
var images = schema.images;
|
|
1891
|
-
var resourceManager = engine$1.resourceManager;
|
|
1892
|
-
for(var i = 0, n = images.length; i < n; i++){
|
|
1893
|
-
// @ts-ignore
|
|
1894
|
-
promises.push(resourceManager.getResourceByRef(images[i]));
|
|
1895
|
-
}
|
|
1896
|
-
return Promise.all(promises).then(function(xrReferenceImages) {
|
|
1897
|
-
xrManager.addFeature(XRImageTracking, xrReferenceImages);
|
|
1898
|
-
});
|
|
1899
|
-
}
|
|
1900
|
-
function addPlaneTracking(xrManager, schema) {
|
|
1901
|
-
if (!xrManager.isSupportedFeature(XRPlaneTracking)) {
|
|
1902
|
-
engine.Logger.error("Plane Tracking is not supported.");
|
|
1903
|
-
return;
|
|
1904
|
-
}
|
|
1905
|
-
xrManager.addFeature(XRPlaneTracking, schema.detectionMode);
|
|
1906
|
-
}
|
|
1907
|
-
function addAnchorTracking(xrManager, schema) {
|
|
1908
|
-
if (!xrManager.isSupportedFeature(XRAnchorTracking)) {
|
|
1909
|
-
engine.Logger.error("Anchor Tracking is not supported.");
|
|
1910
|
-
return;
|
|
1911
|
-
}
|
|
1912
|
-
var anchorTracking = xrManager.addFeature(XRAnchorTracking);
|
|
1913
|
-
var anchors = schema.anchors;
|
|
1914
|
-
for(var i = 0, n = anchors.length; i < n; i++){
|
|
1915
|
-
var anchor = anchors[i];
|
|
1916
|
-
var position = new engine.Vector3().copyFrom(anchor.position);
|
|
1917
|
-
var rotation = new engine.Quaternion().copyFrom(anchor.rotation);
|
|
1918
|
-
anchorTracking.addAnchor(position, rotation);
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
function addHitTest(xrManager, schema) {
|
|
1922
|
-
if (!xrManager.isSupportedFeature(XRHitTest)) {
|
|
1923
|
-
engine.Logger.error("Hit Test is not supported.");
|
|
1924
|
-
return;
|
|
1925
|
-
}
|
|
1926
|
-
xrManager.addFeature(XRHitTest);
|
|
1927
|
-
}
|
|
1928
|
-
function setCamera(cameraManager, device, entity) {
|
|
1929
|
-
var _entity;
|
|
1930
|
-
var camera = (_entity = entity) == null ? void 0 : _entity.getComponent(engine.Camera);
|
|
1931
|
-
camera && cameraManager.attachCamera(device, camera);
|
|
1932
|
-
}
|
|
1933
1627
|
|
|
1934
1628
|
function _is_native_reflect_construct() {
|
|
1935
1629
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|