@galacean/engine-xr-webxr 0.0.0-experimental-stateMachine.0 → 0.0.0-experimental-1.2-xr.0

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
@@ -602,6 +602,7 @@
602
602
  engine.pause();
603
603
  engine.resume();
604
604
  }
605
+ engine.dispatch("XRSessionStart");
605
606
  };
606
607
  /**
607
608
  * Stop the session.
@@ -622,6 +623,7 @@
622
623
  engine.pause();
623
624
  engine.resume();
624
625
  }
626
+ engine.dispatch("XRSessionStop");
625
627
  };
626
628
  /**
627
629
  * @internal
@@ -643,6 +645,7 @@
643
645
  platformSession.addEventListener();
644
646
  xrManager._onSessionInit();
645
647
  resolve();
648
+ _this._engine.dispatch("XRSessionInit");
646
649
  }, reject);
647
650
  });
648
651
  };
@@ -675,11 +678,14 @@
675
678
  /**
676
679
  * @internal
677
680
  */ _proto._exit = function _exit() {
678
- var _this = this, platformSession = _this._platformSession;
681
+ var _this = this;
682
+ var _this1 = this, platformSession = _this1._platformSession;
679
683
  if (!platformSession) {
680
684
  return Promise.reject("Without session to stop.");
681
685
  }
682
- return platformSession.end();
686
+ return platformSession.end().then(function() {
687
+ _this._engine.dispatch("XRSessionExit");
688
+ });
683
689
  };
684
690
  _proto._onSessionExit = function _onSessionExit() {
685
691
  var _this = this, rhi = _this._rhi, platformSession = _this._platformSession, engine = _this._engine;
@@ -761,13 +767,16 @@
761
767
  throw new Error("Cannot add feature when the session is initialized.");
762
768
  }
763
769
  var _this = this, features = _this._features;
770
+ _this._platformDevice;
771
+ if (!this._platformDevice.isSupportedFeature(XRManagerExtended._featureMap.get(type))) {
772
+ throw new Error("The feature is not supported");
773
+ }
764
774
  for(var i = 0, n = features.length; i < n; i++){
765
- var feature = features[i];
766
- if (_instanceof1(feature, type)) throw new Error("The feature has been added");
775
+ if (_instanceof1(features[i], type)) throw new Error("The feature has been added");
767
776
  }
768
- var feature1 = _construct$1(type, [].concat(this, args));
769
- this._features.push(feature1);
770
- return feature1;
777
+ var feature = _construct$1(type, [].concat(this, args));
778
+ this._features.push(feature);
779
+ return feature;
771
780
  };
772
781
  /**
773
782
  * Get feature which match the type.
@@ -782,16 +791,16 @@
782
791
  }
783
792
  }
784
793
  };
785
- _proto.getFeatures = function getFeatures(type, out) {
794
+ _proto.getFeatures = function getFeatures(out) {
795
+ var _this = this, features = _this._features;
796
+ var length = features.length;
786
797
  if (out) {
787
- out.length = 0;
798
+ out.length = length;
788
799
  } else {
789
- out = [];
800
+ out = new Array(length);
790
801
  }
791
- var _this = this, features = _this._features;
792
- for(var i = 0, n = features.length; i < n; i--){
793
- var feature = features[i];
794
- _instanceof1(feature, type) && out.push(feature);
802
+ for(var i = 0; i < length; i--){
803
+ out[i] = features[i];
795
804
  }
796
805
  return out;
797
806
  };
@@ -1024,42 +1033,10 @@
1024
1033
  return XRFeature;
1025
1034
  }();
1026
1035
  /**
1027
- * Enum for the types of hit test that can be performed.
1028
- * Note: currently only supports plane.
1029
- */ var TrackableType;
1030
- (function(TrackableType) {
1031
- TrackableType[TrackableType[/** Tracked plane. */ "Plane"] = 0x1] = "Plane";
1032
- TrackableType[TrackableType[/** All tracked objects. */ "All"] = 0x1] = "All";
1033
- })(TrackableType || (TrackableType = {}));
1034
- /**
1035
- * XR hit result.
1036
- * It is the detection result returned by using XR HitTest feature.
1037
- */ var XRHitResult = function XRHitResult() {
1038
- /** The position of the hit point. */ this.point = new engine.Vector3();
1039
- /** The normal of the hit point. */ this.normal = new engine.Vector3();
1040
- };
1041
- /******************************************************************************
1042
- Copyright (c) Microsoft Corporation.
1043
-
1044
- Permission to use, copy, modify, and/or distribute this software for any
1045
- purpose with or without fee is hereby granted.
1046
-
1047
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1048
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1049
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1050
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1051
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1052
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1053
- PERFORMANCE OF THIS SOFTWARE.
1054
- ***************************************************************************** */ function __decorate(decorators, target, key, desc) {
1055
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1056
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1057
- 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;
1058
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1059
- }
1060
- typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
1061
- var e = new Error(message);
1062
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1036
+ * The base class of XR tracked object.
1037
+ */ var XRTracked = function XRTracked() {
1038
+ /** The pose of the trackable in XR space. */ this.pose = new XRPose();
1039
+ /** The tracking state of the trackable. */ this.state = XRTrackingState.NotTracking;
1063
1040
  };
1064
1041
  var XRFeatureType;
1065
1042
  (function(XRFeatureType) {
@@ -1211,6 +1188,44 @@
1211
1188
  (function() {
1212
1189
  XRTrackableFeature._uuid = 0;
1213
1190
  })();
1191
+ /**
1192
+ * Enum for the types of hit test that can be performed.
1193
+ * Note: currently only supports plane.
1194
+ */ var TrackableType;
1195
+ (function(TrackableType) {
1196
+ TrackableType[TrackableType[/** Tracked plane. */ "Plane"] = 0x1] = "Plane";
1197
+ TrackableType[TrackableType[/** All tracked objects. */ "All"] = 0x1] = "All";
1198
+ })(TrackableType || (TrackableType = {}));
1199
+ /**
1200
+ * XR hit result.
1201
+ * It is the detection result returned by using XR HitTest feature.
1202
+ */ var XRHitResult = function XRHitResult() {
1203
+ /** The position of the hit point. */ this.point = new engine.Vector3();
1204
+ /** The normal of the hit point. */ this.normal = new engine.Vector3();
1205
+ };
1206
+ /******************************************************************************
1207
+ Copyright (c) Microsoft Corporation.
1208
+
1209
+ Permission to use, copy, modify, and/or distribute this software for any
1210
+ purpose with or without fee is hereby granted.
1211
+
1212
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1213
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1214
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1215
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1216
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1217
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1218
+ PERFORMANCE OF THIS SOFTWARE.
1219
+ ***************************************************************************** */ function __decorate(decorators, target, key, desc) {
1220
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1221
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1222
+ 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;
1223
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1224
+ }
1225
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
1226
+ var e = new Error(message);
1227
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1228
+ };
1214
1229
  /**
1215
1230
  * Enumerates modes of plane in XR.
1216
1231
  */ var XRPlaneMode;
@@ -1238,12 +1253,6 @@
1238
1253
  _inherits(XRRequestPlane, XRRequestTracking1);
1239
1254
  return XRRequestPlane;
1240
1255
  }(XRRequestTracking);
1241
- /**
1242
- * The base class of XR tracked object.
1243
- */ var XRTracked = function XRTracked() {
1244
- /** The pose of the trackable in XR space. */ this.pose = new XRPose();
1245
- /** The tracking state of the trackable. */ this.state = XRTrackingState.NotTracking;
1246
- };
1247
1256
  /**
1248
1257
  * The tracked plane in XR space.
1249
1258
  */ var XRTrackedPlane = /*#__PURE__*/ function(XRTracked1) {
@@ -5973,7 +5982,7 @@
5973
5982
  session.removeEventListener("squeeze", onSessionEvent);
5974
5983
  session.removeEventListener("squeezestart", onSessionEvent);
5975
5984
  session.removeEventListener("squeezeend", onSessionEvent);
5976
- session.addEventListener("end", this._onSessionExit);
5985
+ session.removeEventListener("end", this._onSessionExit);
5977
5986
  this._events.length = 0;
5978
5987
  };
5979
5988
  _proto.resetEvents = function resetEvents() {
@@ -6116,7 +6125,18 @@
6116
6125
  });
6117
6126
  };
6118
6127
  _proto.isSupportedFeature = function isSupportedFeature(type) {
6119
- return true;
6128
+ switch(type){
6129
+ case XRFeatureType.HitTest:
6130
+ case XRFeatureType.PlaneTracking:
6131
+ // @ts-ignore
6132
+ return !!window.XRPlane;
6133
+ case XRFeatureType.AnchorTracking:
6134
+ // @ts-ignore
6135
+ return !!window.XRAnchor;
6136
+ case XRFeatureType.ImageTracking:
6137
+ // @ts-ignore
6138
+ return !!window.XRImageTrackingResult;
6139
+ }
6120
6140
  };
6121
6141
  _proto.createPlatformFeature = function createPlatformFeature(type) {
6122
6142
  for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){