@galacean/engine-xr 1.3.0-alpha.2 → 1.3.0-beta.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.
@@ -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[/** Initialized but not started. */ "Initialized"] = 1] = "Initialized";
104
- XRSessionState[XRSessionState[/** Running. */ "Running"] = 2] = "Running";
105
- XRSessionState[XRSessionState[/** Paused. */ "Paused"] = 3] = "Paused";
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
  /**
@@ -185,7 +186,7 @@ function _instanceof(left, right) {
185
186
  */ _proto._onSessionExit = function _onSessionExit() {};
186
187
  /**
187
188
  * @internal
188
- */ _proto._getCameraClearFlagsMask = function _getCameraClearFlagsMask(cameraType) {
189
+ */ _proto._getIgnoreClearFlags = function _getIgnoreClearFlags(cameraType) {
189
190
  if (cameraType === miniprogram.CameraType.XRCenterCamera) {
190
191
  if (this._xrManager.sessionManager.state === exports.XRSessionState.Running) {
191
192
  return miniprogram.CameraClearFlags.Color;
@@ -345,7 +346,7 @@ exports.XRTargetRayMode = void 0;
345
346
  this._removed = [];
346
347
  this._trackedDevices = [];
347
348
  this._statusSnapshot = [];
348
- this._listeners = [];
349
+ this._listeners = new miniprogram.SafeLoopArray();
349
350
  var _this = this, trackedDevices = _this._trackedDevices, controllers = _this._controllers, cameras = _this._cameras;
350
351
  for(var i = 0; i < 6; i++){
351
352
  switch(i){
@@ -375,22 +376,22 @@ exports.XRTargetRayMode = void 0;
375
376
  * Add a listener for tracked device changes.
376
377
  * @param listener - The listener to add
377
378
  */ _proto.addTrackedDeviceChangedListener = function addTrackedDeviceChangedListener(listener) {
378
- this._listeners.push(listener);
379
+ this._listeners.push({
380
+ fn: listener
381
+ });
379
382
  };
380
383
  /**
381
384
  * Remove a listener of tracked device changes.
382
385
  * @param listener - The listener to remove
383
386
  */ _proto.removeTrackedDeviceChangedListener = function removeTrackedDeviceChangedListener(listener) {
384
- var _this = this, listeners = _this._listeners;
385
- var index = listeners.indexOf(listener);
386
- if (index >= 0) {
387
- listeners.splice(index, 1);
388
- }
387
+ this._listeners.findAndRemove(function(value) {
388
+ return value.fn === listener ? value.destroyed = true : false;
389
+ });
389
390
  };
390
391
  /**
391
392
  * @internal
392
393
  */ _proto._onUpdate = function _onUpdate() {
393
- var _this = this, added = _this._added, removed = _this._removed, listeners = _this._listeners, statusSnapshot = _this._statusSnapshot;
394
+ var _this = this, added = _this._added, removed = _this._removed, statusSnapshot = _this._statusSnapshot;
394
395
  var _this1 = this, trackedDevices = _this1._trackedDevices, controllers = _this1._controllers;
395
396
  // Reset data
396
397
  added.length = removed.length = 0;
@@ -423,15 +424,19 @@ exports.XRTargetRayMode = void 0;
423
424
  }
424
425
  // Dispatch change event
425
426
  if (added.length > 0 || removed.length > 0) {
427
+ var listeners = this._listeners.getLoopArray();
426
428
  for(var i3 = 0, n3 = listeners.length; i3 < n3; i3++){
427
- listeners[i3](added, removed);
429
+ var listener = listeners[i3];
430
+ !listener.destroyed && listener.fn(added, removed);
428
431
  }
429
432
  }
430
433
  };
431
434
  /**
432
435
  * @internal
433
436
  */ _proto._onDestroy = function _onDestroy() {
434
- this._listeners.length = 0;
437
+ this._listeners.findAndRemove(function(value) {
438
+ return value.destroyed = true;
439
+ });
435
440
  };
436
441
  _proto._handleEvent = function _handleEvent(event) {
437
442
  var input = this._trackedDevices[event.input];
@@ -527,6 +532,7 @@ exports.XRTargetRayMode = void 0;
527
532
  this._engine = _engine;
528
533
  this._mode = exports.XRSessionMode.None;
529
534
  this._state = exports.XRSessionState.None;
535
+ this._listeners = new miniprogram.SafeLoopArray();
530
536
  // @ts-ignore
531
537
  this._rhi = _engine._hardwareRenderer;
532
538
  this._raf = engineMiniprogramAdapter.requestAnimationFrame.bind(engineMiniprogramAdapter.window);
@@ -549,7 +555,7 @@ exports.XRTargetRayMode = void 0;
549
555
  throw new Error("Without session to run.");
550
556
  }
551
557
  platformSession.start();
552
- this._state = exports.XRSessionState.Running;
558
+ this._setState(exports.XRSessionState.Running);
553
559
  this._xrManager._onSessionStart();
554
560
  if (!engine.isPaused) {
555
561
  engine.pause();
@@ -569,7 +575,7 @@ exports.XRTargetRayMode = void 0;
569
575
  rhi._mainFrameBuffer = null;
570
576
  rhi._mainFrameWidth = rhi._mainFrameHeight = 0;
571
577
  platformSession.stop();
572
- this._state = exports.XRSessionState.Paused;
578
+ this._setState(exports.XRSessionState.Paused);
573
579
  this._xrManager._onSessionStop();
574
580
  if (!engine.isPaused) {
575
581
  engine.pause();
@@ -577,6 +583,32 @@ exports.XRTargetRayMode = void 0;
577
583
  }
578
584
  };
579
585
  /**
586
+ * Add a listening function for session state changes.
587
+ * @param listener - The listening function
588
+ */ _proto.addStateChangedListener = function addStateChangedListener(listener) {
589
+ this._listeners.push({
590
+ fn: listener
591
+ });
592
+ };
593
+ /**
594
+ * Remove a listening function of session state changes.
595
+ * @param listener - The listening function
596
+ */ _proto.removeStateChangedListener = function removeStateChangedListener(listener) {
597
+ this._listeners.findAndRemove(function(value) {
598
+ return value.fn === listener ? value.destroyed = true : false;
599
+ });
600
+ };
601
+ /**
602
+ * @internal
603
+ */ _proto._setState = function _setState(value) {
604
+ this._state = value;
605
+ var listeners = this._listeners.getLoopArray();
606
+ for(var i = 0, n = listeners.length; i < n; i++){
607
+ var listener = listeners[i];
608
+ !listener.destroyed && listener.fn(value);
609
+ }
610
+ };
611
+ /**
580
612
  * @internal
581
613
  */ _proto._initialize = function _initialize(mode, features) {
582
614
  var _this = this;
@@ -591,7 +623,7 @@ exports.XRTargetRayMode = void 0;
591
623
  xrManager._platformDevice.requestSession(_this._rhi, mode, platformFeatures).then(function(platformSession) {
592
624
  _this._mode = mode;
593
625
  _this._platformSession = platformSession;
594
- _this._state = exports.XRSessionState.Initialized;
626
+ _this._setState(exports.XRSessionState.Initialized);
595
627
  platformSession.setSessionExitCallBack(_this._onSessionExit);
596
628
  platformSession.addEventListener();
597
629
  xrManager._onSessionInit();
@@ -640,7 +672,7 @@ exports.XRTargetRayMode = void 0;
640
672
  rhi._mainFrameWidth = rhi._mainFrameHeight = 0;
641
673
  platformSession.removeEventListener();
642
674
  this._platformSession = null;
643
- this._state = exports.XRSessionState.None;
675
+ this._setState(exports.XRSessionState.None);
644
676
  this._xrManager._onSessionExit();
645
677
  if (!engine.isPaused) {
646
678
  engine.pause();
@@ -649,7 +681,12 @@ exports.XRTargetRayMode = void 0;
649
681
  };
650
682
  /**
651
683
  * @internal
652
- */ _proto._onDestroy = function _onDestroy() {};
684
+ */ _proto._onDestroy = function _onDestroy() {
685
+ this._listeners.findAndRemove(function(value) {
686
+ return value.destroyed = true;
687
+ });
688
+ this._raf = this._caf = null;
689
+ };
653
690
  _create_class(XRSessionManager, [
654
691
  {
655
692
  key: "mode",
@@ -688,47 +725,36 @@ exports.XRTargetRayMode = void 0;
688
725
  }();
689
726
 
690
727
  /**
691
- * XRManager is the entry point of the XR system.
728
+ * @internal
692
729
  */ var XRManagerExtended = /*#__PURE__*/ function(XRManager1) {
693
730
  _inherits(XRManagerExtended, XRManager1);
694
731
  function XRManagerExtended() {
695
732
  return XRManager1.apply(this, arguments);
696
733
  }
697
734
  var _proto = XRManagerExtended.prototype;
698
- /**
699
- * Check if the specified feature is supported.
700
- * @param type - The type of the feature
701
- * @returns If the feature is supported
702
- */ _proto.isSupportedFeature = function isSupportedFeature(feature) {
735
+ _proto.isSupportedFeature = function isSupportedFeature(feature) {
703
736
  return this._platformDevice.isSupportedFeature(XRManagerExtended._featureMap.get(feature));
704
737
  };
705
- /**
706
- * Add feature based on the xr feature type.
707
- * @param type - The type of the feature
708
- * @param args - The constructor params of the feature
709
- * @returns The feature which has been added
710
- */ _proto.addFeature = function addFeature(type) {
738
+ _proto.addFeature = function addFeature(type) {
711
739
  for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
712
740
  args[_key - 1] = arguments[_key];
713
741
  }
714
742
  if (this.sessionManager._platformSession) {
715
743
  throw new Error("Cannot add feature when the session is initialized.");
716
744
  }
717
- var _this = this, features = _this._features;
745
+ if (!this._platformDevice.isSupportedFeature(XRManagerExtended._featureMap.get(type))) {
746
+ throw new Error("The feature is not supported");
747
+ }
748
+ var features = this.features;
718
749
  for(var i = 0, n = features.length; i < n; i++){
719
- var feature = features[i];
720
- if (_instanceof(feature, type)) throw new Error("The feature has been added");
750
+ if (_instanceof(features[i], type)) throw new Error("The feature has been added");
721
751
  }
722
- var feature1 = _construct(type, [].concat(this, args));
723
- this._features.push(feature1);
724
- return feature1;
752
+ var feature = _construct(type, [].concat(this, args));
753
+ features.push(feature);
754
+ return feature;
725
755
  };
726
- /**
727
- * Get feature which match the type.
728
- * @param type - The type of the feature
729
- * @returns The feature which match type
730
- */ _proto.getFeature = function getFeature(type) {
731
- var _this = this, features = _this._features;
756
+ _proto.getFeature = function getFeature(type) {
757
+ var features = this.features;
732
758
  for(var i = 0, n = features.length; i < n; i++){
733
759
  var feature = features[i];
734
760
  if (_instanceof(feature, type)) {
@@ -736,25 +762,7 @@ exports.XRTargetRayMode = void 0;
736
762
  }
737
763
  }
738
764
  };
739
- _proto.getFeatures = function getFeatures(type, out) {
740
- if (out) {
741
- out.length = 0;
742
- } else {
743
- out = [];
744
- }
745
- var _this = this, features = _this._features;
746
- for(var i = 0, n = features.length; i < n; i--){
747
- var feature = features[i];
748
- _instanceof(feature, type) && out.push(feature);
749
- }
750
- return out;
751
- };
752
- /**
753
- * Enter XR immersive mode, when you call this method, it will initialize and display the XR virtual world.
754
- * @param sessionMode - The mode of the session
755
- * @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.
756
- * @returns A promise that resolves if the XR virtual world is entered, otherwise rejects
757
- */ _proto.enterXR = function enterXR(sessionMode, autoRun) {
765
+ _proto.enterXR = function enterXR(sessionMode, autoRun) {
758
766
  if (autoRun === void 0) autoRun = true;
759
767
  var _this = this;
760
768
  var sessionManager = this.sessionManager;
@@ -767,18 +775,16 @@ exports.XRTargetRayMode = void 0;
767
775
  return new Promise(function(resolve, reject) {
768
776
  // 1. Check if this xr mode is supported
769
777
  sessionManager.isSupportedMode(sessionMode).then(function() {
778
+ sessionManager._setState(exports.XRSessionState.Initializing);
770
779
  // 2. Initialize session
771
- sessionManager._initialize(sessionMode, _this._features).then(function() {
780
+ sessionManager._initialize(sessionMode, _this.features).then(function() {
772
781
  autoRun && sessionManager.run();
773
782
  resolve();
774
783
  }, reject);
775
784
  }, reject);
776
785
  });
777
786
  };
778
- /**
779
- * Exit XR immersive mode, when you call this method, it will destroy the XR virtual world.
780
- * @returns A promise that resolves if the XR virtual world is destroyed, otherwise rejects
781
- */ _proto.exitXR = function exitXR() {
787
+ _proto.exitXR = function exitXR() {
782
788
  var _this = this;
783
789
  return new Promise(function(resolve, reject) {
784
790
  _this.sessionManager._exit().then(function() {
@@ -786,32 +792,26 @@ exports.XRTargetRayMode = void 0;
786
792
  }, reject);
787
793
  });
788
794
  };
789
- /**
790
- * @internal
791
- */ _proto._initialize = function _initialize(engine, xrDevice) {
795
+ _proto._initialize = function _initialize(engine, xrDevice) {
792
796
  this._features = [];
793
797
  this._platformDevice = xrDevice;
794
798
  this.sessionManager = new XRSessionManager(this, engine);
795
799
  this.inputManager = new XRInputManager(this, engine);
796
800
  this.cameraManager = new XRCameraManager(this);
797
801
  };
798
- /**
799
- * @internal
800
- */ _proto._update = function _update() {
802
+ _proto._update = function _update() {
801
803
  var sessionManager = this.sessionManager;
802
804
  if (sessionManager.state !== exports.XRSessionState.Running) return;
803
805
  sessionManager._onUpdate();
804
806
  this.inputManager._onUpdate();
805
807
  this.cameraManager._onUpdate();
806
- var _this = this, features = _this._features;
808
+ var features = this.features;
807
809
  for(var i = 0, n = features.length; i < n; i++){
808
810
  var feature = features[i];
809
811
  feature.enabled && feature._onUpdate();
810
812
  }
811
813
  };
812
- /**
813
- * @internal
814
- */ _proto._destroy = function _destroy() {
814
+ _proto._destroy = function _destroy() {
815
815
  var _this = this;
816
816
  if (this.sessionManager._platformSession) {
817
817
  this.exitXR().then(function() {
@@ -825,25 +825,19 @@ exports.XRTargetRayMode = void 0;
825
825
  this.cameraManager._onDestroy();
826
826
  }
827
827
  };
828
- /**
829
- * @internal
830
- */ _proto._getRequestAnimationFrame = function _getRequestAnimationFrame() {
828
+ _proto._getRequestAnimationFrame = function _getRequestAnimationFrame() {
831
829
  return this.sessionManager._getRequestAnimationFrame();
832
830
  };
833
- /**
834
- * @internal
835
- */ _proto._getCancelAnimationFrame = function _getCancelAnimationFrame() {
831
+ _proto._getCancelAnimationFrame = function _getCancelAnimationFrame() {
836
832
  return this.sessionManager._getCancelAnimationFrame();
837
833
  };
838
- /**
839
- * @internal
840
- */ _proto._getCameraClearFlagsMask = function _getCameraClearFlagsMask(type) {
841
- return this.cameraManager._getCameraClearFlagsMask(type);
834
+ _proto._getCameraIgnoreClearFlags = function _getCameraIgnoreClearFlags(type) {
835
+ return this.cameraManager._getIgnoreClearFlags(type);
842
836
  };
843
837
  /**
844
838
  * @internal
845
839
  */ _proto._onSessionStop = function _onSessionStop() {
846
- var _this = this, features = _this._features;
840
+ var features = this.features;
847
841
  for(var i = 0, n = features.length; i < n; i++){
848
842
  var feature = features[i];
849
843
  feature.enabled && feature._onSessionStop();
@@ -852,7 +846,7 @@ exports.XRTargetRayMode = void 0;
852
846
  /**
853
847
  * @internal
854
848
  */ _proto._onSessionInit = function _onSessionInit() {
855
- var _this = this, features = _this._features;
849
+ var features = this.features;
856
850
  for(var i = 0, n = features.length; i < n; i++){
857
851
  var feature = features[i];
858
852
  feature.enabled && feature._onSessionInit();
@@ -862,7 +856,7 @@ exports.XRTargetRayMode = void 0;
862
856
  * @internal
863
857
  */ _proto._onSessionStart = function _onSessionStart() {
864
858
  this.cameraManager._onSessionStart();
865
- var _this = this, features = _this._features;
859
+ var features = this.features;
866
860
  for(var i = 0, n = features.length; i < n; i++){
867
861
  var feature = features[i];
868
862
  feature.enabled && feature._onSessionStart();
@@ -872,7 +866,7 @@ exports.XRTargetRayMode = void 0;
872
866
  * @internal
873
867
  */ _proto._onSessionExit = function _onSessionExit() {
874
868
  this.cameraManager._onSessionExit();
875
- var _this = this, features = _this._features;
869
+ var features = this.features;
876
870
  for(var i = 0, n = features.length; i < n; i++){
877
871
  var feature = features[i];
878
872
  feature.enabled && feature._onSessionExit();
@@ -881,12 +875,15 @@ exports.XRTargetRayMode = void 0;
881
875
  features.length = 0;
882
876
  };
883
877
  _create_class(XRManagerExtended, [
878
+ {
879
+ key: "features",
880
+ get: function get() {
881
+ return this._features;
882
+ }
883
+ },
884
884
  {
885
885
  key: "origin",
886
- get: /**
887
- * The current origin of XR space.
888
- * @remarks The connection point between the virtual world and the real world ( XR Space )
889
- */ function get() {
886
+ get: function get() {
890
887
  return this._origin;
891
888
  },
892
889
  set: function set(value) {
@@ -979,50 +976,6 @@ ApplyMixins(miniprogram.XRManager, [
979
976
  return XRFeature;
980
977
  }();
981
978
 
982
- /**
983
- * Enum for the types of hit test that can be performed.
984
- * Note: currently only supports plane.
985
- */ exports.TrackableType = void 0;
986
- (function(TrackableType) {
987
- TrackableType[TrackableType[/** Tracked plane. */ "Plane"] = 0x1] = "Plane";
988
- TrackableType[TrackableType[/** All tracked objects. */ "All"] = 0x1] = "All";
989
- })(exports.TrackableType || (exports.TrackableType = {}));
990
-
991
- /**
992
- * XR hit result.
993
- * It is the detection result returned by using XR HitTest feature.
994
- */ var XRHitResult = function XRHitResult() {
995
- /** The position of the hit point. */ this.point = new miniprogram.Vector3();
996
- /** The normal of the hit point. */ this.normal = new miniprogram.Vector3();
997
- };
998
-
999
- /******************************************************************************
1000
- Copyright (c) Microsoft Corporation.
1001
-
1002
- Permission to use, copy, modify, and/or distribute this software for any
1003
- purpose with or without fee is hereby granted.
1004
-
1005
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1006
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1007
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1008
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1009
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1010
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1011
- PERFORMANCE OF THIS SOFTWARE.
1012
- ***************************************************************************** */
1013
-
1014
- function __decorate(decorators, target, key, desc) {
1015
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1016
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1017
- 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;
1018
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1019
- }
1020
-
1021
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1022
- var e = new Error(message);
1023
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1024
- };
1025
-
1026
979
  exports.XRFeatureType = void 0;
1027
980
  (function(XRFeatureType) {
1028
981
  XRFeatureType[XRFeatureType["AnchorTracking"] = 0] = "AnchorTracking";
@@ -1054,7 +1007,7 @@ exports.XRRequestTrackingState = void 0;
1054
1007
  _this._updated = [];
1055
1008
  _this._removed = [];
1056
1009
  _this._statusSnapshot = {};
1057
- _this._listeners = [];
1010
+ _this._listeners = new miniprogram.SafeLoopArray();
1058
1011
  return _this;
1059
1012
  }
1060
1013
  var _proto = XRTrackableFeature.prototype;
@@ -1062,22 +1015,22 @@ exports.XRRequestTrackingState = void 0;
1062
1015
  * Add a listening function for tracked object changes.
1063
1016
  * @param listener - The listening function
1064
1017
  */ _proto.addChangedListener = function addChangedListener(listener) {
1065
- this._listeners.push(listener);
1018
+ this._listeners.push({
1019
+ fn: listener
1020
+ });
1066
1021
  };
1067
1022
  /**
1068
1023
  * Remove a listening function of tracked object changes.
1069
1024
  * @param listener - The listening function
1070
1025
  */ _proto.removeChangedListener = function removeChangedListener(listener) {
1071
- var _this = this, listeners = _this._listeners;
1072
- var index = listeners.indexOf(listener);
1073
- if (index >= 0) {
1074
- listeners.splice(index, 1);
1075
- }
1026
+ this._listeners.findAndRemove(function(value) {
1027
+ return value.fn === listener ? value.destroyed = true : false;
1028
+ });
1076
1029
  };
1077
1030
  _proto._onUpdate = function _onUpdate() {
1078
1031
  var _this__xrManager_sessionManager = this._xrManager.sessionManager, platformSession = _this__xrManager_sessionManager._platformSession;
1079
1032
  var platformFrame = platformSession.frame;
1080
- 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;
1033
+ var _this = this, platformFeature = _this._platformFeature, requestTrackings = _this._requestTrackings, statusSnapshot = _this._statusSnapshot, allTracked = _this._tracked, added = _this._added, updated = _this._updated, removed = _this._removed;
1081
1034
  if (!platformFrame || !requestTrackings.length) {
1082
1035
  return;
1083
1036
  }
@@ -1129,8 +1082,10 @@ exports.XRRequestTrackingState = void 0;
1129
1082
  requestTrackings[i1].state === exports.XRRequestTrackingState.Destroyed && requestTrackings.splice(i1, 1);
1130
1083
  }
1131
1084
  if (added.length > 0 || updated.length > 0 || removed.length > 0) {
1085
+ var listeners = this._listeners.getLoopArray();
1132
1086
  for(var i2 = 0, n3 = listeners.length; i2 < n3; i2++){
1133
- listeners[i2](added, updated, removed);
1087
+ var listener = listeners[i2];
1088
+ !listener.destroyed && listener.fn(added, updated, removed);
1134
1089
  }
1135
1090
  }
1136
1091
  };
@@ -1140,10 +1095,9 @@ exports.XRRequestTrackingState = void 0;
1140
1095
  _proto._onSessionExit = function _onSessionExit() {
1141
1096
  // prettier-ignore
1142
1097
  this._requestTrackings.length = this._tracked.length = this._added.length = this._updated.length = this._removed.length = 0;
1143
- };
1144
- _proto._onDestroy = function _onDestroy() {
1145
- // prettier-ignore
1146
- this._requestTrackings.length = this._tracked.length = this._added.length = this._updated.length = this._removed.length = 0;
1098
+ this._listeners.findAndRemove(function(value) {
1099
+ return value.destroyed = true;
1100
+ });
1147
1101
  };
1148
1102
  _proto._addRequestTracking = function _addRequestTracking(requestTracking) {
1149
1103
  var _this = this, platformFeature = _this._platformFeature;
@@ -1176,6 +1130,57 @@ exports.XRRequestTrackingState = void 0;
1176
1130
  XRTrackableFeature._uuid = 0;
1177
1131
  })();
1178
1132
 
1133
+ /**
1134
+ * The base class of XR tracked object.
1135
+ */ var XRTracked = function XRTracked() {
1136
+ /** The pose of the trackable in XR space. */ this.pose = new XRPose();
1137
+ /** The tracking state of the trackable. */ this.state = exports.XRTrackingState.NotTracking;
1138
+ };
1139
+
1140
+ /**
1141
+ * Enum for the types of hit test that can be performed.
1142
+ * Note: currently only supports plane.
1143
+ */ exports.TrackableType = void 0;
1144
+ (function(TrackableType) {
1145
+ TrackableType[TrackableType[/** Tracked plane. */ "Plane"] = 0x1] = "Plane";
1146
+ TrackableType[TrackableType[/** All tracked objects. */ "All"] = 0x1] = "All";
1147
+ })(exports.TrackableType || (exports.TrackableType = {}));
1148
+
1149
+ /**
1150
+ * XR hit result.
1151
+ * It is the detection result returned by using XR HitTest feature.
1152
+ */ var XRHitResult = function XRHitResult() {
1153
+ /** The position of the hit point. */ this.point = new miniprogram.Vector3();
1154
+ /** The normal of the hit point. */ this.normal = new miniprogram.Vector3();
1155
+ };
1156
+
1157
+ /******************************************************************************
1158
+ Copyright (c) Microsoft Corporation.
1159
+
1160
+ Permission to use, copy, modify, and/or distribute this software for any
1161
+ purpose with or without fee is hereby granted.
1162
+
1163
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1164
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1165
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1166
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1167
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1168
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1169
+ PERFORMANCE OF THIS SOFTWARE.
1170
+ ***************************************************************************** */
1171
+
1172
+ function __decorate(decorators, target, key, desc) {
1173
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1174
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1175
+ 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;
1176
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1177
+ }
1178
+
1179
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1180
+ var e = new Error(message);
1181
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1182
+ };
1183
+
1179
1184
  /**
1180
1185
  * Enumerates modes of plane in XR.
1181
1186
  */ exports.XRPlaneMode = void 0;
@@ -1206,13 +1211,6 @@ exports.XRRequestTrackingState = void 0;
1206
1211
  return XRRequestPlane;
1207
1212
  }(XRRequestTracking);
1208
1213
 
1209
- /**
1210
- * The base class of XR tracked object.
1211
- */ var XRTracked = function XRTracked() {
1212
- /** The pose of the trackable in XR space. */ this.pose = new XRPose();
1213
- /** The tracking state of the trackable. */ this.state = exports.XRTrackingState.NotTracking;
1214
- };
1215
-
1216
1214
  /**
1217
1215
  * The tracked plane in XR space.
1218
1216
  */ var XRTrackedPlane = /*#__PURE__*/ function(XRTracked1) {
@@ -1560,6 +1558,64 @@ exports.XRImageTracking = __decorate([
1560
1558
  this.physicalWidth = physicalWidth;
1561
1559
  };
1562
1560
 
1561
+ exports.XRReferenceImageDecoder = /*#__PURE__*/ function() {
1562
+ function XRReferenceImageDecoder() {}
1563
+ XRReferenceImageDecoder.decode = function decode(engine, bufferReader) {
1564
+ return new Promise(function(resolve, reject) {
1565
+ var physicalWidth = bufferReader.nextFloat32();
1566
+ bufferReader.nextUint8();
1567
+ var img = new engineMiniprogramAdapter.Image();
1568
+ img.onload = function() {
1569
+ resolve(new XRReferenceImage("", img, physicalWidth));
1570
+ };
1571
+ img.src = engineMiniprogramAdapter.URL.createObjectURL(new engineMiniprogramAdapter.window.Blob([
1572
+ bufferReader.nextImagesData(1)[0]
1573
+ ]));
1574
+ });
1575
+ };
1576
+ return XRReferenceImageDecoder;
1577
+ }();
1578
+ exports.XRReferenceImageDecoder = __decorate([
1579
+ miniprogram.decoder("XRReferenceImage")
1580
+ ], exports.XRReferenceImageDecoder);
1581
+
1582
+ function _extends() {
1583
+ _extends = Object.assign || function assign(target) {
1584
+ for (var i = 1; i < arguments.length; i++) {
1585
+ var source = arguments[i];
1586
+ for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
1587
+ }
1588
+
1589
+ return target;
1590
+ };
1591
+
1592
+ return _extends.apply(this, arguments);
1593
+ }
1594
+
1595
+ exports.XRReferenceImageLoader = /*#__PURE__*/ function(Loader1) {
1596
+ _inherits(XRReferenceImageLoader, Loader1);
1597
+ function XRReferenceImageLoader() {
1598
+ return Loader1.apply(this, arguments);
1599
+ }
1600
+ var _proto = XRReferenceImageLoader.prototype;
1601
+ _proto.load = function load(item, resourceManager) {
1602
+ var _this = this;
1603
+ return new miniprogram.AssetPromise(function(resolve, reject) {
1604
+ _this.request(item.url, _extends({}, item, {
1605
+ type: "arraybuffer"
1606
+ })).then(function(data) {
1607
+ miniprogram.decode(data, resourceManager.engine).then(function(referenceImage) {
1608
+ resolve(referenceImage);
1609
+ });
1610
+ }).catch(reject);
1611
+ });
1612
+ };
1613
+ return XRReferenceImageLoader;
1614
+ }(miniprogram.Loader);
1615
+ exports.XRReferenceImageLoader = __decorate([
1616
+ miniprogram.resourceLoader("XRReferenceImage", [])
1617
+ ], exports.XRReferenceImageLoader);
1618
+
1563
1619
  exports.XRAnchor = XRAnchor;
1564
1620
  exports.XRCamera = XRCamera;
1565
1621
  exports.XRCameraManager = XRCameraManager;
@@ -1570,5 +1626,7 @@ exports.XRInputManager = XRInputManager;
1570
1626
  exports.XRPose = XRPose;
1571
1627
  exports.XRReferenceImage = XRReferenceImage;
1572
1628
  exports.XRSessionManager = XRSessionManager;
1629
+ exports.XRTrackableFeature = XRTrackableFeature;
1630
+ exports.XRTracked = XRTracked;
1573
1631
  exports.XRTrackedImage = XRTrackedImage;
1574
1632
  exports.XRTrackedPlane = XRTrackedPlane;