@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/miniprogram.js
CHANGED
|
@@ -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[/**
|
|
104
|
-
XRSessionState[XRSessionState[/**
|
|
105
|
-
XRSessionState[XRSessionState[/**
|
|
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
|
/**
|
|
@@ -527,6 +528,7 @@ exports.XRTargetRayMode = void 0;
|
|
|
527
528
|
this._engine = _engine;
|
|
528
529
|
this._mode = exports.XRSessionMode.None;
|
|
529
530
|
this._state = exports.XRSessionState.None;
|
|
531
|
+
this._listeners = new miniprogram.SafeLoopArray();
|
|
530
532
|
// @ts-ignore
|
|
531
533
|
this._rhi = _engine._hardwareRenderer;
|
|
532
534
|
this._raf = engineMiniprogramAdapter.requestAnimationFrame.bind(engineMiniprogramAdapter.window);
|
|
@@ -549,7 +551,7 @@ exports.XRTargetRayMode = void 0;
|
|
|
549
551
|
throw new Error("Without session to run.");
|
|
550
552
|
}
|
|
551
553
|
platformSession.start();
|
|
552
|
-
this.
|
|
554
|
+
this._setState(exports.XRSessionState.Running);
|
|
553
555
|
this._xrManager._onSessionStart();
|
|
554
556
|
if (!engine.isPaused) {
|
|
555
557
|
engine.pause();
|
|
@@ -569,7 +571,7 @@ exports.XRTargetRayMode = void 0;
|
|
|
569
571
|
rhi._mainFrameBuffer = null;
|
|
570
572
|
rhi._mainFrameWidth = rhi._mainFrameHeight = 0;
|
|
571
573
|
platformSession.stop();
|
|
572
|
-
this.
|
|
574
|
+
this._setState(exports.XRSessionState.Paused);
|
|
573
575
|
this._xrManager._onSessionStop();
|
|
574
576
|
if (!engine.isPaused) {
|
|
575
577
|
engine.pause();
|
|
@@ -577,6 +579,32 @@ exports.XRTargetRayMode = void 0;
|
|
|
577
579
|
}
|
|
578
580
|
};
|
|
579
581
|
/**
|
|
582
|
+
* Add a listening function for session state changes.
|
|
583
|
+
* @param listener - The listening function
|
|
584
|
+
*/ _proto.addStateChangedListener = function addStateChangedListener(listener) {
|
|
585
|
+
this._listeners.push({
|
|
586
|
+
fn: listener
|
|
587
|
+
});
|
|
588
|
+
};
|
|
589
|
+
/**
|
|
590
|
+
* Remove a listening function of session state changes.
|
|
591
|
+
* @param listener - The listening function
|
|
592
|
+
*/ _proto.removeStateChangedListener = function removeStateChangedListener(listener) {
|
|
593
|
+
this._listeners.findAndRemove(function(value) {
|
|
594
|
+
return value.fn === listener ? value.destroyed = true : false;
|
|
595
|
+
});
|
|
596
|
+
};
|
|
597
|
+
/**
|
|
598
|
+
* @internal
|
|
599
|
+
*/ _proto._setState = function _setState(value) {
|
|
600
|
+
this._state = value;
|
|
601
|
+
var listeners = this._listeners.getLoopArray();
|
|
602
|
+
for(var i = 0, n = listeners.length; i < n; i++){
|
|
603
|
+
var listener = listeners[i];
|
|
604
|
+
!listener.destroyed && listener.fn(value);
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
/**
|
|
580
608
|
* @internal
|
|
581
609
|
*/ _proto._initialize = function _initialize(mode, features) {
|
|
582
610
|
var _this = this;
|
|
@@ -591,7 +619,7 @@ exports.XRTargetRayMode = void 0;
|
|
|
591
619
|
xrManager._platformDevice.requestSession(_this._rhi, mode, platformFeatures).then(function(platformSession) {
|
|
592
620
|
_this._mode = mode;
|
|
593
621
|
_this._platformSession = platformSession;
|
|
594
|
-
_this.
|
|
622
|
+
_this._setState(exports.XRSessionState.Initialized);
|
|
595
623
|
platformSession.setSessionExitCallBack(_this._onSessionExit);
|
|
596
624
|
platformSession.addEventListener();
|
|
597
625
|
xrManager._onSessionInit();
|
|
@@ -640,7 +668,7 @@ exports.XRTargetRayMode = void 0;
|
|
|
640
668
|
rhi._mainFrameWidth = rhi._mainFrameHeight = 0;
|
|
641
669
|
platformSession.removeEventListener();
|
|
642
670
|
this._platformSession = null;
|
|
643
|
-
this.
|
|
671
|
+
this._setState(exports.XRSessionState.None);
|
|
644
672
|
this._xrManager._onSessionExit();
|
|
645
673
|
if (!engine.isPaused) {
|
|
646
674
|
engine.pause();
|
|
@@ -649,7 +677,12 @@ exports.XRTargetRayMode = void 0;
|
|
|
649
677
|
};
|
|
650
678
|
/**
|
|
651
679
|
* @internal
|
|
652
|
-
*/ _proto._onDestroy = function _onDestroy() {
|
|
680
|
+
*/ _proto._onDestroy = function _onDestroy() {
|
|
681
|
+
this._listeners.findAndRemove(function(value) {
|
|
682
|
+
return value.destroyed = true;
|
|
683
|
+
});
|
|
684
|
+
this._raf = this._caf = null;
|
|
685
|
+
};
|
|
653
686
|
_create_class(XRSessionManager, [
|
|
654
687
|
{
|
|
655
688
|
key: "mode",
|
|
@@ -688,47 +721,36 @@ exports.XRTargetRayMode = void 0;
|
|
|
688
721
|
}();
|
|
689
722
|
|
|
690
723
|
/**
|
|
691
|
-
*
|
|
724
|
+
* @internal
|
|
692
725
|
*/ var XRManagerExtended = /*#__PURE__*/ function(XRManager1) {
|
|
693
726
|
_inherits(XRManagerExtended, XRManager1);
|
|
694
727
|
function XRManagerExtended() {
|
|
695
728
|
return XRManager1.apply(this, arguments);
|
|
696
729
|
}
|
|
697
730
|
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) {
|
|
731
|
+
_proto.isSupportedFeature = function isSupportedFeature(feature) {
|
|
703
732
|
return this._platformDevice.isSupportedFeature(XRManagerExtended._featureMap.get(feature));
|
|
704
733
|
};
|
|
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) {
|
|
734
|
+
_proto.addFeature = function addFeature(type) {
|
|
711
735
|
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
712
736
|
args[_key - 1] = arguments[_key];
|
|
713
737
|
}
|
|
714
738
|
if (this.sessionManager._platformSession) {
|
|
715
739
|
throw new Error("Cannot add feature when the session is initialized.");
|
|
716
740
|
}
|
|
717
|
-
|
|
741
|
+
if (!this._platformDevice.isSupportedFeature(XRManagerExtended._featureMap.get(type))) {
|
|
742
|
+
throw new Error("The feature is not supported");
|
|
743
|
+
}
|
|
744
|
+
var features = this.features;
|
|
718
745
|
for(var i = 0, n = features.length; i < n; i++){
|
|
719
|
-
|
|
720
|
-
if (_instanceof(feature, type)) throw new Error("The feature has been added");
|
|
746
|
+
if (_instanceof(features[i], type)) throw new Error("The feature has been added");
|
|
721
747
|
}
|
|
722
|
-
var
|
|
723
|
-
|
|
724
|
-
return
|
|
748
|
+
var feature = _construct(type, [].concat(this, args));
|
|
749
|
+
features.push(feature);
|
|
750
|
+
return feature;
|
|
725
751
|
};
|
|
726
|
-
|
|
727
|
-
|
|
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;
|
|
752
|
+
_proto.getFeature = function getFeature(type) {
|
|
753
|
+
var features = this.features;
|
|
732
754
|
for(var i = 0, n = features.length; i < n; i++){
|
|
733
755
|
var feature = features[i];
|
|
734
756
|
if (_instanceof(feature, type)) {
|
|
@@ -736,25 +758,7 @@ exports.XRTargetRayMode = void 0;
|
|
|
736
758
|
}
|
|
737
759
|
}
|
|
738
760
|
};
|
|
739
|
-
_proto.
|
|
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) {
|
|
761
|
+
_proto.enterXR = function enterXR(sessionMode, autoRun) {
|
|
758
762
|
if (autoRun === void 0) autoRun = true;
|
|
759
763
|
var _this = this;
|
|
760
764
|
var sessionManager = this.sessionManager;
|
|
@@ -767,18 +771,16 @@ exports.XRTargetRayMode = void 0;
|
|
|
767
771
|
return new Promise(function(resolve, reject) {
|
|
768
772
|
// 1. Check if this xr mode is supported
|
|
769
773
|
sessionManager.isSupportedMode(sessionMode).then(function() {
|
|
774
|
+
sessionManager._setState(exports.XRSessionState.Initializing);
|
|
770
775
|
// 2. Initialize session
|
|
771
|
-
sessionManager._initialize(sessionMode, _this.
|
|
776
|
+
sessionManager._initialize(sessionMode, _this.features).then(function() {
|
|
772
777
|
autoRun && sessionManager.run();
|
|
773
778
|
resolve();
|
|
774
779
|
}, reject);
|
|
775
780
|
}, reject);
|
|
776
781
|
});
|
|
777
782
|
};
|
|
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() {
|
|
783
|
+
_proto.exitXR = function exitXR() {
|
|
782
784
|
var _this = this;
|
|
783
785
|
return new Promise(function(resolve, reject) {
|
|
784
786
|
_this.sessionManager._exit().then(function() {
|
|
@@ -786,32 +788,26 @@ exports.XRTargetRayMode = void 0;
|
|
|
786
788
|
}, reject);
|
|
787
789
|
});
|
|
788
790
|
};
|
|
789
|
-
|
|
790
|
-
* @internal
|
|
791
|
-
*/ _proto._initialize = function _initialize(engine, xrDevice) {
|
|
791
|
+
_proto._initialize = function _initialize(engine, xrDevice) {
|
|
792
792
|
this._features = [];
|
|
793
793
|
this._platformDevice = xrDevice;
|
|
794
794
|
this.sessionManager = new XRSessionManager(this, engine);
|
|
795
795
|
this.inputManager = new XRInputManager(this, engine);
|
|
796
796
|
this.cameraManager = new XRCameraManager(this);
|
|
797
797
|
};
|
|
798
|
-
|
|
799
|
-
* @internal
|
|
800
|
-
*/ _proto._update = function _update() {
|
|
798
|
+
_proto._update = function _update() {
|
|
801
799
|
var sessionManager = this.sessionManager;
|
|
802
800
|
if (sessionManager.state !== exports.XRSessionState.Running) return;
|
|
803
801
|
sessionManager._onUpdate();
|
|
804
802
|
this.inputManager._onUpdate();
|
|
805
803
|
this.cameraManager._onUpdate();
|
|
806
|
-
var
|
|
804
|
+
var features = this.features;
|
|
807
805
|
for(var i = 0, n = features.length; i < n; i++){
|
|
808
806
|
var feature = features[i];
|
|
809
807
|
feature.enabled && feature._onUpdate();
|
|
810
808
|
}
|
|
811
809
|
};
|
|
812
|
-
|
|
813
|
-
* @internal
|
|
814
|
-
*/ _proto._destroy = function _destroy() {
|
|
810
|
+
_proto._destroy = function _destroy() {
|
|
815
811
|
var _this = this;
|
|
816
812
|
if (this.sessionManager._platformSession) {
|
|
817
813
|
this.exitXR().then(function() {
|
|
@@ -825,25 +821,19 @@ exports.XRTargetRayMode = void 0;
|
|
|
825
821
|
this.cameraManager._onDestroy();
|
|
826
822
|
}
|
|
827
823
|
};
|
|
828
|
-
|
|
829
|
-
* @internal
|
|
830
|
-
*/ _proto._getRequestAnimationFrame = function _getRequestAnimationFrame() {
|
|
824
|
+
_proto._getRequestAnimationFrame = function _getRequestAnimationFrame() {
|
|
831
825
|
return this.sessionManager._getRequestAnimationFrame();
|
|
832
826
|
};
|
|
833
|
-
|
|
834
|
-
* @internal
|
|
835
|
-
*/ _proto._getCancelAnimationFrame = function _getCancelAnimationFrame() {
|
|
827
|
+
_proto._getCancelAnimationFrame = function _getCancelAnimationFrame() {
|
|
836
828
|
return this.sessionManager._getCancelAnimationFrame();
|
|
837
829
|
};
|
|
838
|
-
|
|
839
|
-
* @internal
|
|
840
|
-
*/ _proto._getCameraClearFlagsMask = function _getCameraClearFlagsMask(type) {
|
|
830
|
+
_proto._getCameraClearFlagsMask = function _getCameraClearFlagsMask(type) {
|
|
841
831
|
return this.cameraManager._getCameraClearFlagsMask(type);
|
|
842
832
|
};
|
|
843
833
|
/**
|
|
844
834
|
* @internal
|
|
845
835
|
*/ _proto._onSessionStop = function _onSessionStop() {
|
|
846
|
-
var
|
|
836
|
+
var features = this.features;
|
|
847
837
|
for(var i = 0, n = features.length; i < n; i++){
|
|
848
838
|
var feature = features[i];
|
|
849
839
|
feature.enabled && feature._onSessionStop();
|
|
@@ -852,7 +842,7 @@ exports.XRTargetRayMode = void 0;
|
|
|
852
842
|
/**
|
|
853
843
|
* @internal
|
|
854
844
|
*/ _proto._onSessionInit = function _onSessionInit() {
|
|
855
|
-
var
|
|
845
|
+
var features = this.features;
|
|
856
846
|
for(var i = 0, n = features.length; i < n; i++){
|
|
857
847
|
var feature = features[i];
|
|
858
848
|
feature.enabled && feature._onSessionInit();
|
|
@@ -862,7 +852,7 @@ exports.XRTargetRayMode = void 0;
|
|
|
862
852
|
* @internal
|
|
863
853
|
*/ _proto._onSessionStart = function _onSessionStart() {
|
|
864
854
|
this.cameraManager._onSessionStart();
|
|
865
|
-
var
|
|
855
|
+
var features = this.features;
|
|
866
856
|
for(var i = 0, n = features.length; i < n; i++){
|
|
867
857
|
var feature = features[i];
|
|
868
858
|
feature.enabled && feature._onSessionStart();
|
|
@@ -872,7 +862,7 @@ exports.XRTargetRayMode = void 0;
|
|
|
872
862
|
* @internal
|
|
873
863
|
*/ _proto._onSessionExit = function _onSessionExit() {
|
|
874
864
|
this.cameraManager._onSessionExit();
|
|
875
|
-
var
|
|
865
|
+
var features = this.features;
|
|
876
866
|
for(var i = 0, n = features.length; i < n; i++){
|
|
877
867
|
var feature = features[i];
|
|
878
868
|
feature.enabled && feature._onSessionExit();
|
|
@@ -881,12 +871,15 @@ exports.XRTargetRayMode = void 0;
|
|
|
881
871
|
features.length = 0;
|
|
882
872
|
};
|
|
883
873
|
_create_class(XRManagerExtended, [
|
|
874
|
+
{
|
|
875
|
+
key: "features",
|
|
876
|
+
get: function get() {
|
|
877
|
+
return this._features;
|
|
878
|
+
}
|
|
879
|
+
},
|
|
884
880
|
{
|
|
885
881
|
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() {
|
|
882
|
+
get: function get() {
|
|
890
883
|
return this._origin;
|
|
891
884
|
},
|
|
892
885
|
set: function set(value) {
|
|
@@ -979,50 +972,6 @@ ApplyMixins(miniprogram.XRManager, [
|
|
|
979
972
|
return XRFeature;
|
|
980
973
|
}();
|
|
981
974
|
|
|
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
975
|
exports.XRFeatureType = void 0;
|
|
1027
976
|
(function(XRFeatureType) {
|
|
1028
977
|
XRFeatureType[XRFeatureType["AnchorTracking"] = 0] = "AnchorTracking";
|
|
@@ -1054,7 +1003,7 @@ exports.XRRequestTrackingState = void 0;
|
|
|
1054
1003
|
_this._updated = [];
|
|
1055
1004
|
_this._removed = [];
|
|
1056
1005
|
_this._statusSnapshot = {};
|
|
1057
|
-
_this._listeners =
|
|
1006
|
+
_this._listeners = new miniprogram.SafeLoopArray();
|
|
1058
1007
|
return _this;
|
|
1059
1008
|
}
|
|
1060
1009
|
var _proto = XRTrackableFeature.prototype;
|
|
@@ -1062,22 +1011,22 @@ exports.XRRequestTrackingState = void 0;
|
|
|
1062
1011
|
* Add a listening function for tracked object changes.
|
|
1063
1012
|
* @param listener - The listening function
|
|
1064
1013
|
*/ _proto.addChangedListener = function addChangedListener(listener) {
|
|
1065
|
-
this._listeners.push(
|
|
1014
|
+
this._listeners.push({
|
|
1015
|
+
fn: listener
|
|
1016
|
+
});
|
|
1066
1017
|
};
|
|
1067
1018
|
/**
|
|
1068
1019
|
* Remove a listening function of tracked object changes.
|
|
1069
1020
|
* @param listener - The listening function
|
|
1070
1021
|
*/ _proto.removeChangedListener = function removeChangedListener(listener) {
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
listeners.splice(index, 1);
|
|
1075
|
-
}
|
|
1022
|
+
this._listeners.findAndRemove(function(value) {
|
|
1023
|
+
return value.fn === listener ? value.destroyed = true : false;
|
|
1024
|
+
});
|
|
1076
1025
|
};
|
|
1077
1026
|
_proto._onUpdate = function _onUpdate() {
|
|
1078
1027
|
var _this__xrManager_sessionManager = this._xrManager.sessionManager, platformSession = _this__xrManager_sessionManager._platformSession;
|
|
1079
1028
|
var platformFrame = platformSession.frame;
|
|
1080
|
-
var _this = this, platformFeature = _this._platformFeature,
|
|
1029
|
+
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
1030
|
if (!platformFrame || !requestTrackings.length) {
|
|
1082
1031
|
return;
|
|
1083
1032
|
}
|
|
@@ -1129,8 +1078,10 @@ exports.XRRequestTrackingState = void 0;
|
|
|
1129
1078
|
requestTrackings[i1].state === exports.XRRequestTrackingState.Destroyed && requestTrackings.splice(i1, 1);
|
|
1130
1079
|
}
|
|
1131
1080
|
if (added.length > 0 || updated.length > 0 || removed.length > 0) {
|
|
1081
|
+
var listeners = this._listeners.getLoopArray();
|
|
1132
1082
|
for(var i2 = 0, n3 = listeners.length; i2 < n3; i2++){
|
|
1133
|
-
listeners[i2]
|
|
1083
|
+
var listener = listeners[i2];
|
|
1084
|
+
!listener.destroyed && listener.fn(added, updated, removed);
|
|
1134
1085
|
}
|
|
1135
1086
|
}
|
|
1136
1087
|
};
|
|
@@ -1140,10 +1091,9 @@ exports.XRRequestTrackingState = void 0;
|
|
|
1140
1091
|
_proto._onSessionExit = function _onSessionExit() {
|
|
1141
1092
|
// prettier-ignore
|
|
1142
1093
|
this._requestTrackings.length = this._tracked.length = this._added.length = this._updated.length = this._removed.length = 0;
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
this._requestTrackings.length = this._tracked.length = this._added.length = this._updated.length = this._removed.length = 0;
|
|
1094
|
+
this._listeners.findAndRemove(function(value) {
|
|
1095
|
+
return value.destroyed = true;
|
|
1096
|
+
});
|
|
1147
1097
|
};
|
|
1148
1098
|
_proto._addRequestTracking = function _addRequestTracking(requestTracking) {
|
|
1149
1099
|
var _this = this, platformFeature = _this._platformFeature;
|
|
@@ -1176,6 +1126,57 @@ exports.XRRequestTrackingState = void 0;
|
|
|
1176
1126
|
XRTrackableFeature._uuid = 0;
|
|
1177
1127
|
})();
|
|
1178
1128
|
|
|
1129
|
+
/**
|
|
1130
|
+
* The base class of XR tracked object.
|
|
1131
|
+
*/ var XRTracked = function XRTracked() {
|
|
1132
|
+
/** The pose of the trackable in XR space. */ this.pose = new XRPose();
|
|
1133
|
+
/** The tracking state of the trackable. */ this.state = exports.XRTrackingState.NotTracking;
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* Enum for the types of hit test that can be performed.
|
|
1138
|
+
* Note: currently only supports plane.
|
|
1139
|
+
*/ exports.TrackableType = void 0;
|
|
1140
|
+
(function(TrackableType) {
|
|
1141
|
+
TrackableType[TrackableType[/** Tracked plane. */ "Plane"] = 0x1] = "Plane";
|
|
1142
|
+
TrackableType[TrackableType[/** All tracked objects. */ "All"] = 0x1] = "All";
|
|
1143
|
+
})(exports.TrackableType || (exports.TrackableType = {}));
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* XR hit result.
|
|
1147
|
+
* It is the detection result returned by using XR HitTest feature.
|
|
1148
|
+
*/ var XRHitResult = function XRHitResult() {
|
|
1149
|
+
/** The position of the hit point. */ this.point = new miniprogram.Vector3();
|
|
1150
|
+
/** The normal of the hit point. */ this.normal = new miniprogram.Vector3();
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
/******************************************************************************
|
|
1154
|
+
Copyright (c) Microsoft Corporation.
|
|
1155
|
+
|
|
1156
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
1157
|
+
purpose with or without fee is hereby granted.
|
|
1158
|
+
|
|
1159
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1160
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1161
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1162
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1163
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1164
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1165
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
1166
|
+
***************************************************************************** */
|
|
1167
|
+
|
|
1168
|
+
function __decorate(decorators, target, key, desc) {
|
|
1169
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1170
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1171
|
+
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;
|
|
1172
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
1176
|
+
var e = new Error(message);
|
|
1177
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1178
|
+
};
|
|
1179
|
+
|
|
1179
1180
|
/**
|
|
1180
1181
|
* Enumerates modes of plane in XR.
|
|
1181
1182
|
*/ exports.XRPlaneMode = void 0;
|
|
@@ -1206,13 +1207,6 @@ exports.XRRequestTrackingState = void 0;
|
|
|
1206
1207
|
return XRRequestPlane;
|
|
1207
1208
|
}(XRRequestTracking);
|
|
1208
1209
|
|
|
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
1210
|
/**
|
|
1217
1211
|
* The tracked plane in XR space.
|
|
1218
1212
|
*/ var XRTrackedPlane = /*#__PURE__*/ function(XRTracked1) {
|
|
@@ -1560,6 +1554,64 @@ exports.XRImageTracking = __decorate([
|
|
|
1560
1554
|
this.physicalWidth = physicalWidth;
|
|
1561
1555
|
};
|
|
1562
1556
|
|
|
1557
|
+
exports.XRReferenceImageDecoder = /*#__PURE__*/ function() {
|
|
1558
|
+
function XRReferenceImageDecoder() {}
|
|
1559
|
+
XRReferenceImageDecoder.decode = function decode(engine, bufferReader) {
|
|
1560
|
+
return new Promise(function(resolve, reject) {
|
|
1561
|
+
var physicalWidth = bufferReader.nextFloat32();
|
|
1562
|
+
bufferReader.nextUint8();
|
|
1563
|
+
var img = new engineMiniprogramAdapter.Image();
|
|
1564
|
+
img.onload = function() {
|
|
1565
|
+
resolve(new XRReferenceImage("", img, physicalWidth));
|
|
1566
|
+
};
|
|
1567
|
+
img.src = engineMiniprogramAdapter.URL.createObjectURL(new engineMiniprogramAdapter.window.Blob([
|
|
1568
|
+
bufferReader.nextImagesData(1)[0]
|
|
1569
|
+
]));
|
|
1570
|
+
});
|
|
1571
|
+
};
|
|
1572
|
+
return XRReferenceImageDecoder;
|
|
1573
|
+
}();
|
|
1574
|
+
exports.XRReferenceImageDecoder = __decorate([
|
|
1575
|
+
miniprogram.decoder("XRReferenceImage")
|
|
1576
|
+
], exports.XRReferenceImageDecoder);
|
|
1577
|
+
|
|
1578
|
+
function _extends() {
|
|
1579
|
+
_extends = Object.assign || function assign(target) {
|
|
1580
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
1581
|
+
var source = arguments[i];
|
|
1582
|
+
for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
return target;
|
|
1586
|
+
};
|
|
1587
|
+
|
|
1588
|
+
return _extends.apply(this, arguments);
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
exports.XRReferenceImageLoader = /*#__PURE__*/ function(Loader1) {
|
|
1592
|
+
_inherits(XRReferenceImageLoader, Loader1);
|
|
1593
|
+
function XRReferenceImageLoader() {
|
|
1594
|
+
return Loader1.apply(this, arguments);
|
|
1595
|
+
}
|
|
1596
|
+
var _proto = XRReferenceImageLoader.prototype;
|
|
1597
|
+
_proto.load = function load(item, resourceManager) {
|
|
1598
|
+
var _this = this;
|
|
1599
|
+
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
1600
|
+
_this.request(item.url, _extends({}, item, {
|
|
1601
|
+
type: "arraybuffer"
|
|
1602
|
+
})).then(function(data) {
|
|
1603
|
+
miniprogram.decode(data, resourceManager.engine).then(function(referenceImage) {
|
|
1604
|
+
resolve(referenceImage);
|
|
1605
|
+
});
|
|
1606
|
+
}).catch(reject);
|
|
1607
|
+
});
|
|
1608
|
+
};
|
|
1609
|
+
return XRReferenceImageLoader;
|
|
1610
|
+
}(miniprogram.Loader);
|
|
1611
|
+
exports.XRReferenceImageLoader = __decorate([
|
|
1612
|
+
miniprogram.resourceLoader("XRReferenceImage", [])
|
|
1613
|
+
], exports.XRReferenceImageLoader);
|
|
1614
|
+
|
|
1563
1615
|
exports.XRAnchor = XRAnchor;
|
|
1564
1616
|
exports.XRCamera = XRCamera;
|
|
1565
1617
|
exports.XRCameraManager = XRCameraManager;
|
|
@@ -1570,5 +1622,7 @@ exports.XRInputManager = XRInputManager;
|
|
|
1570
1622
|
exports.XRPose = XRPose;
|
|
1571
1623
|
exports.XRReferenceImage = XRReferenceImage;
|
|
1572
1624
|
exports.XRSessionManager = XRSessionManager;
|
|
1625
|
+
exports.XRTrackableFeature = XRTrackableFeature;
|
|
1626
|
+
exports.XRTracked = XRTracked;
|
|
1573
1627
|
exports.XRTrackedImage = XRTrackedImage;
|
|
1574
1628
|
exports.XRTrackedPlane = XRTrackedPlane;
|