@galacean/engine 1.5.2 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -5781,6 +5781,185 @@
5781
5781
  GLCapabilityType["sRGB"] = "EXT_sRGB";
5782
5782
  return GLCapabilityType;
5783
5783
  }({});
5784
+ var AssetPromise = /*#__PURE__*/ function() {
5785
+ function AssetPromise(executor) {
5786
+ var _this = this;
5787
+ this._state = "pending";
5788
+ this._onTaskCompleteCallbacks = [];
5789
+ this._onTaskDetailCallbacks = [];
5790
+ this._promise = new Promise(function(resolve, reject) {
5791
+ _this._reject = reject;
5792
+ var onResolve = function onResolve(value) {
5793
+ if (_this._state === "pending") {
5794
+ resolve(value);
5795
+ _this._state = "fulfilled";
5796
+ _this._onTaskCompleteCallbacks = undefined;
5797
+ _this._onTaskDetailCallbacks = undefined;
5798
+ }
5799
+ };
5800
+ var onReject = function onReject(reason) {
5801
+ if (_this._state === "pending") {
5802
+ reject(reason);
5803
+ _this._state = "rejected";
5804
+ _this._onTaskCompleteCallbacks = undefined;
5805
+ _this._onTaskDetailCallbacks = undefined;
5806
+ }
5807
+ };
5808
+ var onCancel = function onCancel(callback) {
5809
+ if (_this._state === "pending") {
5810
+ _this._onCancelHandler = callback;
5811
+ }
5812
+ };
5813
+ var setTaskCompleteProgress = function setTaskCompleteProgress(loaded, total) {
5814
+ if (_this._state === "pending") {
5815
+ var progress = _this._taskCompleteProgress || (_this._taskCompleteProgress = {
5816
+ loaded: loaded,
5817
+ total: total
5818
+ });
5819
+ progress.loaded = loaded;
5820
+ progress.total = total;
5821
+ _this._onTaskCompleteCallbacks.forEach(function(callback) {
5822
+ return callback(loaded, total);
5823
+ });
5824
+ }
5825
+ };
5826
+ var setTaskDetailProgress = function setTaskDetailProgress(url, loaded, total) {
5827
+ if (_this._state === "pending") {
5828
+ var _this__taskDetailProgress, _url;
5829
+ _this._taskDetailProgress || (_this._taskDetailProgress = {});
5830
+ var progress = (_this__taskDetailProgress = _this._taskDetailProgress)[_url = url] || (_this__taskDetailProgress[_url] = {
5831
+ loaded: loaded,
5832
+ total: total
5833
+ });
5834
+ progress.loaded = loaded;
5835
+ progress.total = total;
5836
+ _this._onTaskDetailCallbacks.forEach(function(callback) {
5837
+ return callback(url, loaded, total);
5838
+ });
5839
+ }
5840
+ };
5841
+ executor(onResolve, onReject, setTaskCompleteProgress, setTaskDetailProgress, onCancel);
5842
+ });
5843
+ }
5844
+ var _proto = AssetPromise.prototype;
5845
+ /**
5846
+ * Progress callback.
5847
+ * @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
5848
+ * @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
5849
+ * @returns AssetPromise
5850
+ */ _proto.onProgress = function onProgress(onTaskComplete, onTaskDetail) {
5851
+ var completeProgress = this._taskCompleteProgress;
5852
+ var detailProgress = this._taskDetailProgress;
5853
+ if (completeProgress) {
5854
+ onTaskComplete(completeProgress.loaded, completeProgress.total);
5855
+ }
5856
+ if (detailProgress) {
5857
+ for(var url in detailProgress){
5858
+ var _detailProgress_url = detailProgress[url], loaded = _detailProgress_url.loaded, total = _detailProgress_url.total;
5859
+ onTaskDetail(url, loaded, total);
5860
+ }
5861
+ }
5862
+ if (this._state === "pending") {
5863
+ onTaskComplete && this._onTaskCompleteCallbacks.push(onTaskComplete);
5864
+ onTaskDetail && this._onTaskDetailCallbacks.push(onTaskDetail);
5865
+ }
5866
+ return this;
5867
+ };
5868
+ _proto.then = function then(onfulfilled, onrejected) {
5869
+ var _this = this;
5870
+ return new AssetPromise(function(resolve, reject) {
5871
+ _this._promise.then(onfulfilled, onrejected).then(resolve).catch(reject);
5872
+ });
5873
+ };
5874
+ /**
5875
+ * Attaches a callback for only the rejection of the Promise.
5876
+ * @param onRejected - The callback to execute when the Promise is rejected.
5877
+ * @returns A Promise for the completion of the callback.
5878
+ */ _proto.catch = function _catch(onRejected) {
5879
+ var _this = this;
5880
+ return new AssetPromise(function(resolve, reject) {
5881
+ _this._promise.catch(onRejected).then(resolve).catch(reject);
5882
+ });
5883
+ };
5884
+ /**
5885
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
5886
+ * resolved value cannot be modified from the callback.
5887
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
5888
+ * @returns A Promise for the completion of the callback.
5889
+ */ _proto.finally = function _finally(onFinally) {
5890
+ return this._promise.finally(onFinally);
5891
+ };
5892
+ /**
5893
+ * Cancel promise request.
5894
+ * @returns Asset promise
5895
+ */ _proto.cancel = function cancel() {
5896
+ if (this._state !== "pending") {
5897
+ return;
5898
+ }
5899
+ this._state = "canceled";
5900
+ this._reject("canceled");
5901
+ this._onCancelHandler && this._onCancelHandler();
5902
+ return this;
5903
+ };
5904
+ AssetPromise.resolve = function resolve(value) {
5905
+ if (value === undefined) {
5906
+ return new AssetPromise(function(resolve) {
5907
+ return resolve();
5908
+ });
5909
+ } else if (_instanceof1$2(value, AssetPromise) || _instanceof1$2(value, Promise)) {
5910
+ return new AssetPromise(function(resolve, reject) {
5911
+ value.then(function(resolved) {
5912
+ return resolve(resolved);
5913
+ }, reject);
5914
+ });
5915
+ } else {
5916
+ return new AssetPromise(function(resolve) {
5917
+ return resolve(value);
5918
+ });
5919
+ }
5920
+ };
5921
+ AssetPromise.all = function all(values) {
5922
+ return new AssetPromise(function(resolve, reject, setTaskCompleteProgress) {
5923
+ var onComplete = function onComplete(index, resultValue) {
5924
+ completed++;
5925
+ results[index] = resultValue;
5926
+ setTaskCompleteProgress(completed, count);
5927
+ if (completed === count) {
5928
+ resolve(results);
5929
+ }
5930
+ };
5931
+ var onProgress = function onProgress(promise, index) {
5932
+ if (_instanceof1$2(promise, AssetPromise) || _instanceof1$2(promise, Promise)) {
5933
+ promise.then(function(value) {
5934
+ onComplete(index, value);
5935
+ }, reject);
5936
+ } else {
5937
+ Promise.resolve().then(function() {
5938
+ onComplete(index, promise);
5939
+ });
5940
+ }
5941
+ };
5942
+ var count = Array.from(values).length;
5943
+ var results = new Array(count);
5944
+ var completed = 0;
5945
+ if (count === 0) {
5946
+ return resolve(results);
5947
+ }
5948
+ for(var i = 0; i < count; i++){
5949
+ onProgress(values[i], i);
5950
+ }
5951
+ });
5952
+ };
5953
+ _create_class$2(AssetPromise, [
5954
+ {
5955
+ key: Symbol.toStringTag,
5956
+ get: /** compatible with Promise */ function get() {
5957
+ return "AssetPromise";
5958
+ }
5959
+ }
5960
+ ]);
5961
+ return AssetPromise;
5962
+ }();
5784
5963
  /**
5785
5964
  * Access operating system, platform and hardware information.
5786
5965
  */ var SystemInfo = /*#__PURE__*/ function() {
@@ -5884,6 +6063,27 @@
5884
6063
  }
5885
6064
  return this._simdSupported;
5886
6065
  };
6066
+ SystemInfo._checkWebpSupported = function _checkWebpSupported() {
6067
+ var _this = this;
6068
+ if (!this._webpSupported) {
6069
+ this._webpSupported = new AssetPromise(function(resolve) {
6070
+ if (_this._isBrowser) {
6071
+ var img = new Image();
6072
+ img.onload = function() {
6073
+ var result = img.width > 0 && img.height > 0;
6074
+ resolve(result);
6075
+ };
6076
+ img.onerror = function() {
6077
+ resolve(false);
6078
+ };
6079
+ img.src = "data:image/webp;base64,UklGRhACAABXRUJQVlA4WAoAAAAwAAAAAAAAAAAASUNDUMgBAAAAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogAAAAAAAA9tYAAQAAAADTLXBhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABtbHVjAAAAAAAAAAEAAAAMZW5VUwAAACAAAAAcAEcAbwBvAGcAbABlACAASQBuAGMALgAgADIAMAAxADZBTFBIAgAAAAAAVlA4IBgAAAAwAQCdASoBAAEAAUAmJaQAA3AA/v02aAA=";
6080
+ } else {
6081
+ resolve(false);
6082
+ }
6083
+ });
6084
+ }
6085
+ return this._webpSupported;
6086
+ };
5887
6087
  /**
5888
6088
  * Checks whether the system supports the given texture format.
5889
6089
  * @param format - The texture format
@@ -5937,6 +6137,7 @@
5937
6137
  /** The operating system is running on. */ SystemInfo.operatingSystem = "";
5938
6138
  /** @internal */ SystemInfo._isBrowser = true;
5939
6139
  /** Whether the system support SIMD. */ SystemInfo._simdSupported = null;
6140
+ SystemInfo._webpSupported = null;
5940
6141
  SystemInfo._initialize();
5941
6142
  /**
5942
6143
  * The base class of texture, contains some common functions of texture-related classes.
@@ -28111,185 +28312,6 @@
28111
28312
  ]);
28112
28313
  return SceneManager;
28113
28314
  }();
28114
- var AssetPromise = /*#__PURE__*/ function() {
28115
- function AssetPromise(executor) {
28116
- var _this = this;
28117
- this._state = "pending";
28118
- this._onTaskCompleteCallbacks = [];
28119
- this._onTaskDetailCallbacks = [];
28120
- this._promise = new Promise(function(resolve, reject) {
28121
- _this._reject = reject;
28122
- var onResolve = function onResolve(value) {
28123
- if (_this._state === "pending") {
28124
- resolve(value);
28125
- _this._state = "fulfilled";
28126
- _this._onTaskCompleteCallbacks = undefined;
28127
- _this._onTaskDetailCallbacks = undefined;
28128
- }
28129
- };
28130
- var onReject = function onReject(reason) {
28131
- if (_this._state === "pending") {
28132
- reject(reason);
28133
- _this._state = "rejected";
28134
- _this._onTaskCompleteCallbacks = undefined;
28135
- _this._onTaskDetailCallbacks = undefined;
28136
- }
28137
- };
28138
- var onCancel = function onCancel(callback) {
28139
- if (_this._state === "pending") {
28140
- _this._onCancelHandler = callback;
28141
- }
28142
- };
28143
- var setTaskCompleteProgress = function setTaskCompleteProgress(loaded, total) {
28144
- if (_this._state === "pending") {
28145
- var progress = _this._taskCompleteProgress || (_this._taskCompleteProgress = {
28146
- loaded: loaded,
28147
- total: total
28148
- });
28149
- progress.loaded = loaded;
28150
- progress.total = total;
28151
- _this._onTaskCompleteCallbacks.forEach(function(callback) {
28152
- return callback(loaded, total);
28153
- });
28154
- }
28155
- };
28156
- var setTaskDetailProgress = function setTaskDetailProgress(url, loaded, total) {
28157
- if (_this._state === "pending") {
28158
- var _this__taskDetailProgress, _url;
28159
- _this._taskDetailProgress || (_this._taskDetailProgress = {});
28160
- var progress = (_this__taskDetailProgress = _this._taskDetailProgress)[_url = url] || (_this__taskDetailProgress[_url] = {
28161
- loaded: loaded,
28162
- total: total
28163
- });
28164
- progress.loaded = loaded;
28165
- progress.total = total;
28166
- _this._onTaskDetailCallbacks.forEach(function(callback) {
28167
- return callback(url, loaded, total);
28168
- });
28169
- }
28170
- };
28171
- executor(onResolve, onReject, setTaskCompleteProgress, setTaskDetailProgress, onCancel);
28172
- });
28173
- }
28174
- var _proto = AssetPromise.prototype;
28175
- /**
28176
- * Progress callback.
28177
- * @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
28178
- * @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
28179
- * @returns AssetPromise
28180
- */ _proto.onProgress = function onProgress(onTaskComplete, onTaskDetail) {
28181
- var completeProgress = this._taskCompleteProgress;
28182
- var detailProgress = this._taskDetailProgress;
28183
- if (completeProgress) {
28184
- onTaskComplete(completeProgress.loaded, completeProgress.total);
28185
- }
28186
- if (detailProgress) {
28187
- for(var url in detailProgress){
28188
- var _detailProgress_url = detailProgress[url], loaded = _detailProgress_url.loaded, total = _detailProgress_url.total;
28189
- onTaskDetail(url, loaded, total);
28190
- }
28191
- }
28192
- if (this._state === "pending") {
28193
- onTaskComplete && this._onTaskCompleteCallbacks.push(onTaskComplete);
28194
- onTaskDetail && this._onTaskDetailCallbacks.push(onTaskDetail);
28195
- }
28196
- return this;
28197
- };
28198
- _proto.then = function then(onfulfilled, onrejected) {
28199
- var _this = this;
28200
- return new AssetPromise(function(resolve, reject) {
28201
- _this._promise.then(onfulfilled, onrejected).then(resolve).catch(reject);
28202
- });
28203
- };
28204
- /**
28205
- * Attaches a callback for only the rejection of the Promise.
28206
- * @param onRejected - The callback to execute when the Promise is rejected.
28207
- * @returns A Promise for the completion of the callback.
28208
- */ _proto.catch = function _catch(onRejected) {
28209
- var _this = this;
28210
- return new AssetPromise(function(resolve, reject) {
28211
- _this._promise.catch(onRejected).then(resolve).catch(reject);
28212
- });
28213
- };
28214
- /**
28215
- * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
28216
- * resolved value cannot be modified from the callback.
28217
- * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
28218
- * @returns A Promise for the completion of the callback.
28219
- */ _proto.finally = function _finally(onFinally) {
28220
- return this._promise.finally(onFinally);
28221
- };
28222
- /**
28223
- * Cancel promise request.
28224
- * @returns Asset promise
28225
- */ _proto.cancel = function cancel() {
28226
- if (this._state !== "pending") {
28227
- return;
28228
- }
28229
- this._state = "canceled";
28230
- this._reject("canceled");
28231
- this._onCancelHandler && this._onCancelHandler();
28232
- return this;
28233
- };
28234
- AssetPromise.resolve = function resolve(value) {
28235
- if (value === undefined) {
28236
- return new AssetPromise(function(resolve) {
28237
- return resolve();
28238
- });
28239
- } else if (_instanceof1$2(value, AssetPromise) || _instanceof1$2(value, Promise)) {
28240
- return new AssetPromise(function(resolve, reject) {
28241
- value.then(function(resolved) {
28242
- return resolve(resolved);
28243
- }, reject);
28244
- });
28245
- } else {
28246
- return new AssetPromise(function(resolve) {
28247
- return resolve(value);
28248
- });
28249
- }
28250
- };
28251
- AssetPromise.all = function all(values) {
28252
- return new AssetPromise(function(resolve, reject, setTaskCompleteProgress) {
28253
- var onComplete = function onComplete(index, resultValue) {
28254
- completed++;
28255
- results[index] = resultValue;
28256
- setTaskCompleteProgress(completed, count);
28257
- if (completed === count) {
28258
- resolve(results);
28259
- }
28260
- };
28261
- var onProgress = function onProgress(promise, index) {
28262
- if (_instanceof1$2(promise, AssetPromise) || _instanceof1$2(promise, Promise)) {
28263
- promise.then(function(value) {
28264
- onComplete(index, value);
28265
- }, reject);
28266
- } else {
28267
- Promise.resolve().then(function() {
28268
- onComplete(index, promise);
28269
- });
28270
- }
28271
- };
28272
- var count = Array.from(values).length;
28273
- var results = new Array(count);
28274
- var completed = 0;
28275
- if (count === 0) {
28276
- return resolve(results);
28277
- }
28278
- for(var i = 0; i < count; i++){
28279
- onProgress(values[i], i);
28280
- }
28281
- });
28282
- };
28283
- _create_class$2(AssetPromise, [
28284
- {
28285
- key: Symbol.toStringTag,
28286
- get: /** compatible with Promise */ function get() {
28287
- return "AssetPromise";
28288
- }
28289
- }
28290
- ]);
28291
- return AssetPromise;
28292
- }();
28293
28315
  var mimeType = {
28294
28316
  json: "json",
28295
28317
  gltf: "json",
@@ -41251,7 +41273,8 @@
41251
41273
  // Based on the specific version of the engine implementation, when actualBoundingBoxLeft is not supported, width is used to represent the rendering width, and `textAlign` uses the default value `start` and direction is left to right.
41252
41274
  // Some devices do not support actualBoundingBoxLeft and actualBoundingBoxRight in TextMetrics.
41253
41275
  // Examples: Google Pixel 2 XL (Android 11), Honor 6X (Android 8).
41254
- if (!("actualBoundingBoxLeft" in TextMetrics.prototype)) {
41276
+ // In WeChat Mini Games, TextMetrics may be reported as not defined, so a check for window.TextMetrics is added.
41277
+ if (window.TextMetrics && !("actualBoundingBoxLeft" in TextMetrics.prototype)) {
41255
41278
  Object.defineProperties(TextMetrics.prototype, {
41256
41279
  actualBoundingBoxLeft: {
41257
41280
  get: function get() {
@@ -51117,24 +51140,15 @@
51117
51140
  var EXT_texture_webp = /*#__PURE__*/ function(GLTFExtensionParser) {
51118
51141
  _inherits(EXT_texture_webp, GLTFExtensionParser);
51119
51142
  function EXT_texture_webp() {
51120
- var _this;
51121
- _this = GLTFExtensionParser.call(this) || this, _this._supportWebP = false;
51122
- // @ts-ignore
51123
- if (SystemInfo._isBrowser) {
51124
- var testCanvas = document.createElement("canvas");
51125
- testCanvas.width = testCanvas.height = 1;
51126
- _this._supportWebP = testCanvas.toDataURL("image/webp").indexOf("data:image/webp") == 0;
51127
- } else {
51128
- _this._supportWebP = false;
51129
- }
51130
- return _this;
51143
+ return GLTFExtensionParser.apply(this, arguments) || this;
51131
51144
  }
51132
51145
  var _proto = EXT_texture_webp.prototype;
51133
51146
  _proto.createAndParse = function createAndParse(context, schema, textureInfo, textureIndex, isSRGBColorSpace) {
51134
51147
  var webPIndex = schema.source;
51135
51148
  var sampler = textureInfo.sampler, tmp = textureInfo.source, fallbackIndex = tmp === void 0 ? 0 : tmp, textureName = textureInfo.name;
51136
- var texture = exports.GLTFTextureParser._parseTexture(context, this._supportWebP ? webPIndex : fallbackIndex, textureIndex, sampler, textureName, isSRGBColorSpace);
51137
- return texture;
51149
+ return SystemInfo._checkWebpSupported().then(function(supportWebP) {
51150
+ return exports.GLTFTextureParser._parseTexture(context, supportWebP ? webPIndex : fallbackIndex, textureIndex, sampler, textureName, isSRGBColorSpace);
51151
+ });
51138
51152
  };
51139
51153
  return EXT_texture_webp;
51140
51154
  }(GLTFExtensionParser);
@@ -51143,7 +51157,7 @@
51143
51157
  ], EXT_texture_webp);
51144
51158
 
51145
51159
  //@ts-ignore
51146
- var version = "1.5.2";
51160
+ var version = "1.5.4";
51147
51161
  console.log("Galacean Engine Version: " + version);
51148
51162
  for(var key in CoreObjects){
51149
51163
  Loader.registerClass(key, CoreObjects[key]);