@galacean/engine-xr 1.3.0-alpha.2 → 1.3.0-beta.5
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 +201 -147
- package/dist/browser.js.map +1 -1
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +1 -1
- package/dist/main.js +201 -147
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +201 -147
- package/dist/module.js +201 -149
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/XRManagerExtended.d.ts +7 -64
- package/types/feature/trackable/XRTrackableFeature.d.ts +1 -2
- package/types/index.d.ts +4 -0
- package/types/loader/XRReferenceImageDecoder.d.ts +5 -0
- package/types/loader/XRReferenceImageLoader.d.ts +5 -0
- package/types/session/XRSessionManager.d.ts +11 -0
- package/types/session/XRSessionState.d.ts +5 -3
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CameraType, Matrix, CameraClearFlags, Vector3, Quaternion, Rect, XRManager, Ray, Plane, Vector2 } from '@galacean/engine';
|
|
1
|
+
import { CameraType, Matrix, CameraClearFlags, Vector3, Quaternion, Rect, SafeLoopArray, XRManager, Ray, Plane, Vector2, decoder, resourceLoader, AssetPromise, decode, Loader } from '@galacean/engine';
|
|
2
2
|
|
|
3
3
|
function _is_native_reflect_construct() {
|
|
4
4
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
@@ -95,9 +95,10 @@ function _instanceof(left, right) {
|
|
|
95
95
|
*/ var XRSessionState;
|
|
96
96
|
(function(XRSessionState) {
|
|
97
97
|
XRSessionState[XRSessionState[/** Not initialized. */ "None"] = 0] = "None";
|
|
98
|
-
XRSessionState[XRSessionState[/**
|
|
99
|
-
XRSessionState[XRSessionState[/**
|
|
100
|
-
XRSessionState[XRSessionState[/**
|
|
98
|
+
XRSessionState[XRSessionState[/** Initializing session. */ "Initializing"] = 1] = "Initializing";
|
|
99
|
+
XRSessionState[XRSessionState[/** Initialized but not started. */ "Initialized"] = 2] = "Initialized";
|
|
100
|
+
XRSessionState[XRSessionState[/** Running. */ "Running"] = 3] = "Running";
|
|
101
|
+
XRSessionState[XRSessionState[/** Paused. */ "Paused"] = 4] = "Paused";
|
|
101
102
|
})(XRSessionState || (XRSessionState = {}));
|
|
102
103
|
|
|
103
104
|
/**
|
|
@@ -522,6 +523,7 @@ var XRTargetRayMode;
|
|
|
522
523
|
this._engine = _engine;
|
|
523
524
|
this._mode = XRSessionMode.None;
|
|
524
525
|
this._state = XRSessionState.None;
|
|
526
|
+
this._listeners = new SafeLoopArray();
|
|
525
527
|
// @ts-ignore
|
|
526
528
|
this._rhi = _engine._hardwareRenderer;
|
|
527
529
|
this._raf = requestAnimationFrame.bind(window);
|
|
@@ -544,7 +546,7 @@ var XRTargetRayMode;
|
|
|
544
546
|
throw new Error("Without session to run.");
|
|
545
547
|
}
|
|
546
548
|
platformSession.start();
|
|
547
|
-
this.
|
|
549
|
+
this._setState(XRSessionState.Running);
|
|
548
550
|
this._xrManager._onSessionStart();
|
|
549
551
|
if (!engine.isPaused) {
|
|
550
552
|
engine.pause();
|
|
@@ -564,7 +566,7 @@ var XRTargetRayMode;
|
|
|
564
566
|
rhi._mainFrameBuffer = null;
|
|
565
567
|
rhi._mainFrameWidth = rhi._mainFrameHeight = 0;
|
|
566
568
|
platformSession.stop();
|
|
567
|
-
this.
|
|
569
|
+
this._setState(XRSessionState.Paused);
|
|
568
570
|
this._xrManager._onSessionStop();
|
|
569
571
|
if (!engine.isPaused) {
|
|
570
572
|
engine.pause();
|
|
@@ -572,6 +574,32 @@ var XRTargetRayMode;
|
|
|
572
574
|
}
|
|
573
575
|
};
|
|
574
576
|
/**
|
|
577
|
+
* Add a listening function for session state changes.
|
|
578
|
+
* @param listener - The listening function
|
|
579
|
+
*/ _proto.addStateChangedListener = function addStateChangedListener(listener) {
|
|
580
|
+
this._listeners.push({
|
|
581
|
+
fn: listener
|
|
582
|
+
});
|
|
583
|
+
};
|
|
584
|
+
/**
|
|
585
|
+
* Remove a listening function of session state changes.
|
|
586
|
+
* @param listener - The listening function
|
|
587
|
+
*/ _proto.removeStateChangedListener = function removeStateChangedListener(listener) {
|
|
588
|
+
this._listeners.findAndRemove(function(value) {
|
|
589
|
+
return value.fn === listener ? value.destroyed = true : false;
|
|
590
|
+
});
|
|
591
|
+
};
|
|
592
|
+
/**
|
|
593
|
+
* @internal
|
|
594
|
+
*/ _proto._setState = function _setState(value) {
|
|
595
|
+
this._state = value;
|
|
596
|
+
var listeners = this._listeners.getLoopArray();
|
|
597
|
+
for(var i = 0, n = listeners.length; i < n; i++){
|
|
598
|
+
var listener = listeners[i];
|
|
599
|
+
!listener.destroyed && listener.fn(value);
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
/**
|
|
575
603
|
* @internal
|
|
576
604
|
*/ _proto._initialize = function _initialize(mode, features) {
|
|
577
605
|
var _this = this;
|
|
@@ -586,7 +614,7 @@ var XRTargetRayMode;
|
|
|
586
614
|
xrManager._platformDevice.requestSession(_this._rhi, mode, platformFeatures).then(function(platformSession) {
|
|
587
615
|
_this._mode = mode;
|
|
588
616
|
_this._platformSession = platformSession;
|
|
589
|
-
_this.
|
|
617
|
+
_this._setState(XRSessionState.Initialized);
|
|
590
618
|
platformSession.setSessionExitCallBack(_this._onSessionExit);
|
|
591
619
|
platformSession.addEventListener();
|
|
592
620
|
xrManager._onSessionInit();
|
|
@@ -635,7 +663,7 @@ var XRTargetRayMode;
|
|
|
635
663
|
rhi._mainFrameWidth = rhi._mainFrameHeight = 0;
|
|
636
664
|
platformSession.removeEventListener();
|
|
637
665
|
this._platformSession = null;
|
|
638
|
-
this.
|
|
666
|
+
this._setState(XRSessionState.None);
|
|
639
667
|
this._xrManager._onSessionExit();
|
|
640
668
|
if (!engine.isPaused) {
|
|
641
669
|
engine.pause();
|
|
@@ -644,7 +672,12 @@ var XRTargetRayMode;
|
|
|
644
672
|
};
|
|
645
673
|
/**
|
|
646
674
|
* @internal
|
|
647
|
-
*/ _proto._onDestroy = function _onDestroy() {
|
|
675
|
+
*/ _proto._onDestroy = function _onDestroy() {
|
|
676
|
+
this._listeners.findAndRemove(function(value) {
|
|
677
|
+
return value.destroyed = true;
|
|
678
|
+
});
|
|
679
|
+
this._raf = this._caf = null;
|
|
680
|
+
};
|
|
648
681
|
_create_class(XRSessionManager, [
|
|
649
682
|
{
|
|
650
683
|
key: "mode",
|
|
@@ -683,47 +716,36 @@ var XRTargetRayMode;
|
|
|
683
716
|
}();
|
|
684
717
|
|
|
685
718
|
/**
|
|
686
|
-
*
|
|
719
|
+
* @internal
|
|
687
720
|
*/ var XRManagerExtended = /*#__PURE__*/ function(XRManager1) {
|
|
688
721
|
_inherits(XRManagerExtended, XRManager1);
|
|
689
722
|
function XRManagerExtended() {
|
|
690
723
|
return XRManager1.apply(this, arguments);
|
|
691
724
|
}
|
|
692
725
|
var _proto = XRManagerExtended.prototype;
|
|
693
|
-
|
|
694
|
-
* Check if the specified feature is supported.
|
|
695
|
-
* @param type - The type of the feature
|
|
696
|
-
* @returns If the feature is supported
|
|
697
|
-
*/ _proto.isSupportedFeature = function isSupportedFeature(feature) {
|
|
726
|
+
_proto.isSupportedFeature = function isSupportedFeature(feature) {
|
|
698
727
|
return this._platformDevice.isSupportedFeature(XRManagerExtended._featureMap.get(feature));
|
|
699
728
|
};
|
|
700
|
-
|
|
701
|
-
* Add feature based on the xr feature type.
|
|
702
|
-
* @param type - The type of the feature
|
|
703
|
-
* @param args - The constructor params of the feature
|
|
704
|
-
* @returns The feature which has been added
|
|
705
|
-
*/ _proto.addFeature = function addFeature(type) {
|
|
729
|
+
_proto.addFeature = function addFeature(type) {
|
|
706
730
|
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
707
731
|
args[_key - 1] = arguments[_key];
|
|
708
732
|
}
|
|
709
733
|
if (this.sessionManager._platformSession) {
|
|
710
734
|
throw new Error("Cannot add feature when the session is initialized.");
|
|
711
735
|
}
|
|
712
|
-
|
|
736
|
+
if (!this._platformDevice.isSupportedFeature(XRManagerExtended._featureMap.get(type))) {
|
|
737
|
+
throw new Error("The feature is not supported");
|
|
738
|
+
}
|
|
739
|
+
var features = this.features;
|
|
713
740
|
for(var i = 0, n = features.length; i < n; i++){
|
|
714
|
-
|
|
715
|
-
if (_instanceof(feature, type)) throw new Error("The feature has been added");
|
|
741
|
+
if (_instanceof(features[i], type)) throw new Error("The feature has been added");
|
|
716
742
|
}
|
|
717
|
-
var
|
|
718
|
-
|
|
719
|
-
return
|
|
743
|
+
var feature = _construct(type, [].concat(this, args));
|
|
744
|
+
features.push(feature);
|
|
745
|
+
return feature;
|
|
720
746
|
};
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
* @param type - The type of the feature
|
|
724
|
-
* @returns The feature which match type
|
|
725
|
-
*/ _proto.getFeature = function getFeature(type) {
|
|
726
|
-
var _this = this, features = _this._features;
|
|
747
|
+
_proto.getFeature = function getFeature(type) {
|
|
748
|
+
var features = this.features;
|
|
727
749
|
for(var i = 0, n = features.length; i < n; i++){
|
|
728
750
|
var feature = features[i];
|
|
729
751
|
if (_instanceof(feature, type)) {
|
|
@@ -731,25 +753,7 @@ var XRTargetRayMode;
|
|
|
731
753
|
}
|
|
732
754
|
}
|
|
733
755
|
};
|
|
734
|
-
_proto.
|
|
735
|
-
if (out) {
|
|
736
|
-
out.length = 0;
|
|
737
|
-
} else {
|
|
738
|
-
out = [];
|
|
739
|
-
}
|
|
740
|
-
var _this = this, features = _this._features;
|
|
741
|
-
for(var i = 0, n = features.length; i < n; i--){
|
|
742
|
-
var feature = features[i];
|
|
743
|
-
_instanceof(feature, type) && out.push(feature);
|
|
744
|
-
}
|
|
745
|
-
return out;
|
|
746
|
-
};
|
|
747
|
-
/**
|
|
748
|
-
* Enter XR immersive mode, when you call this method, it will initialize and display the XR virtual world.
|
|
749
|
-
* @param sessionMode - The mode of the session
|
|
750
|
-
* @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.
|
|
751
|
-
* @returns A promise that resolves if the XR virtual world is entered, otherwise rejects
|
|
752
|
-
*/ _proto.enterXR = function enterXR(sessionMode, autoRun) {
|
|
756
|
+
_proto.enterXR = function enterXR(sessionMode, autoRun) {
|
|
753
757
|
if (autoRun === void 0) autoRun = true;
|
|
754
758
|
var _this = this;
|
|
755
759
|
var sessionManager = this.sessionManager;
|
|
@@ -762,18 +766,16 @@ var XRTargetRayMode;
|
|
|
762
766
|
return new Promise(function(resolve, reject) {
|
|
763
767
|
// 1. Check if this xr mode is supported
|
|
764
768
|
sessionManager.isSupportedMode(sessionMode).then(function() {
|
|
769
|
+
sessionManager._setState(XRSessionState.Initializing);
|
|
765
770
|
// 2. Initialize session
|
|
766
|
-
sessionManager._initialize(sessionMode, _this.
|
|
771
|
+
sessionManager._initialize(sessionMode, _this.features).then(function() {
|
|
767
772
|
autoRun && sessionManager.run();
|
|
768
773
|
resolve();
|
|
769
774
|
}, reject);
|
|
770
775
|
}, reject);
|
|
771
776
|
});
|
|
772
777
|
};
|
|
773
|
-
|
|
774
|
-
* Exit XR immersive mode, when you call this method, it will destroy the XR virtual world.
|
|
775
|
-
* @returns A promise that resolves if the XR virtual world is destroyed, otherwise rejects
|
|
776
|
-
*/ _proto.exitXR = function exitXR() {
|
|
778
|
+
_proto.exitXR = function exitXR() {
|
|
777
779
|
var _this = this;
|
|
778
780
|
return new Promise(function(resolve, reject) {
|
|
779
781
|
_this.sessionManager._exit().then(function() {
|
|
@@ -781,32 +783,26 @@ var XRTargetRayMode;
|
|
|
781
783
|
}, reject);
|
|
782
784
|
});
|
|
783
785
|
};
|
|
784
|
-
|
|
785
|
-
* @internal
|
|
786
|
-
*/ _proto._initialize = function _initialize(engine, xrDevice) {
|
|
786
|
+
_proto._initialize = function _initialize(engine, xrDevice) {
|
|
787
787
|
this._features = [];
|
|
788
788
|
this._platformDevice = xrDevice;
|
|
789
789
|
this.sessionManager = new XRSessionManager(this, engine);
|
|
790
790
|
this.inputManager = new XRInputManager(this, engine);
|
|
791
791
|
this.cameraManager = new XRCameraManager(this);
|
|
792
792
|
};
|
|
793
|
-
|
|
794
|
-
* @internal
|
|
795
|
-
*/ _proto._update = function _update() {
|
|
793
|
+
_proto._update = function _update() {
|
|
796
794
|
var sessionManager = this.sessionManager;
|
|
797
795
|
if (sessionManager.state !== XRSessionState.Running) return;
|
|
798
796
|
sessionManager._onUpdate();
|
|
799
797
|
this.inputManager._onUpdate();
|
|
800
798
|
this.cameraManager._onUpdate();
|
|
801
|
-
var
|
|
799
|
+
var features = this.features;
|
|
802
800
|
for(var i = 0, n = features.length; i < n; i++){
|
|
803
801
|
var feature = features[i];
|
|
804
802
|
feature.enabled && feature._onUpdate();
|
|
805
803
|
}
|
|
806
804
|
};
|
|
807
|
-
|
|
808
|
-
* @internal
|
|
809
|
-
*/ _proto._destroy = function _destroy() {
|
|
805
|
+
_proto._destroy = function _destroy() {
|
|
810
806
|
var _this = this;
|
|
811
807
|
if (this.sessionManager._platformSession) {
|
|
812
808
|
this.exitXR().then(function() {
|
|
@@ -820,25 +816,19 @@ var XRTargetRayMode;
|
|
|
820
816
|
this.cameraManager._onDestroy();
|
|
821
817
|
}
|
|
822
818
|
};
|
|
823
|
-
|
|
824
|
-
* @internal
|
|
825
|
-
*/ _proto._getRequestAnimationFrame = function _getRequestAnimationFrame() {
|
|
819
|
+
_proto._getRequestAnimationFrame = function _getRequestAnimationFrame() {
|
|
826
820
|
return this.sessionManager._getRequestAnimationFrame();
|
|
827
821
|
};
|
|
828
|
-
|
|
829
|
-
* @internal
|
|
830
|
-
*/ _proto._getCancelAnimationFrame = function _getCancelAnimationFrame() {
|
|
822
|
+
_proto._getCancelAnimationFrame = function _getCancelAnimationFrame() {
|
|
831
823
|
return this.sessionManager._getCancelAnimationFrame();
|
|
832
824
|
};
|
|
833
|
-
|
|
834
|
-
* @internal
|
|
835
|
-
*/ _proto._getCameraClearFlagsMask = function _getCameraClearFlagsMask(type) {
|
|
825
|
+
_proto._getCameraClearFlagsMask = function _getCameraClearFlagsMask(type) {
|
|
836
826
|
return this.cameraManager._getCameraClearFlagsMask(type);
|
|
837
827
|
};
|
|
838
828
|
/**
|
|
839
829
|
* @internal
|
|
840
830
|
*/ _proto._onSessionStop = function _onSessionStop() {
|
|
841
|
-
var
|
|
831
|
+
var features = this.features;
|
|
842
832
|
for(var i = 0, n = features.length; i < n; i++){
|
|
843
833
|
var feature = features[i];
|
|
844
834
|
feature.enabled && feature._onSessionStop();
|
|
@@ -847,7 +837,7 @@ var XRTargetRayMode;
|
|
|
847
837
|
/**
|
|
848
838
|
* @internal
|
|
849
839
|
*/ _proto._onSessionInit = function _onSessionInit() {
|
|
850
|
-
var
|
|
840
|
+
var features = this.features;
|
|
851
841
|
for(var i = 0, n = features.length; i < n; i++){
|
|
852
842
|
var feature = features[i];
|
|
853
843
|
feature.enabled && feature._onSessionInit();
|
|
@@ -857,7 +847,7 @@ var XRTargetRayMode;
|
|
|
857
847
|
* @internal
|
|
858
848
|
*/ _proto._onSessionStart = function _onSessionStart() {
|
|
859
849
|
this.cameraManager._onSessionStart();
|
|
860
|
-
var
|
|
850
|
+
var features = this.features;
|
|
861
851
|
for(var i = 0, n = features.length; i < n; i++){
|
|
862
852
|
var feature = features[i];
|
|
863
853
|
feature.enabled && feature._onSessionStart();
|
|
@@ -867,7 +857,7 @@ var XRTargetRayMode;
|
|
|
867
857
|
* @internal
|
|
868
858
|
*/ _proto._onSessionExit = function _onSessionExit() {
|
|
869
859
|
this.cameraManager._onSessionExit();
|
|
870
|
-
var
|
|
860
|
+
var features = this.features;
|
|
871
861
|
for(var i = 0, n = features.length; i < n; i++){
|
|
872
862
|
var feature = features[i];
|
|
873
863
|
feature.enabled && feature._onSessionExit();
|
|
@@ -876,12 +866,15 @@ var XRTargetRayMode;
|
|
|
876
866
|
features.length = 0;
|
|
877
867
|
};
|
|
878
868
|
_create_class(XRManagerExtended, [
|
|
869
|
+
{
|
|
870
|
+
key: "features",
|
|
871
|
+
get: function get() {
|
|
872
|
+
return this._features;
|
|
873
|
+
}
|
|
874
|
+
},
|
|
879
875
|
{
|
|
880
876
|
key: "origin",
|
|
881
|
-
get:
|
|
882
|
-
* The current origin of XR space.
|
|
883
|
-
* @remarks The connection point between the virtual world and the real world ( XR Space )
|
|
884
|
-
*/ function get() {
|
|
877
|
+
get: function get() {
|
|
885
878
|
return this._origin;
|
|
886
879
|
},
|
|
887
880
|
set: function set(value) {
|
|
@@ -974,50 +967,6 @@ ApplyMixins(XRManager, [
|
|
|
974
967
|
return XRFeature;
|
|
975
968
|
}();
|
|
976
969
|
|
|
977
|
-
/**
|
|
978
|
-
* Enum for the types of hit test that can be performed.
|
|
979
|
-
* Note: currently only supports plane.
|
|
980
|
-
*/ var TrackableType;
|
|
981
|
-
(function(TrackableType) {
|
|
982
|
-
TrackableType[TrackableType[/** Tracked plane. */ "Plane"] = 0x1] = "Plane";
|
|
983
|
-
TrackableType[TrackableType[/** All tracked objects. */ "All"] = 0x1] = "All";
|
|
984
|
-
})(TrackableType || (TrackableType = {}));
|
|
985
|
-
|
|
986
|
-
/**
|
|
987
|
-
* XR hit result.
|
|
988
|
-
* It is the detection result returned by using XR HitTest feature.
|
|
989
|
-
*/ var XRHitResult = function XRHitResult() {
|
|
990
|
-
/** The position of the hit point. */ this.point = new Vector3();
|
|
991
|
-
/** The normal of the hit point. */ this.normal = new Vector3();
|
|
992
|
-
};
|
|
993
|
-
|
|
994
|
-
/******************************************************************************
|
|
995
|
-
Copyright (c) Microsoft Corporation.
|
|
996
|
-
|
|
997
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
998
|
-
purpose with or without fee is hereby granted.
|
|
999
|
-
|
|
1000
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1001
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1002
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1003
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1004
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1005
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1006
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
1007
|
-
***************************************************************************** */
|
|
1008
|
-
|
|
1009
|
-
function __decorate(decorators, target, key, desc) {
|
|
1010
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1011
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1012
|
-
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;
|
|
1013
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
1017
|
-
var e = new Error(message);
|
|
1018
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1019
|
-
};
|
|
1020
|
-
|
|
1021
970
|
var XRFeatureType;
|
|
1022
971
|
(function(XRFeatureType) {
|
|
1023
972
|
XRFeatureType[XRFeatureType["AnchorTracking"] = 0] = "AnchorTracking";
|
|
@@ -1049,7 +998,7 @@ var XRRequestTrackingState;
|
|
|
1049
998
|
_this._updated = [];
|
|
1050
999
|
_this._removed = [];
|
|
1051
1000
|
_this._statusSnapshot = {};
|
|
1052
|
-
_this._listeners =
|
|
1001
|
+
_this._listeners = new SafeLoopArray();
|
|
1053
1002
|
return _this;
|
|
1054
1003
|
}
|
|
1055
1004
|
var _proto = XRTrackableFeature.prototype;
|
|
@@ -1057,22 +1006,22 @@ var XRRequestTrackingState;
|
|
|
1057
1006
|
* Add a listening function for tracked object changes.
|
|
1058
1007
|
* @param listener - The listening function
|
|
1059
1008
|
*/ _proto.addChangedListener = function addChangedListener(listener) {
|
|
1060
|
-
this._listeners.push(
|
|
1009
|
+
this._listeners.push({
|
|
1010
|
+
fn: listener
|
|
1011
|
+
});
|
|
1061
1012
|
};
|
|
1062
1013
|
/**
|
|
1063
1014
|
* Remove a listening function of tracked object changes.
|
|
1064
1015
|
* @param listener - The listening function
|
|
1065
1016
|
*/ _proto.removeChangedListener = function removeChangedListener(listener) {
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
listeners.splice(index, 1);
|
|
1070
|
-
}
|
|
1017
|
+
this._listeners.findAndRemove(function(value) {
|
|
1018
|
+
return value.fn === listener ? value.destroyed = true : false;
|
|
1019
|
+
});
|
|
1071
1020
|
};
|
|
1072
1021
|
_proto._onUpdate = function _onUpdate() {
|
|
1073
1022
|
var _this__xrManager_sessionManager = this._xrManager.sessionManager, platformSession = _this__xrManager_sessionManager._platformSession;
|
|
1074
1023
|
var platformFrame = platformSession.frame;
|
|
1075
|
-
var _this = this, platformFeature = _this._platformFeature,
|
|
1024
|
+
var _this = this, platformFeature = _this._platformFeature, requestTrackings = _this._requestTrackings, statusSnapshot = _this._statusSnapshot, allTracked = _this._tracked, added = _this._added, updated = _this._updated, removed = _this._removed;
|
|
1076
1025
|
if (!platformFrame || !requestTrackings.length) {
|
|
1077
1026
|
return;
|
|
1078
1027
|
}
|
|
@@ -1124,8 +1073,10 @@ var XRRequestTrackingState;
|
|
|
1124
1073
|
requestTrackings[i1].state === XRRequestTrackingState.Destroyed && requestTrackings.splice(i1, 1);
|
|
1125
1074
|
}
|
|
1126
1075
|
if (added.length > 0 || updated.length > 0 || removed.length > 0) {
|
|
1076
|
+
var listeners = this._listeners.getLoopArray();
|
|
1127
1077
|
for(var i2 = 0, n3 = listeners.length; i2 < n3; i2++){
|
|
1128
|
-
listeners[i2]
|
|
1078
|
+
var listener = listeners[i2];
|
|
1079
|
+
!listener.destroyed && listener.fn(added, updated, removed);
|
|
1129
1080
|
}
|
|
1130
1081
|
}
|
|
1131
1082
|
};
|
|
@@ -1135,10 +1086,9 @@ var XRRequestTrackingState;
|
|
|
1135
1086
|
_proto._onSessionExit = function _onSessionExit() {
|
|
1136
1087
|
// prettier-ignore
|
|
1137
1088
|
this._requestTrackings.length = this._tracked.length = this._added.length = this._updated.length = this._removed.length = 0;
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
this._requestTrackings.length = this._tracked.length = this._added.length = this._updated.length = this._removed.length = 0;
|
|
1089
|
+
this._listeners.findAndRemove(function(value) {
|
|
1090
|
+
return value.destroyed = true;
|
|
1091
|
+
});
|
|
1142
1092
|
};
|
|
1143
1093
|
_proto._addRequestTracking = function _addRequestTracking(requestTracking) {
|
|
1144
1094
|
var _this = this, platformFeature = _this._platformFeature;
|
|
@@ -1171,6 +1121,57 @@ var XRRequestTrackingState;
|
|
|
1171
1121
|
XRTrackableFeature._uuid = 0;
|
|
1172
1122
|
})();
|
|
1173
1123
|
|
|
1124
|
+
/**
|
|
1125
|
+
* The base class of XR tracked object.
|
|
1126
|
+
*/ var XRTracked = function XRTracked() {
|
|
1127
|
+
/** The pose of the trackable in XR space. */ this.pose = new XRPose();
|
|
1128
|
+
/** The tracking state of the trackable. */ this.state = XRTrackingState.NotTracking;
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* Enum for the types of hit test that can be performed.
|
|
1133
|
+
* Note: currently only supports plane.
|
|
1134
|
+
*/ var TrackableType;
|
|
1135
|
+
(function(TrackableType) {
|
|
1136
|
+
TrackableType[TrackableType[/** Tracked plane. */ "Plane"] = 0x1] = "Plane";
|
|
1137
|
+
TrackableType[TrackableType[/** All tracked objects. */ "All"] = 0x1] = "All";
|
|
1138
|
+
})(TrackableType || (TrackableType = {}));
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
* XR hit result.
|
|
1142
|
+
* It is the detection result returned by using XR HitTest feature.
|
|
1143
|
+
*/ var XRHitResult = function XRHitResult() {
|
|
1144
|
+
/** The position of the hit point. */ this.point = new Vector3();
|
|
1145
|
+
/** The normal of the hit point. */ this.normal = new Vector3();
|
|
1146
|
+
};
|
|
1147
|
+
|
|
1148
|
+
/******************************************************************************
|
|
1149
|
+
Copyright (c) Microsoft Corporation.
|
|
1150
|
+
|
|
1151
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
1152
|
+
purpose with or without fee is hereby granted.
|
|
1153
|
+
|
|
1154
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1155
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1156
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1157
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1158
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1159
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1160
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
1161
|
+
***************************************************************************** */
|
|
1162
|
+
|
|
1163
|
+
function __decorate(decorators, target, key, desc) {
|
|
1164
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1165
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1166
|
+
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;
|
|
1167
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
1171
|
+
var e = new Error(message);
|
|
1172
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1174
1175
|
/**
|
|
1175
1176
|
* Enumerates modes of plane in XR.
|
|
1176
1177
|
*/ var XRPlaneMode;
|
|
@@ -1201,13 +1202,6 @@ var XRRequestTrackingState;
|
|
|
1201
1202
|
return XRRequestPlane;
|
|
1202
1203
|
}(XRRequestTracking);
|
|
1203
1204
|
|
|
1204
|
-
/**
|
|
1205
|
-
* The base class of XR tracked object.
|
|
1206
|
-
*/ var XRTracked = function XRTracked() {
|
|
1207
|
-
/** The pose of the trackable in XR space. */ this.pose = new XRPose();
|
|
1208
|
-
/** The tracking state of the trackable. */ this.state = XRTrackingState.NotTracking;
|
|
1209
|
-
};
|
|
1210
|
-
|
|
1211
1205
|
/**
|
|
1212
1206
|
* The tracked plane in XR space.
|
|
1213
1207
|
*/ var XRTrackedPlane = /*#__PURE__*/ function(XRTracked1) {
|
|
@@ -1555,5 +1549,63 @@ XRImageTracking = __decorate([
|
|
|
1555
1549
|
this.physicalWidth = physicalWidth;
|
|
1556
1550
|
};
|
|
1557
1551
|
|
|
1558
|
-
|
|
1552
|
+
var XRReferenceImageDecoder = /*#__PURE__*/ function() {
|
|
1553
|
+
function XRReferenceImageDecoder() {}
|
|
1554
|
+
XRReferenceImageDecoder.decode = function decode(engine, bufferReader) {
|
|
1555
|
+
return new Promise(function(resolve, reject) {
|
|
1556
|
+
var physicalWidth = bufferReader.nextFloat32();
|
|
1557
|
+
bufferReader.nextUint8();
|
|
1558
|
+
var img = new Image();
|
|
1559
|
+
img.onload = function() {
|
|
1560
|
+
resolve(new XRReferenceImage("", img, physicalWidth));
|
|
1561
|
+
};
|
|
1562
|
+
img.src = URL.createObjectURL(new window.Blob([
|
|
1563
|
+
bufferReader.nextImagesData(1)[0]
|
|
1564
|
+
]));
|
|
1565
|
+
});
|
|
1566
|
+
};
|
|
1567
|
+
return XRReferenceImageDecoder;
|
|
1568
|
+
}();
|
|
1569
|
+
XRReferenceImageDecoder = __decorate([
|
|
1570
|
+
decoder("XRReferenceImage")
|
|
1571
|
+
], XRReferenceImageDecoder);
|
|
1572
|
+
|
|
1573
|
+
function _extends() {
|
|
1574
|
+
_extends = Object.assign || function assign(target) {
|
|
1575
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
1576
|
+
var source = arguments[i];
|
|
1577
|
+
for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
return target;
|
|
1581
|
+
};
|
|
1582
|
+
|
|
1583
|
+
return _extends.apply(this, arguments);
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
var XRReferenceImageLoader = /*#__PURE__*/ function(Loader1) {
|
|
1587
|
+
_inherits(XRReferenceImageLoader, Loader1);
|
|
1588
|
+
function XRReferenceImageLoader() {
|
|
1589
|
+
return Loader1.apply(this, arguments);
|
|
1590
|
+
}
|
|
1591
|
+
var _proto = XRReferenceImageLoader.prototype;
|
|
1592
|
+
_proto.load = function load(item, resourceManager) {
|
|
1593
|
+
var _this = this;
|
|
1594
|
+
return new AssetPromise(function(resolve, reject) {
|
|
1595
|
+
_this.request(item.url, _extends({}, item, {
|
|
1596
|
+
type: "arraybuffer"
|
|
1597
|
+
})).then(function(data) {
|
|
1598
|
+
decode(data, resourceManager.engine).then(function(referenceImage) {
|
|
1599
|
+
resolve(referenceImage);
|
|
1600
|
+
});
|
|
1601
|
+
}).catch(reject);
|
|
1602
|
+
});
|
|
1603
|
+
};
|
|
1604
|
+
return XRReferenceImageLoader;
|
|
1605
|
+
}(Loader);
|
|
1606
|
+
XRReferenceImageLoader = __decorate([
|
|
1607
|
+
resourceLoader("XRReferenceImage", [])
|
|
1608
|
+
], XRReferenceImageLoader);
|
|
1609
|
+
|
|
1610
|
+
export { TrackableType, XRAnchor, XRAnchorTracking, XRCamera, XRCameraManager, XRController, XRFeature, XRFeatureType, XRHitResult, XRHitTest, XRImageTracking, XRInputButton, XRInputEventType, XRInputManager, XRPlaneMode, XRPlaneTracking, XRPose, XRReferenceImage, XRReferenceImageDecoder, XRReferenceImageLoader, XRRequestTrackingState, XRSessionManager, XRSessionMode, XRSessionState, XRTargetRayMode, XRTrackableFeature, XRTracked, XRTrackedImage, XRTrackedInputDevice, XRTrackedPlane, XRTrackingState };
|
|
1559
1611
|
//# sourceMappingURL=module.js.map
|