@galacean/engine-core 1.5.3 → 1.5.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/main.js CHANGED
@@ -695,6 +695,186 @@ var Logger = {
695
695
  return GLCapabilityType;
696
696
  }({});
697
697
 
698
+ var AssetPromise = /*#__PURE__*/ function() {
699
+ function AssetPromise(executor) {
700
+ var _this = this;
701
+ this._state = "pending";
702
+ this._onTaskCompleteCallbacks = [];
703
+ this._onTaskDetailCallbacks = [];
704
+ this._promise = new Promise(function(resolve, reject) {
705
+ _this._reject = reject;
706
+ var onResolve = function(value) {
707
+ if (_this._state === "pending") {
708
+ resolve(value);
709
+ _this._state = "fulfilled";
710
+ _this._onTaskCompleteCallbacks = undefined;
711
+ _this._onTaskDetailCallbacks = undefined;
712
+ }
713
+ };
714
+ var onReject = function(reason) {
715
+ if (_this._state === "pending") {
716
+ reject(reason);
717
+ _this._state = "rejected";
718
+ _this._onTaskCompleteCallbacks = undefined;
719
+ _this._onTaskDetailCallbacks = undefined;
720
+ }
721
+ };
722
+ var onCancel = function(callback) {
723
+ if (_this._state === "pending") {
724
+ _this._onCancelHandler = callback;
725
+ }
726
+ };
727
+ var setTaskCompleteProgress = function(loaded, total) {
728
+ if (_this._state === "pending") {
729
+ var progress = _this._taskCompleteProgress || (_this._taskCompleteProgress = {
730
+ loaded: loaded,
731
+ total: total
732
+ });
733
+ progress.loaded = loaded;
734
+ progress.total = total;
735
+ _this._onTaskCompleteCallbacks.forEach(function(callback) {
736
+ return callback(loaded, total);
737
+ });
738
+ }
739
+ };
740
+ var setTaskDetailProgress = function(url, loaded, total) {
741
+ if (_this._state === "pending") {
742
+ var _this__taskDetailProgress, _url;
743
+ _this._taskDetailProgress || (_this._taskDetailProgress = {});
744
+ var progress = (_this__taskDetailProgress = _this._taskDetailProgress)[_url = url] || (_this__taskDetailProgress[_url] = {
745
+ loaded: loaded,
746
+ total: total
747
+ });
748
+ progress.loaded = loaded;
749
+ progress.total = total;
750
+ _this._onTaskDetailCallbacks.forEach(function(callback) {
751
+ return callback(url, loaded, total);
752
+ });
753
+ }
754
+ };
755
+ executor(onResolve, onReject, setTaskCompleteProgress, setTaskDetailProgress, onCancel);
756
+ });
757
+ }
758
+ var _proto = AssetPromise.prototype;
759
+ /**
760
+ * Progress callback.
761
+ * @param onTaskComplete - This callback function provides information about the overall progress of the task. For example, in batch processing tasks, you can use the loaded and total parameters to calculate the percentage of task completion or display a progress bar
762
+ * @param onTaskDetail - This callback function provides detailed progress information about the task. For instance, in file downloading scenarios, you can use the loaded and total parameters to calculate the download progress percentage and utilize the url parameter to provide additional details such as download speed and estimated remaining time
763
+ * @returns AssetPromise
764
+ */ _proto.onProgress = function onProgress(onTaskComplete, onTaskDetail) {
765
+ var completeProgress = this._taskCompleteProgress;
766
+ var detailProgress = this._taskDetailProgress;
767
+ if (completeProgress) {
768
+ onTaskComplete(completeProgress.loaded, completeProgress.total);
769
+ }
770
+ if (detailProgress) {
771
+ for(var url in detailProgress){
772
+ var _detailProgress_url = detailProgress[url], loaded = _detailProgress_url.loaded, total = _detailProgress_url.total;
773
+ onTaskDetail(url, loaded, total);
774
+ }
775
+ }
776
+ if (this._state === "pending") {
777
+ onTaskComplete && this._onTaskCompleteCallbacks.push(onTaskComplete);
778
+ onTaskDetail && this._onTaskDetailCallbacks.push(onTaskDetail);
779
+ }
780
+ return this;
781
+ };
782
+ _proto.then = function then(onfulfilled, onrejected) {
783
+ var _this = this;
784
+ return new AssetPromise(function(resolve, reject) {
785
+ _this._promise.then(onfulfilled, onrejected).then(resolve).catch(reject);
786
+ });
787
+ };
788
+ /**
789
+ * Attaches a callback for only the rejection of the Promise.
790
+ * @param onRejected - The callback to execute when the Promise is rejected.
791
+ * @returns A Promise for the completion of the callback.
792
+ */ _proto.catch = function _catch(onRejected) {
793
+ var _this = this;
794
+ return new AssetPromise(function(resolve, reject) {
795
+ _this._promise.catch(onRejected).then(resolve).catch(reject);
796
+ });
797
+ };
798
+ /**
799
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
800
+ * resolved value cannot be modified from the callback.
801
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
802
+ * @returns A Promise for the completion of the callback.
803
+ */ _proto.finally = function _finally(onFinally) {
804
+ return this._promise.finally(onFinally);
805
+ };
806
+ /**
807
+ * Cancel promise request.
808
+ * @returns Asset promise
809
+ */ _proto.cancel = function cancel() {
810
+ if (this._state !== "pending") {
811
+ return;
812
+ }
813
+ this._state = "canceled";
814
+ this._reject("canceled");
815
+ this._onCancelHandler && this._onCancelHandler();
816
+ return this;
817
+ };
818
+ AssetPromise.resolve = function resolve(value) {
819
+ if (value === undefined) {
820
+ return new AssetPromise(function(resolve) {
821
+ return resolve();
822
+ });
823
+ } else if (_instanceof(value, AssetPromise) || _instanceof(value, Promise)) {
824
+ return new AssetPromise(function(resolve, reject) {
825
+ value.then(function(resolved) {
826
+ return resolve(resolved);
827
+ }, reject);
828
+ });
829
+ } else {
830
+ return new AssetPromise(function(resolve) {
831
+ return resolve(value);
832
+ });
833
+ }
834
+ };
835
+ AssetPromise.all = function all(values) {
836
+ return new AssetPromise(function(resolve, reject, setTaskCompleteProgress) {
837
+ var onComplete = function onComplete(index, resultValue) {
838
+ completed++;
839
+ results[index] = resultValue;
840
+ setTaskCompleteProgress(completed, count);
841
+ if (completed === count) {
842
+ resolve(results);
843
+ }
844
+ };
845
+ var onProgress = function onProgress(promise, index) {
846
+ if (_instanceof(promise, AssetPromise) || _instanceof(promise, Promise)) {
847
+ promise.then(function(value) {
848
+ onComplete(index, value);
849
+ }, reject);
850
+ } else {
851
+ Promise.resolve().then(function() {
852
+ onComplete(index, promise);
853
+ });
854
+ }
855
+ };
856
+ var count = Array.from(values).length;
857
+ var results = new Array(count);
858
+ var completed = 0;
859
+ if (count === 0) {
860
+ return resolve(results);
861
+ }
862
+ for(var i = 0; i < count; i++){
863
+ onProgress(values[i], i);
864
+ }
865
+ });
866
+ };
867
+ _create_class(AssetPromise, [
868
+ {
869
+ key: Symbol.toStringTag,
870
+ get: /** compatible with Promise */ function get() {
871
+ return "AssetPromise";
872
+ }
873
+ }
874
+ ]);
875
+ return AssetPromise;
876
+ }();
877
+
698
878
  /**
699
879
  * Access operating system, platform and hardware information.
700
880
  */ var SystemInfo = /*#__PURE__*/ function() {
@@ -798,6 +978,27 @@ var Logger = {
798
978
  }
799
979
  return this._simdSupported;
800
980
  };
981
+ SystemInfo._checkWebpSupported = function _checkWebpSupported() {
982
+ var _this = this;
983
+ if (!this._webpSupported) {
984
+ this._webpSupported = new AssetPromise(function(resolve) {
985
+ if (_this._isBrowser) {
986
+ var img = new Image();
987
+ img.onload = function() {
988
+ var result = img.width > 0 && img.height > 0;
989
+ resolve(result);
990
+ };
991
+ img.onerror = function() {
992
+ resolve(false);
993
+ };
994
+ img.src = "data:image/webp;base64,UklGRhACAABXRUJQVlA4WAoAAAAwAAAAAAAAAAAASUNDUMgBAAAAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogAAAAAAAA9tYAAQAAAADTLXBhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABtbHVjAAAAAAAAAAEAAAAMZW5VUwAAACAAAAAcAEcAbwBvAGcAbABlACAASQBuAGMALgAgADIAMAAxADZBTFBIAgAAAAAAVlA4IBgAAAAwAQCdASoBAAEAAUAmJaQAA3AA/v02aAA=";
995
+ } else {
996
+ resolve(false);
997
+ }
998
+ });
999
+ }
1000
+ return this._webpSupported;
1001
+ };
801
1002
  /**
802
1003
  * Checks whether the system supports the given texture format.
803
1004
  * @param format - The texture format
@@ -851,6 +1052,7 @@ var Logger = {
851
1052
  /** The operating system is running on. */ SystemInfo.operatingSystem = "";
852
1053
  /** @internal */ SystemInfo._isBrowser = true;
853
1054
  /** Whether the system support SIMD. */ SystemInfo._simdSupported = null;
1055
+ SystemInfo._webpSupported = null;
854
1056
  SystemInfo._initialize();
855
1057
 
856
1058
  /**
@@ -23331,186 +23533,6 @@ var SafeLoopArray = /*#__PURE__*/ function() {
23331
23533
  return SceneManager;
23332
23534
  }();
23333
23535
 
23334
- var AssetPromise = /*#__PURE__*/ function() {
23335
- function AssetPromise(executor) {
23336
- var _this = this;
23337
- this._state = "pending";
23338
- this._onTaskCompleteCallbacks = [];
23339
- this._onTaskDetailCallbacks = [];
23340
- this._promise = new Promise(function(resolve, reject) {
23341
- _this._reject = reject;
23342
- var onResolve = function(value) {
23343
- if (_this._state === "pending") {
23344
- resolve(value);
23345
- _this._state = "fulfilled";
23346
- _this._onTaskCompleteCallbacks = undefined;
23347
- _this._onTaskDetailCallbacks = undefined;
23348
- }
23349
- };
23350
- var onReject = function(reason) {
23351
- if (_this._state === "pending") {
23352
- reject(reason);
23353
- _this._state = "rejected";
23354
- _this._onTaskCompleteCallbacks = undefined;
23355
- _this._onTaskDetailCallbacks = undefined;
23356
- }
23357
- };
23358
- var onCancel = function(callback) {
23359
- if (_this._state === "pending") {
23360
- _this._onCancelHandler = callback;
23361
- }
23362
- };
23363
- var setTaskCompleteProgress = function(loaded, total) {
23364
- if (_this._state === "pending") {
23365
- var progress = _this._taskCompleteProgress || (_this._taskCompleteProgress = {
23366
- loaded: loaded,
23367
- total: total
23368
- });
23369
- progress.loaded = loaded;
23370
- progress.total = total;
23371
- _this._onTaskCompleteCallbacks.forEach(function(callback) {
23372
- return callback(loaded, total);
23373
- });
23374
- }
23375
- };
23376
- var setTaskDetailProgress = function(url, loaded, total) {
23377
- if (_this._state === "pending") {
23378
- var _this__taskDetailProgress, _url;
23379
- _this._taskDetailProgress || (_this._taskDetailProgress = {});
23380
- var progress = (_this__taskDetailProgress = _this._taskDetailProgress)[_url = url] || (_this__taskDetailProgress[_url] = {
23381
- loaded: loaded,
23382
- total: total
23383
- });
23384
- progress.loaded = loaded;
23385
- progress.total = total;
23386
- _this._onTaskDetailCallbacks.forEach(function(callback) {
23387
- return callback(url, loaded, total);
23388
- });
23389
- }
23390
- };
23391
- executor(onResolve, onReject, setTaskCompleteProgress, setTaskDetailProgress, onCancel);
23392
- });
23393
- }
23394
- var _proto = AssetPromise.prototype;
23395
- /**
23396
- * Progress callback.
23397
- * @param onTaskComplete - This callback function provides information about the overall progress of the task. For example, in batch processing tasks, you can use the loaded and total parameters to calculate the percentage of task completion or display a progress bar
23398
- * @param onTaskDetail - This callback function provides detailed progress information about the task. For instance, in file downloading scenarios, you can use the loaded and total parameters to calculate the download progress percentage and utilize the url parameter to provide additional details such as download speed and estimated remaining time
23399
- * @returns AssetPromise
23400
- */ _proto.onProgress = function onProgress(onTaskComplete, onTaskDetail) {
23401
- var completeProgress = this._taskCompleteProgress;
23402
- var detailProgress = this._taskDetailProgress;
23403
- if (completeProgress) {
23404
- onTaskComplete(completeProgress.loaded, completeProgress.total);
23405
- }
23406
- if (detailProgress) {
23407
- for(var url in detailProgress){
23408
- var _detailProgress_url = detailProgress[url], loaded = _detailProgress_url.loaded, total = _detailProgress_url.total;
23409
- onTaskDetail(url, loaded, total);
23410
- }
23411
- }
23412
- if (this._state === "pending") {
23413
- onTaskComplete && this._onTaskCompleteCallbacks.push(onTaskComplete);
23414
- onTaskDetail && this._onTaskDetailCallbacks.push(onTaskDetail);
23415
- }
23416
- return this;
23417
- };
23418
- _proto.then = function then(onfulfilled, onrejected) {
23419
- var _this = this;
23420
- return new AssetPromise(function(resolve, reject) {
23421
- _this._promise.then(onfulfilled, onrejected).then(resolve).catch(reject);
23422
- });
23423
- };
23424
- /**
23425
- * Attaches a callback for only the rejection of the Promise.
23426
- * @param onRejected - The callback to execute when the Promise is rejected.
23427
- * @returns A Promise for the completion of the callback.
23428
- */ _proto.catch = function _catch(onRejected) {
23429
- var _this = this;
23430
- return new AssetPromise(function(resolve, reject) {
23431
- _this._promise.catch(onRejected).then(resolve).catch(reject);
23432
- });
23433
- };
23434
- /**
23435
- * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
23436
- * resolved value cannot be modified from the callback.
23437
- * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
23438
- * @returns A Promise for the completion of the callback.
23439
- */ _proto.finally = function _finally(onFinally) {
23440
- return this._promise.finally(onFinally);
23441
- };
23442
- /**
23443
- * Cancel promise request.
23444
- * @returns Asset promise
23445
- */ _proto.cancel = function cancel() {
23446
- if (this._state !== "pending") {
23447
- return;
23448
- }
23449
- this._state = "canceled";
23450
- this._reject("canceled");
23451
- this._onCancelHandler && this._onCancelHandler();
23452
- return this;
23453
- };
23454
- AssetPromise.resolve = function resolve(value) {
23455
- if (value === undefined) {
23456
- return new AssetPromise(function(resolve) {
23457
- return resolve();
23458
- });
23459
- } else if (_instanceof(value, AssetPromise) || _instanceof(value, Promise)) {
23460
- return new AssetPromise(function(resolve, reject) {
23461
- value.then(function(resolved) {
23462
- return resolve(resolved);
23463
- }, reject);
23464
- });
23465
- } else {
23466
- return new AssetPromise(function(resolve) {
23467
- return resolve(value);
23468
- });
23469
- }
23470
- };
23471
- AssetPromise.all = function all(values) {
23472
- return new AssetPromise(function(resolve, reject, setTaskCompleteProgress) {
23473
- var onComplete = function onComplete(index, resultValue) {
23474
- completed++;
23475
- results[index] = resultValue;
23476
- setTaskCompleteProgress(completed, count);
23477
- if (completed === count) {
23478
- resolve(results);
23479
- }
23480
- };
23481
- var onProgress = function onProgress(promise, index) {
23482
- if (_instanceof(promise, AssetPromise) || _instanceof(promise, Promise)) {
23483
- promise.then(function(value) {
23484
- onComplete(index, value);
23485
- }, reject);
23486
- } else {
23487
- Promise.resolve().then(function() {
23488
- onComplete(index, promise);
23489
- });
23490
- }
23491
- };
23492
- var count = Array.from(values).length;
23493
- var results = new Array(count);
23494
- var completed = 0;
23495
- if (count === 0) {
23496
- return resolve(results);
23497
- }
23498
- for(var i = 0; i < count; i++){
23499
- onProgress(values[i], i);
23500
- }
23501
- });
23502
- };
23503
- _create_class(AssetPromise, [
23504
- {
23505
- key: Symbol.toStringTag,
23506
- get: /** compatible with Promise */ function get() {
23507
- return "AssetPromise";
23508
- }
23509
- }
23510
- ]);
23511
- return AssetPromise;
23512
- }();
23513
-
23514
23536
  var mimeType = {
23515
23537
  json: "json",
23516
23538
  gltf: "json",