@galacean/effects 1.1.3 → 1.1.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/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime player for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v1.1.3
6
+ * Version: v1.1.5
7
7
  */
8
8
 
9
9
  'use strict';
@@ -14733,6 +14733,9 @@ var VFXItem = /** @class */ (function () {
14733
14733
  VFXItem.isTree = function (item) {
14734
14734
  return item.type === ItemType$1.tree;
14735
14735
  };
14736
+ VFXItem.isCamera = function (item) {
14737
+ return item.type === ItemType$1.camera;
14738
+ };
14736
14739
  VFXItem.isExtraCamera = function (item) {
14737
14740
  return item.id === 'extra-camera' && item.name === 'extra-camera';
14738
14741
  };
@@ -14933,10 +14936,11 @@ var VFXItem = /** @class */ (function () {
14933
14936
  }
14934
14937
  else if (this.endBehavior === END_BEHAVIOR_DESTROY$1) {
14935
14938
  this._contentVisible = false;
14939
+ shouldUpdate = true;
14940
+ dt = 0;
14936
14941
  // 预合成配置 reusable 且销毁时, 需要隐藏其中的元素
14937
14942
  if (this.type === ItemType$1.composition) {
14938
14943
  this.handleVisibleChanged(false);
14939
- this.onItemUpdate(0, lifetime);
14940
14944
  }
14941
14945
  }
14942
14946
  lifetime = Math.min(lifetime, 1);
@@ -14945,7 +14949,6 @@ var VFXItem = /** @class */ (function () {
14945
14949
  shouldUpdate = true;
14946
14950
  if (this.endBehavior === END_BEHAVIOR_RESTART$1) {
14947
14951
  this.ended = true;
14948
- lifetime = lifetime % 1;
14949
14952
  }
14950
14953
  }
14951
14954
  }
@@ -14953,7 +14956,7 @@ var VFXItem = /** @class */ (function () {
14953
14956
  this.setVisible(true);
14954
14957
  this.callEnd = false;
14955
14958
  }
14956
- this.lifetime = lifetime;
14959
+ this.lifetime = lifetime % 1;
14957
14960
  shouldUpdate && this.onItemUpdate(dt, lifetime);
14958
14961
  }
14959
14962
  }
@@ -15520,10 +15523,6 @@ var CameraVFXItem = /** @class */ (function (_super) {
15520
15523
  (_a = this.controller) === null || _a === void 0 ? void 0 : _a.update(lifetime);
15521
15524
  this.updateCamera();
15522
15525
  };
15523
- // override onEnd () {
15524
- // this.controller?.update(1);
15525
- // this.updateCamera();
15526
- // }
15527
15526
  CameraVFXItem.prototype.updateCamera = function () {
15528
15527
  if (this.controller && this.composition) {
15529
15528
  var camera = this.composition.camera;
@@ -19280,19 +19279,28 @@ var SpriteMesh = /** @class */ (function () {
19280
19279
  var aPointLen = 0;
19281
19280
  var indexLen = 0;
19282
19281
  var pointCount = 0;
19282
+ var renderInfo;
19283
19283
  if (!items.length) {
19284
19284
  this.mesh.setVisible(false);
19285
19285
  return true;
19286
19286
  }
19287
+ for (var i = 0; i < items.length; i++) {
19288
+ if (items[i].renderInfo) {
19289
+ renderInfo = items[i].renderInfo;
19290
+ break;
19291
+ }
19292
+ }
19293
+ if (!renderInfo) {
19294
+ return true;
19295
+ }
19287
19296
  this.items = items.slice();
19288
19297
  if (items.length > 2) {
19289
19298
  itemSlot = exports.maxSpriteMeshItemCount;
19290
19299
  }
19291
- var renderInfo = items[0].renderInfo;
19292
19300
  if (this.mtlSlotCount !== itemSlot) {
19293
19301
  this.mesh.setMaterial(this.createMaterial(renderInfo, itemSlot), { textures: exports.DestroyOptions.keep });
19294
19302
  }
19295
- var attachmentLength = (_d = (_c = (_b = (_a = renderInfo === null || renderInfo === void 0 ? void 0 : renderInfo.filter) === null || _a === void 0 ? void 0 : _a.passSplitOptions) === null || _b === void 0 ? void 0 : _b.attachments) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0;
19303
+ var attachmentLength = (_d = (_c = (_b = (_a = renderInfo.filter) === null || _a === void 0 ? void 0 : _a.passSplitOptions) === null || _b === void 0 ? void 0 : _b.attachments) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0;
19296
19304
  this.splitLayer = attachmentLength > 0;
19297
19305
  for (var i = 0; i < items.length; i++) {
19298
19306
  var item = items[i];
@@ -23568,7 +23576,7 @@ var ParticleSystem = /** @class */ (function () {
23568
23576
  configurable: true
23569
23577
  });
23570
23578
  ParticleSystem.prototype.updateEmitterTransform = function (time) {
23571
- var parentTransform = this.parentTransform;
23579
+ var parentTransform = this.transform.parentTransform;
23572
23580
  var _a = this.basicTransform, path = _a.path, position = _a.position;
23573
23581
  var selfPos = position.clone();
23574
23582
  if (path) {
@@ -23578,9 +23586,9 @@ var ParticleSystem = /** @class */ (function () {
23578
23586
  this.transform.setPosition(selfPos.x, selfPos.y, selfPos.z);
23579
23587
  if (this.options.particleFollowParent && parentTransform) {
23580
23588
  var tempMatrix = parentTransform.getWorldMatrix();
23581
- this.particleMesh.mesh.worldMatrix = tempMatrix.clone();
23589
+ this.particleMesh.mesh.worldMatrix = tempMatrix;
23582
23590
  if (this.trailMesh) {
23583
- this.trailMesh.mesh.worldMatrix = tempMatrix.clone();
23591
+ this.trailMesh.mesh.worldMatrix = tempMatrix;
23584
23592
  }
23585
23593
  }
23586
23594
  };
@@ -23599,8 +23607,8 @@ var ParticleSystem = /** @class */ (function () {
23599
23607
  link.pushNode(linkContent);
23600
23608
  this.particleMesh.setPoint(point, pointIndex);
23601
23609
  this.clearPointTrail(pointIndex);
23602
- if (this.parentTransform && this.trailMesh) {
23603
- this.trailMesh.setPointStartPos(pointIndex, this.parentTransform.position.clone());
23610
+ if (this.trailMesh) {
23611
+ this.trailMesh.setPointStartPos(pointIndex, this.transform.parentTransform.position.clone());
23604
23612
  }
23605
23613
  };
23606
23614
  ParticleSystem.prototype.setVisible = function (visible) {
@@ -23638,7 +23646,8 @@ var ParticleSystem = /** @class */ (function () {
23638
23646
  }
23639
23647
  };
23640
23648
  ParticleSystem.prototype.setParentTransform = function (transform) {
23641
- this.parentTransform = transform;
23649
+ // this.transform.parentTransform = transform;
23650
+ // this.parentTransform = transform;
23642
23651
  };
23643
23652
  ParticleSystem.prototype.getTextures = function () {
23644
23653
  var e_1, _a, e_2, _b;
@@ -23890,9 +23899,7 @@ var ParticleSystem = /** @class */ (function () {
23890
23899
  if (options.removeParticle) {
23891
23900
  mesh.removePoint(pointIndex);
23892
23901
  this.clearPointTrail(pointIndex);
23893
- link.removeNode(node);
23894
- node.content = [0];
23895
- // link.shiftNode(node.content); // 删了又加回去 没明白什么意思
23902
+ node.content[0] = 0;
23896
23903
  }
23897
23904
  hitPositions.push(pos);
23898
23905
  if (!options.multiple) {
@@ -23931,8 +23938,8 @@ var ParticleSystem = /** @class */ (function () {
23931
23938
  if (trails.sizeAffectsLifetime) {
23932
23939
  lifetime *= size[0];
23933
23940
  }
23934
- if (trails.parentAffectsPosition && this.parentTransform) {
23935
- position.add(this.parentTransform.position);
23941
+ if (trails.parentAffectsPosition && this.transform.parentTransform) {
23942
+ position.add(this.transform.parentTransform.position);
23936
23943
  var pos = this.trailMesh.getPointStartPos(pointIndex);
23937
23944
  if (pos) {
23938
23945
  position.subtract(pos);
@@ -24146,7 +24153,9 @@ function randomArrItem(arr, keepArr) {
24146
24153
  var ParticleVFXItem = /** @class */ (function (_super) {
24147
24154
  __extends(ParticleVFXItem, _super);
24148
24155
  function ParticleVFXItem() {
24149
- return _super !== null && _super.apply(this, arguments) || this;
24156
+ var _this = _super !== null && _super.apply(this, arguments) || this;
24157
+ _this.destroyed = false;
24158
+ return _this;
24150
24159
  }
24151
24160
  Object.defineProperty(ParticleVFXItem.prototype, "type", {
24152
24161
  get: function () {
@@ -24172,12 +24181,11 @@ var ParticleVFXItem = /** @class */ (function (_super) {
24172
24181
  ParticleVFXItem.prototype.onItemUpdate = function (dt, lifetime) {
24173
24182
  var _a;
24174
24183
  if (this.content) {
24175
- var hide = !this.contentVisible;
24184
+ var hide = !this.visible;
24176
24185
  var parentItem = this.parentId && ((_a = this.composition) === null || _a === void 0 ? void 0 : _a.getItemByID(this.parentId));
24177
24186
  if (!hide && parentItem) {
24178
24187
  var parentData = parentItem.getRenderData();
24179
24188
  if (parentData) {
24180
- this.content.setParentTransform(parentData.transform);
24181
24189
  if (!parentData.visible) {
24182
24190
  hide = false;
24183
24191
  }
@@ -29180,7 +29188,6 @@ var CompositionSourceManager = /** @class */ (function () {
29180
29188
  }
29181
29189
  var cachedTextures = textureOptions.map(function (option) { return option && (option instanceof Texture ? option : Texture.create(engine, option)); });
29182
29190
  // 缓存创建的Texture对象
29183
- // @ts-expect-error
29184
29191
  scene.textureOptions = cachedTextures;
29185
29192
  cachedTextures === null || cachedTextures === void 0 ? void 0 : cachedTextures.forEach(function (tex) { return tex === null || tex === void 0 ? void 0 : tex.initialize(); });
29186
29193
  try {
@@ -29410,24 +29417,24 @@ var AssetManager = /** @class */ (function () {
29410
29417
  this.timeout = timeout;
29411
29418
  };
29412
29419
  /**
29413
- * 场景创建
29414
- * 通过 json 创建出场景对象,并进行提前编译等工作
29420
+ * 场景创建,通过 json 创建出场景对象,并进行提前编译等工作
29415
29421
  * @param url - json 的 URL 链接或者 json 对象
29416
29422
  * @param renderer - renderer 对象,用于获取管理、编译 shader 及 GPU 上下文的参数
29417
29423
  * @param options - 扩展参数
29418
29424
  * @returns
29419
29425
  */
29420
29426
  AssetManager.prototype.loadScene = function (url, renderer, options) {
29421
- var _a, _b;
29427
+ var _a, _b, _c;
29422
29428
  return __awaiter(this, void 0, void 0, function () {
29423
- var rawJSON, timeLabel, startTime, timeInfos, gpuInstance, asyncShaderCompile, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
29429
+ var rawJSON, timeLabel, startTime, timeInfos, gpuInstance, asyncShaderCompile, compressedTexture, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
29424
29430
  var _this = this;
29425
- return __generator(this, function (_c) {
29431
+ return __generator(this, function (_d) {
29426
29432
  timeLabel = "Load asset: ".concat(isString(url) ? url : this.id);
29427
29433
  startTime = performance.now();
29428
29434
  timeInfos = [];
29429
29435
  gpuInstance = renderer === null || renderer === void 0 ? void 0 : renderer.engine.gpuCapability;
29430
29436
  asyncShaderCompile = (_b = (_a = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail) === null || _a === void 0 ? void 0 : _a.asyncShaderCompile) !== null && _b !== void 0 ? _b : false;
29437
+ compressedTexture = (_c = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail.compressedTexture) !== null && _c !== void 0 ? _c : 0;
29431
29438
  cancelLoading = false;
29432
29439
  waitPromise = new Promise(function (resolve, reject) {
29433
29440
  return loadTimer = window.setTimeout(function () {
@@ -29452,10 +29459,10 @@ var AssetManager = /** @class */ (function () {
29452
29459
  });
29453
29460
  }); };
29454
29461
  loadResourcePromise = function () { return __awaiter(_this, void 0, void 0, function () {
29455
- var _a, usedImages, jsonScene, _b, bins, images, compositions, fonts, _c, loadedBins, loadedImages, loadedTextures, scene, totalTime;
29462
+ var scene, rawImages, images_1, i, _a, i, _b, usedImages_1, jsonScene_1, pluginSystem_1, _c, bins_1, images_2, compositions_1, fonts_1, _d, loadedBins_1, loadedImages_1, loadedTextures, totalTime;
29456
29463
  var _this = this;
29457
- return __generator(this, function (_d) {
29458
- switch (_d.label) {
29464
+ return __generator(this, function (_e) {
29465
+ switch (_e.label) {
29459
29466
  case 0:
29460
29467
  if (!isObject(url)) return [3 /*break*/, 1];
29461
29468
  // TODO: 原 JSONLoader contructor 判断是否兼容
@@ -29468,42 +29475,66 @@ var AssetManager = /** @class */ (function () {
29468
29475
  this.baseUrl = url;
29469
29476
  return [4 /*yield*/, hookTimeInfo('loadJSON', function () { return _this.loadJSON(url); })];
29470
29477
  case 2:
29471
- rawJSON = _d.sent();
29472
- _d.label = 3;
29473
- case 3: return [4 /*yield*/, hookTimeInfo('processJSON', function () { return _this.processJSON(rawJSON); })];
29478
+ rawJSON = _e.sent();
29479
+ _e.label = 3;
29480
+ case 3:
29481
+ if (!isScene(rawJSON)) return [3 /*break*/, 6];
29482
+ // 已经加载过的 可能需要更新数据模板
29483
+ scene = __assign$1({}, rawJSON);
29484
+ if (!(this.options && this.options.variables && Object.keys(this.options.variables).length !== 0)) return [3 /*break*/, 5];
29485
+ rawImages = rawJSON.jsonScene.images;
29486
+ images_1 = scene.images;
29487
+ for (i = 0; i < rawImages.length; i++) {
29488
+ // 仅重新加载数据模板对应的图片
29489
+ if (images_1[i] instanceof HTMLCanvasElement) {
29490
+ images_1[i] = rawImages[i];
29491
+ }
29492
+ }
29493
+ _a = scene;
29494
+ return [4 /*yield*/, hookTimeInfo('processImages', function () { return _this.processImages(images_1, scene.usedImages, compressedTexture); })];
29474
29495
  case 4:
29475
- _a = _d.sent(), usedImages = _a.usedImages, jsonScene = _a.jsonScene;
29476
- _b = jsonScene.bins, bins = _b === void 0 ? [] : _b, images = jsonScene.images, compositions = jsonScene.compositions, fonts = jsonScene.fonts;
29496
+ _a.images = _e.sent();
29497
+ // 更新 TextureOptions 中的 image 指向
29498
+ for (i = 0; i < scene.images.length; i++) {
29499
+ scene.textureOptions[i].image = scene.images[i];
29500
+ }
29501
+ _e.label = 5;
29502
+ case 5: return [3 /*break*/, 12];
29503
+ case 6: return [4 /*yield*/, hookTimeInfo('processJSON', function () { return _this.processJSON(rawJSON); })];
29504
+ case 7:
29505
+ _b = _e.sent(), usedImages_1 = _b.usedImages, jsonScene_1 = _b.jsonScene, pluginSystem_1 = _b.pluginSystem;
29506
+ _c = jsonScene_1.bins, bins_1 = _c === void 0 ? [] : _c, images_2 = jsonScene_1.images, compositions_1 = jsonScene_1.compositions, fonts_1 = jsonScene_1.fonts;
29477
29507
  return [4 /*yield*/, Promise.all([
29478
- hookTimeInfo('processBins', function () { return _this.processBins(bins); }),
29479
- hookTimeInfo('processImages', function () { var _a; return _this.processImages(images, usedImages, (_a = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail.compressedTexture) !== null && _a !== void 0 ? _a : 0); }),
29480
- hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', " compile"), function () { return _this.precompile(compositions, renderer, options); }),
29508
+ hookTimeInfo('processBins', function () { return _this.processBins(bins_1); }),
29509
+ hookTimeInfo('processImages', function () { return _this.processImages(images_2, usedImages_1, compressedTexture); }),
29510
+ hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', " compile"), function () { return _this.precompile(compositions_1, pluginSystem_1, renderer, options); }),
29481
29511
  ])];
29482
- case 5:
29483
- _c = __read$3.apply(void 0, [_d.sent(), 2]), loadedBins = _c[0], loadedImages = _c[1];
29484
- return [4 /*yield*/, hookTimeInfo('processFontURL', function () { return _this.processFontURL(fonts); })];
29485
- case 6:
29486
- _d.sent();
29487
- return [4 /*yield*/, hookTimeInfo('processTextures', function () { return _this.processTextures(loadedImages, loadedBins, jsonScene); })];
29488
- case 7:
29489
- loadedTextures = _d.sent();
29512
+ case 8:
29513
+ _d = __read$3.apply(void 0, [_e.sent(), 2]), loadedBins_1 = _d[0], loadedImages_1 = _d[1];
29514
+ return [4 /*yield*/, hookTimeInfo('processFontURL', function () { return _this.processFontURL(fonts_1); })];
29515
+ case 9:
29516
+ _e.sent();
29517
+ return [4 /*yield*/, hookTimeInfo('processTextures', function () { return _this.processTextures(loadedImages_1, loadedBins_1, jsonScene_1); })];
29518
+ case 10:
29519
+ loadedTextures = _e.sent();
29490
29520
  scene = {
29491
- jsonScene: jsonScene,
29492
- images: loadedImages,
29493
- textureOptions: loadedTextures,
29494
- bins: loadedBins,
29495
- storage: {},
29496
- pluginSystem: this.pluginSystem,
29497
- renderLevel: this.options.renderLevel,
29498
- totalTime: 0,
29499
- startTime: 0,
29500
29521
  url: url,
29522
+ renderLevel: this.options.renderLevel,
29523
+ storage: {},
29524
+ pluginSystem: pluginSystem_1,
29525
+ jsonScene: jsonScene_1,
29526
+ usedImages: usedImages_1,
29527
+ images: loadedImages_1,
29528
+ textureOptions: loadedTextures,
29529
+ bins: loadedBins_1,
29501
29530
  };
29502
29531
  // 触发插件系统 pluginSystem 的回调 prepareResource
29503
- return [4 /*yield*/, hookTimeInfo('processPlugins', function () { return _this.pluginSystem.loadResources(scene, _this.options); })];
29504
- case 8:
29532
+ return [4 /*yield*/, hookTimeInfo('processPlugins', function () { return pluginSystem_1.loadResources(scene, _this.options); })];
29533
+ case 11:
29505
29534
  // 触发插件系统 pluginSystem 的回调 prepareResource
29506
- _d.sent();
29535
+ _e.sent();
29536
+ _e.label = 12;
29537
+ case 12:
29507
29538
  totalTime = performance.now() - startTime;
29508
29539
  console.info({
29509
29540
  content: "".concat(timeLabel, ": ").concat(totalTime.toFixed(4), "ms, ").concat(timeInfos.join(' ')),
@@ -29520,7 +29551,7 @@ var AssetManager = /** @class */ (function () {
29520
29551
  });
29521
29552
  });
29522
29553
  };
29523
- AssetManager.prototype.precompile = function (compositions, renderer, options) {
29554
+ AssetManager.prototype.precompile = function (compositions, pluginSystem, renderer, options) {
29524
29555
  return __awaiter(this, void 0, void 0, function () {
29525
29556
  var shaderLibrary;
29526
29557
  return __generator(this, function (_a) {
@@ -29530,7 +29561,7 @@ var AssetManager = /** @class */ (function () {
29530
29561
  return [2 /*return*/];
29531
29562
  }
29532
29563
  shaderLibrary = renderer === null || renderer === void 0 ? void 0 : renderer.getShaderLibrary();
29533
- return [4 /*yield*/, this.pluginSystem.precompile(compositions, renderer, options)];
29564
+ return [4 /*yield*/, (pluginSystem === null || pluginSystem === void 0 ? void 0 : pluginSystem.precompile(compositions, renderer, options))];
29534
29565
  case 1:
29535
29566
  _a.sent();
29536
29567
  return [4 /*yield*/, new Promise(function (resolve) {
@@ -29547,7 +29578,7 @@ var AssetManager = /** @class */ (function () {
29547
29578
  };
29548
29579
  AssetManager.prototype.processJSON = function (json) {
29549
29580
  return __awaiter(this, void 0, void 0, function () {
29550
- var jsonScene, _a, plugins, sceneCompositions, imgUsage, images, renderLevel, usedImages;
29581
+ var jsonScene, _a, plugins, sceneCompositions, imgUsage, images, pluginSystem, renderLevel, usedImages;
29551
29582
  return __generator(this, function (_b) {
29552
29583
  switch (_b.label) {
29553
29584
  case 0:
@@ -29561,8 +29592,8 @@ var AssetManager = /** @class */ (function () {
29561
29592
  }
29562
29593
  });
29563
29594
  _a = jsonScene.plugins, plugins = _a === void 0 ? [] : _a, sceneCompositions = jsonScene.compositions, imgUsage = jsonScene.imgUsage, images = jsonScene.images;
29564
- this.pluginSystem = new PluginSystem(plugins);
29565
- return [4 /*yield*/, this.pluginSystem.processRawJSON(jsonScene, this.options)];
29595
+ pluginSystem = new PluginSystem(plugins);
29596
+ return [4 /*yield*/, pluginSystem.processRawJSON(jsonScene, this.options)];
29566
29597
  case 1:
29567
29598
  _b.sent();
29568
29599
  renderLevel = this.options.renderLevel;
@@ -29579,6 +29610,7 @@ var AssetManager = /** @class */ (function () {
29579
29610
  return [2 /*return*/, {
29580
29611
  usedImages: usedImages,
29581
29612
  jsonScene: jsonScene,
29613
+ pluginSystem: pluginSystem,
29582
29614
  }];
29583
29615
  }
29584
29616
  });
@@ -29962,7 +29994,8 @@ var CompVFXItem = /** @class */ (function (_super) {
29962
29994
  }
29963
29995
  else {
29964
29996
  item = createVFXItem(this.itemProps[i], this.composition);
29965
- item.transform.parentTransform = this.transform;
29997
+ // 相机不跟随合成移动
29998
+ item.transform.parentTransform = VFXItem.isCamera(item) ? new Transform() : this.transform;
29966
29999
  }
29967
30000
  if (VFXItem.isExtraCamera(item)) {
29968
30001
  this.extraCamera = item;
@@ -30148,7 +30181,7 @@ var CompVFXItem = /** @class */ (function (_super) {
30148
30181
  if (!parentItem) {
30149
30182
  itemNode.parentId = undefined;
30150
30183
  item.parent = undefined;
30151
- item.transform.parentTransform = this.transform;
30184
+ item.transform.parentTransform = VFXItem.isExtraCamera(item) ? new Transform() : this.transform;
30152
30185
  }
30153
30186
  else {
30154
30187
  var parentNode = this.itemCacheMap.get(parentItem.id);
@@ -30445,7 +30478,7 @@ var Composition = /** @class */ (function () {
30445
30478
  });
30446
30479
  Object.defineProperty(Composition.prototype, "startTime", {
30447
30480
  /**
30448
- * 获取合成开始时间
30481
+ * 获取合成开始渲染的时间
30449
30482
  */
30450
30483
  get: function () {
30451
30484
  var _a;
@@ -30525,7 +30558,12 @@ var Composition = /** @class */ (function () {
30525
30558
  if (this.content.ended && this.reusable) {
30526
30559
  this.restart();
30527
30560
  }
30528
- this.gotoAndPlay(this.time);
30561
+ if (this.content.started) {
30562
+ this.gotoAndPlay(this.time - this.startTime);
30563
+ }
30564
+ else {
30565
+ this.gotoAndPlay(0);
30566
+ }
30529
30567
  };
30530
30568
  /**
30531
30569
  * 暂停合成的播放
@@ -30539,14 +30577,21 @@ var Composition = /** @class */ (function () {
30539
30577
  Composition.prototype.resume = function () {
30540
30578
  this.paused = false;
30541
30579
  };
30580
+ /**
30581
+ * 跳转合成到指定时间播放
30582
+ * @param time - 相对 startTime 的时间
30583
+ */
30542
30584
  Composition.prototype.gotoAndPlay = function (time) {
30543
30585
  this.resume();
30544
30586
  if (!this.content.started) {
30545
30587
  this.content.start();
30546
- this.forwardTime(this.startTime);
30547
30588
  }
30548
- this.forwardTime(time);
30589
+ this.forwardTime(time + this.startTime);
30549
30590
  };
30591
+ /**
30592
+ * 跳转合成到指定时间并暂停
30593
+ * @param time - 相对 startTime 的时间
30594
+ */
30550
30595
  Composition.prototype.gotoAndStop = function (time) {
30551
30596
  this.gotoAndPlay(time);
30552
30597
  this.pause();
@@ -30566,21 +30611,29 @@ var Composition = /** @class */ (function () {
30566
30611
  };
30567
30612
  /**
30568
30613
  * 跳到指定时间点(不做任何播放行为)
30569
- * @param time - 指定的时间
30614
+ * @param time - 相对 startTime 的时间
30570
30615
  */
30571
30616
  Composition.prototype.setTime = function (time) {
30572
30617
  var pause = this.paused;
30573
30618
  if (pause) {
30574
30619
  this.resume();
30575
30620
  }
30576
- this.forwardTime(time, true);
30621
+ if (!this.content.started) {
30622
+ this.content.start();
30623
+ }
30624
+ this.forwardTime(time + this.startTime, true);
30577
30625
  if (pause) {
30578
30626
  this.pause();
30579
30627
  }
30580
30628
  };
30629
+ /**
30630
+ * 前进合成到指定时间
30631
+ * @param time - 相对0时刻的时间
30632
+ * @param skipRender - 是否跳过渲染
30633
+ */
30581
30634
  Composition.prototype.forwardTime = function (time, skipRender) {
30582
30635
  if (skipRender === void 0) { skipRender = false; }
30583
- var deltaTime = (this.startTime + Math.max(0, time)) * 1000 - this.content.timeInms;
30636
+ var deltaTime = time * 1000 - this.content.timeInms;
30584
30637
  var reverse = deltaTime < 0;
30585
30638
  var step = 15;
30586
30639
  var t = Math.abs(deltaTime);
@@ -32980,6 +33033,13 @@ var GLMaterial = /** @class */ (function (_super) {
32980
33033
  try {
32981
33034
  for (var _b = __values$1(Object.values(this.textures)), _c = _b.next(); !_c.done; _c = _b.next()) {
32982
33035
  var texture = _c.value;
33036
+ if (!isFunction(texture.initialize)) {
33037
+ console.error({
33038
+ content: "".concat(JSON.stringify(texture), " is not valid Texture to initialize"),
33039
+ type: LOG_TYPE,
33040
+ });
33041
+ return;
33042
+ }
32983
33043
  texture.initialize();
32984
33044
  }
32985
33045
  }
@@ -35783,7 +35843,7 @@ var Player = /** @class */ (function () {
35783
35843
  Player.prototype.createComposition = function (url, options) {
35784
35844
  if (options === void 0) { options = {}; }
35785
35845
  return __awaiter(this, void 0, void 0, function () {
35786
- var renderer, last, opts, scene, source, composition, firstFrameTime;
35846
+ var renderer, last, opts, source, scene, composition, firstFrameTime;
35787
35847
  var _this = this;
35788
35848
  return __generator(this, function (_a) {
35789
35849
  switch (_a.label) {
@@ -35804,14 +35864,9 @@ var Player = /** @class */ (function () {
35804
35864
  else {
35805
35865
  this.assetManager = new AssetManager(opts);
35806
35866
  }
35807
- if (!isScene(source)) return [3 /*break*/, 1];
35808
- scene = source;
35809
- return [3 /*break*/, 3];
35810
- case 1: return [4 /*yield*/, this.assetManager.loadScene(source, this.renderer, { env: this.env })];
35811
- case 2:
35867
+ return [4 /*yield*/, this.assetManager.loadScene(source, this.renderer, { env: this.env })];
35868
+ case 1:
35812
35869
  scene = _a.sent();
35813
- _a.label = 3;
35814
- case 3:
35815
35870
  composition = new Composition(__assign$1(__assign$1({}, opts), { renderer: renderer, width: renderer.getWidth(), height: renderer.getHeight(), event: this.event, handlePlayerPause: this.handlePlayerPause, handleMessageItem: this.handleMessageItem }), scene);
35816
35871
  if (this.ticker) {
35817
35872
  if (composition.renderLevel === RenderLevel$1.B) {
@@ -35823,7 +35878,7 @@ var Player = /** @class */ (function () {
35823
35878
  resolve(null);
35824
35879
  });
35825
35880
  })];
35826
- case 4:
35881
+ case 2:
35827
35882
  _a.sent();
35828
35883
  if (opts.autoplay) {
35829
35884
  this.autoPlaying = true;
@@ -35880,7 +35935,7 @@ var Player = /** @class */ (function () {
35880
35935
  }
35881
35936
  };
35882
35937
  /**
35883
- * 跳转全部合成带指定时间并停留
35938
+ * 跳转全部合成到指定时间并停留
35884
35939
  * @param time - 指定时间, 单位秒
35885
35940
  */
35886
35941
  Player.prototype.gotoAndStop = function (time) {
@@ -35981,38 +36036,29 @@ var Player = /** @class */ (function () {
35981
36036
  var _this = this;
35982
36037
  var _a, _b, _c;
35983
36038
  dt = Math.min(dt, 33) * this.speed;
35984
- var removed = false;
35985
36039
  var comps = this.compositions;
35986
36040
  var skipRender = false;
35987
36041
  comps.sort(function (a, b) { return a.getIndex() - b.getIndex(); });
35988
- comps.forEach(function (composition, i) {
36042
+ this.compositions = [];
36043
+ for (var i = 0; i < comps.length; i++) {
36044
+ var composition = comps[i];
35989
36045
  if (composition.textureOffloaded) {
35990
36046
  skipRender = true;
35991
36047
  console.error({
35992
36048
  content: "Composition ".concat(composition.name, " texture offloaded, skip render."),
35993
36049
  type: LOG_TYPE,
35994
36050
  });
36051
+ this.compositions.push(composition);
36052
+ continue;
35995
36053
  }
35996
- if (composition.isDestroyed) {
35997
- delete comps[i];
35998
- removed = true;
35999
- return;
36000
- }
36001
- if (composition.renderer) {
36054
+ if (!composition.isDestroyed && composition.renderer) {
36002
36055
  composition.update(dt);
36003
36056
  }
36004
- if (composition.isDestroyed) {
36005
- delete comps[i];
36006
- removed = true;
36007
- return;
36057
+ if (!composition.isDestroyed) {
36058
+ this.compositions.push(composition);
36008
36059
  }
36009
- });
36010
- if (removed) {
36011
- comps = comps.filter(function (comp) { return comp; });
36012
- comps.map(function (comp, index) { return comp.setIndex(index); });
36013
- this.compositions = comps;
36014
36060
  }
36015
- this.baseCompositionIndex = comps.length;
36061
+ this.baseCompositionIndex = this.compositions.length;
36016
36062
  if (skipRender) {
36017
36063
  (_a = this.handleRenderError) === null || _a === void 0 ? void 0 : _a.call(this, new Error('play when texture offloaded'));
36018
36064
  return (_b = this.ticker) === null || _b === void 0 ? void 0 : _b.pause();
@@ -36022,7 +36068,7 @@ var Player = /** @class */ (function () {
36022
36068
  var gl = this.renderer.context.gl;
36023
36069
  var time = (level === 2 && this.reportGPUTime) ? gpuTimer(gl) : undefined;
36024
36070
  time === null || time === void 0 ? void 0 : time.begin();
36025
- if (this.compositions.length || forceRender) {
36071
+ if (this.compositions.length || this.compositions.length < comps.length || forceRender) {
36026
36072
  this.renderer.setFrameBuffer(null);
36027
36073
  this.renderer.clear({
36028
36074
  stencilAction: exports.TextureLoadAction.clear,
@@ -36368,9 +36414,9 @@ Renderer.create = function (canvas, framework, renderOptions) {
36368
36414
  Engine.create = function (gl) {
36369
36415
  return new GLEngine(gl);
36370
36416
  };
36371
- var version = "1.1.3";
36417
+ var version = "1.1.5";
36372
36418
  console.info({
36373
- content: '[Galacean Effects Player] version: ' + "1.1.3",
36419
+ content: '[Galacean Effects Player] version: ' + "1.1.5",
36374
36420
  type: LOG_TYPE,
36375
36421
  });
36376
36422