@galacean/engine-core 1.3.19 → 1.3.21

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