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