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