@galacean/engine-core 1.3.19 → 1.3.20

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
@@ -18672,8 +18672,20 @@ __decorate([
18672
18672
  mesh.setVertexElements([
18673
18673
  new VertexElement("POSITION_UV", 0, exports.VertexElementFormat.Vector4, 0)
18674
18674
  ]);
18675
- mesh.setVertexBufferBinding(new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices, exports.BufferUsage.Static), 16);
18675
+ var buffer = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices, exports.BufferUsage.Static, true);
18676
+ mesh.setVertexBufferBinding(buffer, 16);
18676
18677
  mesh.addSubMesh(0, 3, exports.MeshTopology.Triangles);
18678
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
18679
+ _inherits(_class, ContentRestorer);
18680
+ function _class() {
18681
+ return ContentRestorer.call(this, mesh);
18682
+ }
18683
+ var _proto = _class.prototype;
18684
+ _proto.restoreContent = function restoreContent() {
18685
+ buffer.setData(buffer.data);
18686
+ };
18687
+ return _class;
18688
+ }(ContentRestorer))());
18677
18689
  return mesh;
18678
18690
  };
18679
18691
  _proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel) {
@@ -19464,6 +19476,151 @@ var /** @internal */ PromiseState;
19464
19476
  PromiseState["Canceled"] = "canceled";
19465
19477
  })(PromiseState || (PromiseState = {}));
19466
19478
 
19479
+ var mimeType = {
19480
+ json: "json",
19481
+ gltf: "json",
19482
+ mtl: "json",
19483
+ prefab: "json",
19484
+ txt: "text",
19485
+ bin: "arraybuffer",
19486
+ png: "image",
19487
+ webp: "image",
19488
+ jpg: "image"
19489
+ };
19490
+ var defaultRetryCount = 1;
19491
+ var defaultTimeout = Infinity;
19492
+ var defaultInterval = 500;
19493
+ /**
19494
+ * Web request.
19495
+ * @param url - The link
19496
+ * @param config - Load configuration
19497
+ */ function request(url, config) {
19498
+ if (config === void 0) config = {};
19499
+ return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
19500
+ var _config_retryCount;
19501
+ var retryCount = (_config_retryCount = config.retryCount) != null ? _config_retryCount : defaultRetryCount;
19502
+ var _config_retryInterval;
19503
+ var retryInterval = (_config_retryInterval = config.retryInterval) != null ? _config_retryInterval : defaultInterval;
19504
+ var _config_timeout;
19505
+ config.timeout = (_config_timeout = config.timeout) != null ? _config_timeout : defaultTimeout;
19506
+ var _config_type;
19507
+ config.type = (_config_type = config.type) != null ? _config_type : getMimeTypeFromUrl(url);
19508
+ var executor = new MultiExecutor(function() {
19509
+ return requestRes(url, config).onProgress(setTaskCompleteProgress, setTaskDetailProgress);
19510
+ }, retryCount, retryInterval);
19511
+ executor.start().onError(reject).onComplete(resolve);
19512
+ });
19513
+ }
19514
+ function requestRes(url, config) {
19515
+ return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
19516
+ var xhr = new XMLHttpRequest();
19517
+ var isImg = config.type === "image";
19518
+ xhr.timeout = config.timeout;
19519
+ var _config_method;
19520
+ config.method = (_config_method = config.method) != null ? _config_method : "get";
19521
+ xhr.onload = function() {
19522
+ if (xhr.status < 200 || xhr.status >= 300) {
19523
+ reject(new Error("request failed from: " + url));
19524
+ return;
19525
+ }
19526
+ var _xhr_response;
19527
+ var result = (_xhr_response = xhr.response) != null ? _xhr_response : xhr.responseText;
19528
+ if (isImg) {
19529
+ var img = new Image();
19530
+ img.onload = function() {
19531
+ // Call requestAnimationFrame to avoid iOS's bug.
19532
+ requestAnimationFrame(function() {
19533
+ setTaskCompleteProgress(1, 1);
19534
+ //@ts-ignore
19535
+ resolve(img);
19536
+ img.onload = null;
19537
+ img.onerror = null;
19538
+ img.onabort = null;
19539
+ URL.revokeObjectURL(img.src);
19540
+ });
19541
+ };
19542
+ img.onerror = img.onabort = function() {
19543
+ reject(new Error("request " + img.src + " fail"));
19544
+ URL.revokeObjectURL(img.src);
19545
+ };
19546
+ img.crossOrigin = "anonymous";
19547
+ img.src = URL.createObjectURL(result);
19548
+ } else {
19549
+ setTaskCompleteProgress(1, 1);
19550
+ resolve(result);
19551
+ }
19552
+ };
19553
+ xhr.onerror = function() {
19554
+ reject(new Error("request failed from: " + url));
19555
+ };
19556
+ xhr.ontimeout = function() {
19557
+ reject(new Error("request timeout from: " + url));
19558
+ };
19559
+ xhr.onprogress = function(e) {
19560
+ if (e.lengthComputable) {
19561
+ setTaskDetailProgress(url, e.loaded, e.total);
19562
+ }
19563
+ };
19564
+ xhr.open(config.method, url, true);
19565
+ xhr.withCredentials = config.credentials === "include";
19566
+ // @ts-ignore
19567
+ xhr.responseType = isImg ? "blob" : config.type;
19568
+ var headers = config.headers;
19569
+ if (headers) {
19570
+ Object.keys(headers).forEach(function(name) {
19571
+ xhr.setRequestHeader(name, headers[name]);
19572
+ });
19573
+ }
19574
+ // @ts-ignore
19575
+ xhr.send(config.body);
19576
+ });
19577
+ }
19578
+ function getMimeTypeFromUrl(url) {
19579
+ var extname = url.substring(url.lastIndexOf(".") + 1);
19580
+ return mimeType[extname];
19581
+ }
19582
+ var MultiExecutor = /*#__PURE__*/ function() {
19583
+ function MultiExecutor(execFunc, totalCount, interval) {
19584
+ this.execFunc = execFunc;
19585
+ this.totalCount = totalCount;
19586
+ this.interval = interval;
19587
+ this._timeoutId = -100;
19588
+ this._currentCount = 0;
19589
+ this.exec = this.exec.bind(this);
19590
+ }
19591
+ var _proto = MultiExecutor.prototype;
19592
+ _proto.start = function start() {
19593
+ this.exec();
19594
+ return this;
19595
+ };
19596
+ _proto.onComplete = function onComplete(func) {
19597
+ this._onComplete = func;
19598
+ return this;
19599
+ };
19600
+ _proto.onError = function onError(func) {
19601
+ this._onError = func;
19602
+ return this;
19603
+ };
19604
+ _proto.cancel = function cancel() {
19605
+ window.clearTimeout(this._timeoutId);
19606
+ };
19607
+ _proto.exec = function exec() {
19608
+ var _this = this;
19609
+ if (this._currentCount >= this.totalCount) {
19610
+ this._onError && this._onError(this._error);
19611
+ return;
19612
+ }
19613
+ this._currentCount++;
19614
+ this.execFunc(this._currentCount).then(function(result) {
19615
+ return _this._onComplete && _this._onComplete(result);
19616
+ }).catch(function(e) {
19617
+ _this._error = e;
19618
+ _this._timeoutId = window.setTimeout(_this.exec, _this.interval);
19619
+ });
19620
+ };
19621
+ return MultiExecutor;
19622
+ }();
19623
+
19467
19624
  /**
19468
19625
  * ResourceManager
19469
19626
  */ var ResourceManager = /*#__PURE__*/ function() {
@@ -19559,6 +19716,23 @@ var /** @internal */ PromiseState;
19559
19716
  };
19560
19717
  /**
19561
19718
  * @internal
19719
+ */ _proto._getRemoteUrl = function _getRemoteUrl(url) {
19720
+ var _this__virtualPathMap_url;
19721
+ return (_this__virtualPathMap_url = this._virtualPathMap[url]) != null ? _this__virtualPathMap_url : url;
19722
+ };
19723
+ /**
19724
+ * @internal
19725
+ */ _proto._requestByRemoteUrl = function _requestByRemoteUrl(url, config) {
19726
+ return request(url, config);
19727
+ };
19728
+ /**
19729
+ * @internal
19730
+ */ _proto._request = function _request(url, config) {
19731
+ var remoteUrl = this._getRemoteUrl(url);
19732
+ return this._requestByRemoteUrl(remoteUrl, config);
19733
+ };
19734
+ /**
19735
+ * @internal
19562
19736
  */ _proto._onSubAssetSuccess = function _onSubAssetSuccess(assetBaseURL, assetSubPath, value) {
19563
19737
  var _this__subAssetPromiseCallbacks_remoteAssetBaseURL;
19564
19738
  var _this__virtualPathMap_assetBaseURL;
@@ -24088,7 +24262,21 @@ ShaderPool.init();
24088
24262
  mesh.uploadData(false);
24089
24263
  };
24090
24264
  _proto._initMesh = function _initMesh(engine) {
24091
- this._mesh = this._createPlane(engine);
24265
+ var mesh = this._mesh = this._createPlane(engine);
24266
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
24267
+ _inherits(_class, ContentRestorer);
24268
+ function _class() {
24269
+ return ContentRestorer.call(this, mesh);
24270
+ }
24271
+ var _proto = _class.prototype;
24272
+ _proto.restoreContent = function restoreContent() {
24273
+ mesh.setPositions(mesh.getPositions());
24274
+ mesh.setUVs(mesh.getUVs());
24275
+ mesh.setIndices(mesh.getIndices());
24276
+ mesh.uploadData(false);
24277
+ };
24278
+ return _class;
24279
+ }(ContentRestorer))());
24092
24280
  this._mesh._addReferCount(1);
24093
24281
  };
24094
24282
  _proto._initMaterial = function _initMaterial(engine) {
@@ -26335,163 +26523,12 @@ __decorate([
26335
26523
  ignoreClone
26336
26524
  ], Script.prototype, "_entityScriptsIndex", void 0);
26337
26525
 
26338
- var mimeType = {
26339
- json: "json",
26340
- gltf: "json",
26341
- mtl: "json",
26342
- prefab: "json",
26343
- txt: "text",
26344
- bin: "arraybuffer",
26345
- png: "image",
26346
- webp: "image",
26347
- jpg: "image"
26348
- };
26349
- var defaultRetryCount = 1;
26350
- var defaultTimeout = Infinity;
26351
- var defaultInterval = 500;
26352
- /**
26353
- * Web request.
26354
- * @param url - The link
26355
- * @param config - Load configuration
26356
- */ function request(url, config) {
26357
- if (config === void 0) config = {};
26358
- return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
26359
- var _config_retryCount;
26360
- var retryCount = (_config_retryCount = config.retryCount) != null ? _config_retryCount : defaultRetryCount;
26361
- var _config_retryInterval;
26362
- var retryInterval = (_config_retryInterval = config.retryInterval) != null ? _config_retryInterval : defaultInterval;
26363
- var _config_timeout;
26364
- config.timeout = (_config_timeout = config.timeout) != null ? _config_timeout : defaultTimeout;
26365
- var _config_type;
26366
- config.type = (_config_type = config.type) != null ? _config_type : getMimeTypeFromUrl(url);
26367
- var executor = new MultiExecutor(function() {
26368
- return requestRes(url, config).onProgress(setTaskCompleteProgress, setTaskDetailProgress);
26369
- }, retryCount, retryInterval);
26370
- executor.start().onError(reject).onComplete(resolve);
26371
- });
26372
- }
26373
- function requestRes(url, config) {
26374
- return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
26375
- var xhr = new XMLHttpRequest();
26376
- var isImg = config.type === "image";
26377
- xhr.timeout = config.timeout;
26378
- var _config_method;
26379
- config.method = (_config_method = config.method) != null ? _config_method : "get";
26380
- xhr.onload = function() {
26381
- if (xhr.status < 200 || xhr.status >= 300) {
26382
- reject(new Error("request failed from: " + url));
26383
- return;
26384
- }
26385
- var _xhr_response;
26386
- var result = (_xhr_response = xhr.response) != null ? _xhr_response : xhr.responseText;
26387
- if (isImg) {
26388
- var img = new Image();
26389
- img.onload = function() {
26390
- // Call requestAnimationFrame to avoid iOS's bug.
26391
- requestAnimationFrame(function() {
26392
- setTaskCompleteProgress(1, 1);
26393
- //@ts-ignore
26394
- resolve(img);
26395
- img.onload = null;
26396
- img.onerror = null;
26397
- img.onabort = null;
26398
- URL.revokeObjectURL(img.src);
26399
- });
26400
- };
26401
- img.onerror = img.onabort = function() {
26402
- reject(new Error("request " + img.src + " fail"));
26403
- URL.revokeObjectURL(img.src);
26404
- };
26405
- img.crossOrigin = "anonymous";
26406
- img.src = URL.createObjectURL(result);
26407
- } else {
26408
- setTaskCompleteProgress(1, 1);
26409
- resolve(result);
26410
- }
26411
- };
26412
- xhr.onerror = function() {
26413
- reject(new Error("request failed from: " + url));
26414
- };
26415
- xhr.ontimeout = function() {
26416
- reject(new Error("request timeout from: " + url));
26417
- };
26418
- xhr.onprogress = function(e) {
26419
- if (e.lengthComputable) {
26420
- setTaskDetailProgress(url, e.loaded, e.total);
26421
- }
26422
- };
26423
- xhr.open(config.method, url, true);
26424
- xhr.withCredentials = config.credentials === "include";
26425
- // @ts-ignore
26426
- xhr.responseType = isImg ? "blob" : config.type;
26427
- var headers = config.headers;
26428
- if (headers) {
26429
- Object.keys(headers).forEach(function(name) {
26430
- xhr.setRequestHeader(name, headers[name]);
26431
- });
26432
- }
26433
- // @ts-ignore
26434
- xhr.send(config.body);
26435
- });
26436
- }
26437
- function getMimeTypeFromUrl(url) {
26438
- var extname = url.substring(url.lastIndexOf(".") + 1);
26439
- return mimeType[extname];
26440
- }
26441
- var MultiExecutor = /*#__PURE__*/ function() {
26442
- function MultiExecutor(execFunc, totalCount, interval) {
26443
- this.execFunc = execFunc;
26444
- this.totalCount = totalCount;
26445
- this.interval = interval;
26446
- this._timeoutId = -100;
26447
- this._currentCount = 0;
26448
- this.exec = this.exec.bind(this);
26449
- }
26450
- var _proto = MultiExecutor.prototype;
26451
- _proto.start = function start() {
26452
- this.exec();
26453
- return this;
26454
- };
26455
- _proto.onComplete = function onComplete(func) {
26456
- this._onComplete = func;
26457
- return this;
26458
- };
26459
- _proto.onError = function onError(func) {
26460
- this._onError = func;
26461
- return this;
26462
- };
26463
- _proto.cancel = function cancel() {
26464
- window.clearTimeout(this._timeoutId);
26465
- };
26466
- _proto.exec = function exec() {
26467
- var _this = this;
26468
- if (this._currentCount >= this.totalCount) {
26469
- this._onError && this._onError(this._error);
26470
- return;
26471
- }
26472
- this._currentCount++;
26473
- this.execFunc(this._currentCount).then(function(result) {
26474
- return _this._onComplete && _this._onComplete(result);
26475
- }).catch(function(e) {
26476
- _this._error = e;
26477
- _this._timeoutId = window.setTimeout(_this.exec, _this.interval);
26478
- });
26479
- };
26480
- return MultiExecutor;
26481
- }();
26482
-
26483
26526
  /**
26484
26527
  * Loader abstract class.
26485
26528
  */ var Loader = /*#__PURE__*/ function() {
26486
26529
  function Loader(useCache) {
26487
26530
  this.useCache = useCache;
26488
26531
  }
26489
- var _proto = Loader.prototype;
26490
- _proto.request = function request1(url, resourceManager, config) {
26491
- var _resourceManager__virtualPathMap_url;
26492
- var remoteUrl = (_resourceManager__virtualPathMap_url = resourceManager._virtualPathMap[url]) != null ? _resourceManager__virtualPathMap_url : url;
26493
- return request(remoteUrl, config);
26494
- };
26495
26532
  /**
26496
26533
  * Register a class with a string name for serialization and deserialization.
26497
26534
  * @param key - class name
@@ -31482,6 +31519,7 @@ var MainModule = /*#__PURE__*/ function() {
31482
31519
  /** Control how the Particle Generator applies its Transform component to the particles it emits. */ this.scalingMode = exports.ParticleScaleMode.Local;
31483
31520
  /** If set to true, the Particle Generator automatically begins to play on startup. */ this.playOnEnabled = true;
31484
31521
  /** @internal */ this._maxParticleBuffer = 1000;
31522
+ /** @internal */ this._startDelayRand = new engineMath.Rand(0, ParticleRandomSubSeeds.StartDelay);
31485
31523
  /** @internal */ this._startSpeedRand = new engineMath.Rand(0, ParticleRandomSubSeeds.StartSpeed);
31486
31524
  /** @internal */ this._startLifeTimeRand = new engineMath.Rand(0, ParticleRandomSubSeeds.StartLifetime);
31487
31525
  /** @internal */ this._startColorRand = new engineMath.Rand(0, ParticleRandomSubSeeds.StartColor);
@@ -31766,6 +31804,9 @@ __decorate([
31766
31804
  __decorate([
31767
31805
  ignoreClone
31768
31806
  ], MainModule.prototype, "_maxParticleBuffer", void 0);
31807
+ __decorate([
31808
+ ignoreClone
31809
+ ], MainModule.prototype, "_startDelayRand", void 0);
31769
31810
  __decorate([
31770
31811
  ignoreClone
31771
31812
  ], MainModule.prototype, "_startSpeedRand", void 0);
@@ -32610,6 +32651,7 @@ __decorate([
32610
32651
  this._transformedBoundsCount = 0;
32611
32652
  this._firstActiveTransformedBoundingBox = 0;
32612
32653
  this._firstFreeTransformedBoundingBox = 0;
32654
+ this._playStartDelay = 0;
32613
32655
  this._renderer = renderer;
32614
32656
  var subPrimitive = new SubPrimitive();
32615
32657
  subPrimitive.start = 0;
@@ -32638,6 +32680,7 @@ __decorate([
32638
32680
  if (this.useAutoRandomSeed) {
32639
32681
  this._resetGlobalRandSeed(Math.floor(Math.random() * 0xffffffff)); // 2^32 - 1
32640
32682
  }
32683
+ this._playStartDelay = this.main.startDelay.evaluate(undefined, this.main._startDelayRand.random());
32641
32684
  }
32642
32685
  };
32643
32686
  /**
@@ -32707,7 +32750,18 @@ __decorate([
32707
32750
  var _this = this, main = _this.main, emission = _this.emission;
32708
32751
  var duration = main.duration;
32709
32752
  var lastPlayTime = this._playTime;
32710
- this._playTime += elapsedTime * main.simulationSpeed;
32753
+ var deltaTime = elapsedTime * main.simulationSpeed;
32754
+ // Process start delay time
32755
+ if (this._playStartDelay > 0) {
32756
+ var remainingDelay = this._playStartDelay -= deltaTime;
32757
+ if (remainingDelay < 0) {
32758
+ this._playTime -= remainingDelay;
32759
+ this._playStartDelay = 0;
32760
+ } else {
32761
+ return;
32762
+ }
32763
+ }
32764
+ this._playTime += deltaTime;
32711
32765
  this._retireActiveParticles();
32712
32766
  this._freeRetiredParticles();
32713
32767
  if (main.simulationSpace === exports.ParticleSimulationSpace.World) {
@@ -33484,6 +33538,9 @@ __decorate([
33484
33538
  __decorate([
33485
33539
  ignoreClone
33486
33540
  ], ParticleGenerator.prototype, "_firstFreeTransformedBoundingBox", void 0);
33541
+ __decorate([
33542
+ ignoreClone
33543
+ ], ParticleGenerator.prototype, "_playStartDelay", void 0);
33487
33544
 
33488
33545
  /**
33489
33546
  * Particle Material.