@galacean/effects-core 1.1.3 → 1.1.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.
@@ -84,10 +84,6 @@ export declare class AssetManager implements Disposable {
84
84
  * 相对url的基本路径
85
85
  */
86
86
  private baseUrl;
87
- /**
88
- * 插件系统
89
- */
90
- private pluginSystem;
91
87
  /**
92
88
  * 图像资源,用于创建和释放GPU纹理资源
93
89
  */
@@ -110,14 +106,13 @@ export declare class AssetManager implements Disposable {
110
106
  constructor(options?: SceneLoadOptions, downloader?: Downloader);
111
107
  updateOptions(options?: SceneLoadOptions): void;
112
108
  /**
113
- * 场景创建
114
- * 通过 json 创建出场景对象,并进行提前编译等工作
109
+ * 场景创建,通过 json 创建出场景对象,并进行提前编译等工作
115
110
  * @param url - json 的 URL 链接或者 json 对象
116
111
  * @param renderer - renderer 对象,用于获取管理、编译 shader 及 GPU 上下文的参数
117
112
  * @param options - 扩展参数
118
113
  * @returns
119
114
  */
120
- loadScene(url: string | JSONValue, renderer?: Renderer, options?: {
115
+ loadScene(url: string | JSONValue | Scene, renderer?: Renderer, options?: {
121
116
  env: string;
122
117
  }): Promise<Scene>;
123
118
  private precompile;
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v1.1.3
6
+ * Version: v1.1.4
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);
@@ -15520,10 +15524,6 @@ var CameraVFXItem = /** @class */ (function (_super) {
15520
15524
  (_a = this.controller) === null || _a === void 0 ? void 0 : _a.update(lifetime);
15521
15525
  this.updateCamera();
15522
15526
  };
15523
- // override onEnd () {
15524
- // this.controller?.update(1);
15525
- // this.updateCamera();
15526
- // }
15527
15527
  CameraVFXItem.prototype.updateCamera = function () {
15528
15528
  if (this.controller && this.composition) {
15529
15529
  var camera = this.composition.camera;
@@ -23568,7 +23568,7 @@ var ParticleSystem = /** @class */ (function () {
23568
23568
  configurable: true
23569
23569
  });
23570
23570
  ParticleSystem.prototype.updateEmitterTransform = function (time) {
23571
- var parentTransform = this.parentTransform;
23571
+ var parentTransform = this.transform.parentTransform;
23572
23572
  var _a = this.basicTransform, path = _a.path, position = _a.position;
23573
23573
  var selfPos = position.clone();
23574
23574
  if (path) {
@@ -23578,9 +23578,9 @@ var ParticleSystem = /** @class */ (function () {
23578
23578
  this.transform.setPosition(selfPos.x, selfPos.y, selfPos.z);
23579
23579
  if (this.options.particleFollowParent && parentTransform) {
23580
23580
  var tempMatrix = parentTransform.getWorldMatrix();
23581
- this.particleMesh.mesh.worldMatrix = tempMatrix.clone();
23581
+ this.particleMesh.mesh.worldMatrix = tempMatrix;
23582
23582
  if (this.trailMesh) {
23583
- this.trailMesh.mesh.worldMatrix = tempMatrix.clone();
23583
+ this.trailMesh.mesh.worldMatrix = tempMatrix;
23584
23584
  }
23585
23585
  }
23586
23586
  };
@@ -23599,8 +23599,8 @@ var ParticleSystem = /** @class */ (function () {
23599
23599
  link.pushNode(linkContent);
23600
23600
  this.particleMesh.setPoint(point, pointIndex);
23601
23601
  this.clearPointTrail(pointIndex);
23602
- if (this.parentTransform && this.trailMesh) {
23603
- this.trailMesh.setPointStartPos(pointIndex, this.parentTransform.position.clone());
23602
+ if (this.trailMesh) {
23603
+ this.trailMesh.setPointStartPos(pointIndex, this.transform.parentTransform.position.clone());
23604
23604
  }
23605
23605
  };
23606
23606
  ParticleSystem.prototype.setVisible = function (visible) {
@@ -23638,7 +23638,8 @@ var ParticleSystem = /** @class */ (function () {
23638
23638
  }
23639
23639
  };
23640
23640
  ParticleSystem.prototype.setParentTransform = function (transform) {
23641
- this.parentTransform = transform;
23641
+ // this.transform.parentTransform = transform;
23642
+ // this.parentTransform = transform;
23642
23643
  };
23643
23644
  ParticleSystem.prototype.getTextures = function () {
23644
23645
  var e_1, _a, e_2, _b;
@@ -23931,8 +23932,8 @@ var ParticleSystem = /** @class */ (function () {
23931
23932
  if (trails.sizeAffectsLifetime) {
23932
23933
  lifetime *= size[0];
23933
23934
  }
23934
- if (trails.parentAffectsPosition && this.parentTransform) {
23935
- position.add(this.parentTransform.position);
23935
+ if (trails.parentAffectsPosition && this.transform.parentTransform) {
23936
+ position.add(this.transform.parentTransform.position);
23936
23937
  var pos = this.trailMesh.getPointStartPos(pointIndex);
23937
23938
  if (pos) {
23938
23939
  position.subtract(pos);
@@ -24172,12 +24173,11 @@ var ParticleVFXItem = /** @class */ (function (_super) {
24172
24173
  ParticleVFXItem.prototype.onItemUpdate = function (dt, lifetime) {
24173
24174
  var _a;
24174
24175
  if (this.content) {
24175
- var hide = !this.contentVisible;
24176
+ var hide = !this.visible;
24176
24177
  var parentItem = this.parentId && ((_a = this.composition) === null || _a === void 0 ? void 0 : _a.getItemByID(this.parentId));
24177
24178
  if (!hide && parentItem) {
24178
24179
  var parentData = parentItem.getRenderData();
24179
24180
  if (parentData) {
24180
- this.content.setParentTransform(parentData.transform);
24181
24181
  if (!parentData.visible) {
24182
24182
  hide = false;
24183
24183
  }
@@ -29180,7 +29180,6 @@ var CompositionSourceManager = /** @class */ (function () {
29180
29180
  }
29181
29181
  var cachedTextures = textureOptions.map(function (option) { return option && (option instanceof Texture ? option : Texture.create(engine, option)); });
29182
29182
  // 缓存创建的Texture对象
29183
- // @ts-expect-error
29184
29183
  scene.textureOptions = cachedTextures;
29185
29184
  cachedTextures === null || cachedTextures === void 0 ? void 0 : cachedTextures.forEach(function (tex) { return tex === null || tex === void 0 ? void 0 : tex.initialize(); });
29186
29185
  try {
@@ -29410,24 +29409,24 @@ var AssetManager = /** @class */ (function () {
29410
29409
  this.timeout = timeout;
29411
29410
  };
29412
29411
  /**
29413
- * 场景创建
29414
- * 通过 json 创建出场景对象,并进行提前编译等工作
29412
+ * 场景创建,通过 json 创建出场景对象,并进行提前编译等工作
29415
29413
  * @param url - json 的 URL 链接或者 json 对象
29416
29414
  * @param renderer - renderer 对象,用于获取管理、编译 shader 及 GPU 上下文的参数
29417
29415
  * @param options - 扩展参数
29418
29416
  * @returns
29419
29417
  */
29420
29418
  AssetManager.prototype.loadScene = function (url, renderer, options) {
29421
- var _a, _b;
29419
+ var _a, _b, _c;
29422
29420
  return __awaiter(this, void 0, void 0, function () {
29423
- var rawJSON, timeLabel, startTime, timeInfos, gpuInstance, asyncShaderCompile, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
29421
+ var rawJSON, timeLabel, startTime, timeInfos, gpuInstance, asyncShaderCompile, compressedTexture, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
29424
29422
  var _this = this;
29425
- return __generator(this, function (_c) {
29423
+ return __generator(this, function (_d) {
29426
29424
  timeLabel = "Load asset: ".concat(isString(url) ? url : this.id);
29427
29425
  startTime = performance.now();
29428
29426
  timeInfos = [];
29429
29427
  gpuInstance = renderer === null || renderer === void 0 ? void 0 : renderer.engine.gpuCapability;
29430
29428
  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;
29429
+ compressedTexture = (_c = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail.compressedTexture) !== null && _c !== void 0 ? _c : 0;
29431
29430
  cancelLoading = false;
29432
29431
  waitPromise = new Promise(function (resolve, reject) {
29433
29432
  return loadTimer = window.setTimeout(function () {
@@ -29452,10 +29451,10 @@ var AssetManager = /** @class */ (function () {
29452
29451
  });
29453
29452
  }); };
29454
29453
  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;
29454
+ 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
29455
  var _this = this;
29457
- return __generator(this, function (_d) {
29458
- switch (_d.label) {
29456
+ return __generator(this, function (_e) {
29457
+ switch (_e.label) {
29459
29458
  case 0:
29460
29459
  if (!isObject(url)) return [3 /*break*/, 1];
29461
29460
  // TODO: 原 JSONLoader contructor 判断是否兼容
@@ -29468,42 +29467,66 @@ var AssetManager = /** @class */ (function () {
29468
29467
  this.baseUrl = url;
29469
29468
  return [4 /*yield*/, hookTimeInfo('loadJSON', function () { return _this.loadJSON(url); })];
29470
29469
  case 2:
29471
- rawJSON = _d.sent();
29472
- _d.label = 3;
29473
- case 3: return [4 /*yield*/, hookTimeInfo('processJSON', function () { return _this.processJSON(rawJSON); })];
29470
+ rawJSON = _e.sent();
29471
+ _e.label = 3;
29472
+ case 3:
29473
+ if (!isScene(rawJSON)) return [3 /*break*/, 6];
29474
+ // 已经加载过的 可能需要更新数据模板
29475
+ scene = __assign$1({}, rawJSON);
29476
+ if (!(this.options && this.options.variables && Object.keys(this.options.variables).length !== 0)) return [3 /*break*/, 5];
29477
+ rawImages = rawJSON.jsonScene.images;
29478
+ images_1 = scene.images;
29479
+ for (i = 0; i < rawImages.length; i++) {
29480
+ // 仅重新加载数据模板对应的图片
29481
+ if (images_1[i] instanceof HTMLCanvasElement) {
29482
+ images_1[i] = rawImages[i];
29483
+ }
29484
+ }
29485
+ _a = scene;
29486
+ return [4 /*yield*/, hookTimeInfo('processImages', function () { return _this.processImages(images_1, scene.usedImages, compressedTexture); })];
29474
29487
  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;
29488
+ _a.images = _e.sent();
29489
+ // 更新 TextureOptions 中的 image 指向
29490
+ for (i = 0; i < scene.images.length; i++) {
29491
+ scene.textureOptions[i].image = scene.images[i];
29492
+ }
29493
+ _e.label = 5;
29494
+ case 5: return [3 /*break*/, 12];
29495
+ case 6: return [4 /*yield*/, hookTimeInfo('processJSON', function () { return _this.processJSON(rawJSON); })];
29496
+ case 7:
29497
+ _b = _e.sent(), usedImages_1 = _b.usedImages, jsonScene_1 = _b.jsonScene, pluginSystem_1 = _b.pluginSystem;
29498
+ _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
29499
  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); }),
29500
+ hookTimeInfo('processBins', function () { return _this.processBins(bins_1); }),
29501
+ hookTimeInfo('processImages', function () { return _this.processImages(images_2, usedImages_1, compressedTexture); }),
29502
+ hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', " compile"), function () { return _this.precompile(compositions_1, pluginSystem_1, renderer, options); }),
29481
29503
  ])];
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();
29504
+ case 8:
29505
+ _d = __read$3.apply(void 0, [_e.sent(), 2]), loadedBins_1 = _d[0], loadedImages_1 = _d[1];
29506
+ return [4 /*yield*/, hookTimeInfo('processFontURL', function () { return _this.processFontURL(fonts_1); })];
29507
+ case 9:
29508
+ _e.sent();
29509
+ return [4 /*yield*/, hookTimeInfo('processTextures', function () { return _this.processTextures(loadedImages_1, loadedBins_1, jsonScene_1); })];
29510
+ case 10:
29511
+ loadedTextures = _e.sent();
29490
29512
  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
29513
  url: url,
29514
+ renderLevel: this.options.renderLevel,
29515
+ storage: {},
29516
+ pluginSystem: pluginSystem_1,
29517
+ jsonScene: jsonScene_1,
29518
+ usedImages: usedImages_1,
29519
+ images: loadedImages_1,
29520
+ textureOptions: loadedTextures,
29521
+ bins: loadedBins_1,
29501
29522
  };
29502
29523
  // 触发插件系统 pluginSystem 的回调 prepareResource
29503
- return [4 /*yield*/, hookTimeInfo('processPlugins', function () { return _this.pluginSystem.loadResources(scene, _this.options); })];
29504
- case 8:
29524
+ return [4 /*yield*/, hookTimeInfo('processPlugins', function () { return pluginSystem_1.loadResources(scene, _this.options); })];
29525
+ case 11:
29505
29526
  // 触发插件系统 pluginSystem 的回调 prepareResource
29506
- _d.sent();
29527
+ _e.sent();
29528
+ _e.label = 12;
29529
+ case 12:
29507
29530
  totalTime = performance.now() - startTime;
29508
29531
  console.info({
29509
29532
  content: "".concat(timeLabel, ": ").concat(totalTime.toFixed(4), "ms, ").concat(timeInfos.join(' ')),
@@ -29520,7 +29543,7 @@ var AssetManager = /** @class */ (function () {
29520
29543
  });
29521
29544
  });
29522
29545
  };
29523
- AssetManager.prototype.precompile = function (compositions, renderer, options) {
29546
+ AssetManager.prototype.precompile = function (compositions, pluginSystem, renderer, options) {
29524
29547
  return __awaiter(this, void 0, void 0, function () {
29525
29548
  var shaderLibrary;
29526
29549
  return __generator(this, function (_a) {
@@ -29530,7 +29553,7 @@ var AssetManager = /** @class */ (function () {
29530
29553
  return [2 /*return*/];
29531
29554
  }
29532
29555
  shaderLibrary = renderer === null || renderer === void 0 ? void 0 : renderer.getShaderLibrary();
29533
- return [4 /*yield*/, this.pluginSystem.precompile(compositions, renderer, options)];
29556
+ return [4 /*yield*/, (pluginSystem === null || pluginSystem === void 0 ? void 0 : pluginSystem.precompile(compositions, renderer, options))];
29534
29557
  case 1:
29535
29558
  _a.sent();
29536
29559
  return [4 /*yield*/, new Promise(function (resolve) {
@@ -29547,7 +29570,7 @@ var AssetManager = /** @class */ (function () {
29547
29570
  };
29548
29571
  AssetManager.prototype.processJSON = function (json) {
29549
29572
  return __awaiter(this, void 0, void 0, function () {
29550
- var jsonScene, _a, plugins, sceneCompositions, imgUsage, images, renderLevel, usedImages;
29573
+ var jsonScene, _a, plugins, sceneCompositions, imgUsage, images, pluginSystem, renderLevel, usedImages;
29551
29574
  return __generator(this, function (_b) {
29552
29575
  switch (_b.label) {
29553
29576
  case 0:
@@ -29561,8 +29584,8 @@ var AssetManager = /** @class */ (function () {
29561
29584
  }
29562
29585
  });
29563
29586
  _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)];
29587
+ pluginSystem = new PluginSystem(plugins);
29588
+ return [4 /*yield*/, pluginSystem.processRawJSON(jsonScene, this.options)];
29566
29589
  case 1:
29567
29590
  _b.sent();
29568
29591
  renderLevel = this.options.renderLevel;
@@ -29579,6 +29602,7 @@ var AssetManager = /** @class */ (function () {
29579
29602
  return [2 /*return*/, {
29580
29603
  usedImages: usedImages,
29581
29604
  jsonScene: jsonScene,
29605
+ pluginSystem: pluginSystem,
29582
29606
  }];
29583
29607
  }
29584
29608
  });
@@ -29962,7 +29986,8 @@ var CompVFXItem = /** @class */ (function (_super) {
29962
29986
  }
29963
29987
  else {
29964
29988
  item = createVFXItem(this.itemProps[i], this.composition);
29965
- item.transform.parentTransform = this.transform;
29989
+ // 相机不跟随合成移动
29990
+ item.transform.parentTransform = VFXItem.isCamera(item) ? new Transform() : this.transform;
29966
29991
  }
29967
29992
  if (VFXItem.isExtraCamera(item)) {
29968
29993
  this.extraCamera = item;
@@ -30148,7 +30173,7 @@ var CompVFXItem = /** @class */ (function (_super) {
30148
30173
  if (!parentItem) {
30149
30174
  itemNode.parentId = undefined;
30150
30175
  item.parent = undefined;
30151
- item.transform.parentTransform = this.transform;
30176
+ item.transform.parentTransform = VFXItem.isExtraCamera(item) ? new Transform() : this.transform;
30152
30177
  }
30153
30178
  else {
30154
30179
  var parentNode = this.itemCacheMap.get(parentItem.id);