@galacean/engine-xr-webxr 0.0.0-experimental-1.3-xr.5 → 0.0.0-experimental-1.3-xr.10

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