@galacean/effects-threejs 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.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime threejs plugin 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';
@@ -14755,6 +14755,9 @@ var VFXItem = /** @class */ (function () {
14755
14755
  VFXItem.isTree = function (item) {
14756
14756
  return item.type === ItemType$1.tree;
14757
14757
  };
14758
+ VFXItem.isCamera = function (item) {
14759
+ return item.type === ItemType$1.camera;
14760
+ };
14758
14761
  VFXItem.isExtraCamera = function (item) {
14759
14762
  return item.id === 'extra-camera' && item.name === 'extra-camera';
14760
14763
  };
@@ -14955,10 +14958,11 @@ var VFXItem = /** @class */ (function () {
14955
14958
  }
14956
14959
  else if (this.endBehavior === END_BEHAVIOR_DESTROY$1) {
14957
14960
  this._contentVisible = false;
14961
+ shouldUpdate = true;
14962
+ dt = 0;
14958
14963
  // 预合成配置 reusable 且销毁时, 需要隐藏其中的元素
14959
14964
  if (this.type === ItemType$1.composition) {
14960
14965
  this.handleVisibleChanged(false);
14961
- this.onItemUpdate(0, lifetime);
14962
14966
  }
14963
14967
  }
14964
14968
  lifetime = Math.min(lifetime, 1);
@@ -15542,10 +15546,6 @@ var CameraVFXItem = /** @class */ (function (_super) {
15542
15546
  (_a = this.controller) === null || _a === void 0 ? void 0 : _a.update(lifetime);
15543
15547
  this.updateCamera();
15544
15548
  };
15545
- // override onEnd () {
15546
- // this.controller?.update(1);
15547
- // this.updateCamera();
15548
- // }
15549
15549
  CameraVFXItem.prototype.updateCamera = function () {
15550
15550
  if (this.controller && this.composition) {
15551
15551
  var camera = this.composition.camera;
@@ -23590,7 +23590,7 @@ var ParticleSystem = /** @class */ (function () {
23590
23590
  configurable: true
23591
23591
  });
23592
23592
  ParticleSystem.prototype.updateEmitterTransform = function (time) {
23593
- var parentTransform = this.parentTransform;
23593
+ var parentTransform = this.transform.parentTransform;
23594
23594
  var _a = this.basicTransform, path = _a.path, position = _a.position;
23595
23595
  var selfPos = position.clone();
23596
23596
  if (path) {
@@ -23600,9 +23600,9 @@ var ParticleSystem = /** @class */ (function () {
23600
23600
  this.transform.setPosition(selfPos.x, selfPos.y, selfPos.z);
23601
23601
  if (this.options.particleFollowParent && parentTransform) {
23602
23602
  var tempMatrix = parentTransform.getWorldMatrix();
23603
- this.particleMesh.mesh.worldMatrix = tempMatrix.clone();
23603
+ this.particleMesh.mesh.worldMatrix = tempMatrix;
23604
23604
  if (this.trailMesh) {
23605
- this.trailMesh.mesh.worldMatrix = tempMatrix.clone();
23605
+ this.trailMesh.mesh.worldMatrix = tempMatrix;
23606
23606
  }
23607
23607
  }
23608
23608
  };
@@ -23621,8 +23621,8 @@ var ParticleSystem = /** @class */ (function () {
23621
23621
  link.pushNode(linkContent);
23622
23622
  this.particleMesh.setPoint(point, pointIndex);
23623
23623
  this.clearPointTrail(pointIndex);
23624
- if (this.parentTransform && this.trailMesh) {
23625
- this.trailMesh.setPointStartPos(pointIndex, this.parentTransform.position.clone());
23624
+ if (this.trailMesh) {
23625
+ this.trailMesh.setPointStartPos(pointIndex, this.transform.parentTransform.position.clone());
23626
23626
  }
23627
23627
  };
23628
23628
  ParticleSystem.prototype.setVisible = function (visible) {
@@ -23660,7 +23660,8 @@ var ParticleSystem = /** @class */ (function () {
23660
23660
  }
23661
23661
  };
23662
23662
  ParticleSystem.prototype.setParentTransform = function (transform) {
23663
- this.parentTransform = transform;
23663
+ // this.transform.parentTransform = transform;
23664
+ // this.parentTransform = transform;
23664
23665
  };
23665
23666
  ParticleSystem.prototype.getTextures = function () {
23666
23667
  var e_1, _a, e_2, _b;
@@ -23953,8 +23954,8 @@ var ParticleSystem = /** @class */ (function () {
23953
23954
  if (trails.sizeAffectsLifetime) {
23954
23955
  lifetime *= size[0];
23955
23956
  }
23956
- if (trails.parentAffectsPosition && this.parentTransform) {
23957
- position.add(this.parentTransform.position);
23957
+ if (trails.parentAffectsPosition && this.transform.parentTransform) {
23958
+ position.add(this.transform.parentTransform.position);
23958
23959
  var pos = this.trailMesh.getPointStartPos(pointIndex);
23959
23960
  if (pos) {
23960
23961
  position.subtract(pos);
@@ -24194,12 +24195,11 @@ var ParticleVFXItem = /** @class */ (function (_super) {
24194
24195
  ParticleVFXItem.prototype.onItemUpdate = function (dt, lifetime) {
24195
24196
  var _a;
24196
24197
  if (this.content) {
24197
- var hide = !this.contentVisible;
24198
+ var hide = !this.visible;
24198
24199
  var parentItem = this.parentId && ((_a = this.composition) === null || _a === void 0 ? void 0 : _a.getItemByID(this.parentId));
24199
24200
  if (!hide && parentItem) {
24200
24201
  var parentData = parentItem.getRenderData();
24201
24202
  if (parentData) {
24202
- this.content.setParentTransform(parentData.transform);
24203
24203
  if (!parentData.visible) {
24204
24204
  hide = false;
24205
24205
  }
@@ -29202,7 +29202,6 @@ var CompositionSourceManager = /** @class */ (function () {
29202
29202
  }
29203
29203
  var cachedTextures = textureOptions.map(function (option) { return option && (option instanceof Texture ? option : Texture.create(engine, option)); });
29204
29204
  // 缓存创建的Texture对象
29205
- // @ts-expect-error
29206
29205
  scene.textureOptions = cachedTextures;
29207
29206
  cachedTextures === null || cachedTextures === void 0 ? void 0 : cachedTextures.forEach(function (tex) { return tex === null || tex === void 0 ? void 0 : tex.initialize(); });
29208
29207
  try {
@@ -29432,24 +29431,24 @@ var AssetManager = /** @class */ (function () {
29432
29431
  this.timeout = timeout;
29433
29432
  };
29434
29433
  /**
29435
- * 场景创建
29436
- * 通过 json 创建出场景对象,并进行提前编译等工作
29434
+ * 场景创建,通过 json 创建出场景对象,并进行提前编译等工作
29437
29435
  * @param url - json 的 URL 链接或者 json 对象
29438
29436
  * @param renderer - renderer 对象,用于获取管理、编译 shader 及 GPU 上下文的参数
29439
29437
  * @param options - 扩展参数
29440
29438
  * @returns
29441
29439
  */
29442
29440
  AssetManager.prototype.loadScene = function (url, renderer, options) {
29443
- var _a, _b;
29441
+ var _a, _b, _c;
29444
29442
  return __awaiter(this, void 0, void 0, function () {
29445
- var rawJSON, timeLabel, startTime, timeInfos, gpuInstance, asyncShaderCompile, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
29443
+ var rawJSON, timeLabel, startTime, timeInfos, gpuInstance, asyncShaderCompile, compressedTexture, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
29446
29444
  var _this = this;
29447
- return __generator(this, function (_c) {
29445
+ return __generator(this, function (_d) {
29448
29446
  timeLabel = "Load asset: ".concat(isString(url) ? url : this.id);
29449
29447
  startTime = performance.now();
29450
29448
  timeInfos = [];
29451
29449
  gpuInstance = renderer === null || renderer === void 0 ? void 0 : renderer.engine.gpuCapability;
29452
29450
  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;
29451
+ compressedTexture = (_c = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail.compressedTexture) !== null && _c !== void 0 ? _c : 0;
29453
29452
  cancelLoading = false;
29454
29453
  waitPromise = new Promise(function (resolve, reject) {
29455
29454
  return loadTimer = window.setTimeout(function () {
@@ -29474,10 +29473,10 @@ var AssetManager = /** @class */ (function () {
29474
29473
  });
29475
29474
  }); };
29476
29475
  loadResourcePromise = function () { return __awaiter(_this, void 0, void 0, function () {
29477
- var _a, usedImages, jsonScene, _b, bins, images, compositions, fonts, _c, loadedBins, loadedImages, loadedTextures, scene, totalTime;
29476
+ 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;
29478
29477
  var _this = this;
29479
- return __generator(this, function (_d) {
29480
- switch (_d.label) {
29478
+ return __generator(this, function (_e) {
29479
+ switch (_e.label) {
29481
29480
  case 0:
29482
29481
  if (!isObject(url)) return [3 /*break*/, 1];
29483
29482
  // TODO: 原 JSONLoader contructor 判断是否兼容
@@ -29490,42 +29489,66 @@ var AssetManager = /** @class */ (function () {
29490
29489
  this.baseUrl = url;
29491
29490
  return [4 /*yield*/, hookTimeInfo('loadJSON', function () { return _this.loadJSON(url); })];
29492
29491
  case 2:
29493
- rawJSON = _d.sent();
29494
- _d.label = 3;
29495
- case 3: return [4 /*yield*/, hookTimeInfo('processJSON', function () { return _this.processJSON(rawJSON); })];
29492
+ rawJSON = _e.sent();
29493
+ _e.label = 3;
29494
+ case 3:
29495
+ if (!isScene(rawJSON)) return [3 /*break*/, 6];
29496
+ // 已经加载过的 可能需要更新数据模板
29497
+ scene = __assign$1({}, rawJSON);
29498
+ if (!(this.options && this.options.variables && Object.keys(this.options.variables).length !== 0)) return [3 /*break*/, 5];
29499
+ rawImages = rawJSON.jsonScene.images;
29500
+ images_1 = scene.images;
29501
+ for (i = 0; i < rawImages.length; i++) {
29502
+ // 仅重新加载数据模板对应的图片
29503
+ if (images_1[i] instanceof HTMLCanvasElement) {
29504
+ images_1[i] = rawImages[i];
29505
+ }
29506
+ }
29507
+ _a = scene;
29508
+ return [4 /*yield*/, hookTimeInfo('processImages', function () { return _this.processImages(images_1, scene.usedImages, compressedTexture); })];
29496
29509
  case 4:
29497
- _a = _d.sent(), usedImages = _a.usedImages, jsonScene = _a.jsonScene;
29498
- _b = jsonScene.bins, bins = _b === void 0 ? [] : _b, images = jsonScene.images, compositions = jsonScene.compositions, fonts = jsonScene.fonts;
29510
+ _a.images = _e.sent();
29511
+ // 更新 TextureOptions 中的 image 指向
29512
+ for (i = 0; i < scene.images.length; i++) {
29513
+ scene.textureOptions[i].image = scene.images[i];
29514
+ }
29515
+ _e.label = 5;
29516
+ case 5: return [3 /*break*/, 12];
29517
+ case 6: return [4 /*yield*/, hookTimeInfo('processJSON', function () { return _this.processJSON(rawJSON); })];
29518
+ case 7:
29519
+ _b = _e.sent(), usedImages_1 = _b.usedImages, jsonScene_1 = _b.jsonScene, pluginSystem_1 = _b.pluginSystem;
29520
+ _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;
29499
29521
  return [4 /*yield*/, Promise.all([
29500
- hookTimeInfo('processBins', function () { return _this.processBins(bins); }),
29501
- 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); }),
29502
- hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', " compile"), function () { return _this.precompile(compositions, renderer, options); }),
29522
+ hookTimeInfo('processBins', function () { return _this.processBins(bins_1); }),
29523
+ hookTimeInfo('processImages', function () { return _this.processImages(images_2, usedImages_1, compressedTexture); }),
29524
+ hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', " compile"), function () { return _this.precompile(compositions_1, pluginSystem_1, renderer, options); }),
29503
29525
  ])];
29504
- case 5:
29505
- _c = __read$3.apply(void 0, [_d.sent(), 2]), loadedBins = _c[0], loadedImages = _c[1];
29506
- return [4 /*yield*/, hookTimeInfo('processFontURL', function () { return _this.processFontURL(fonts); })];
29507
- case 6:
29508
- _d.sent();
29509
- return [4 /*yield*/, hookTimeInfo('processTextures', function () { return _this.processTextures(loadedImages, loadedBins, jsonScene); })];
29510
- case 7:
29511
- loadedTextures = _d.sent();
29526
+ case 8:
29527
+ _d = __read$3.apply(void 0, [_e.sent(), 2]), loadedBins_1 = _d[0], loadedImages_1 = _d[1];
29528
+ return [4 /*yield*/, hookTimeInfo('processFontURL', function () { return _this.processFontURL(fonts_1); })];
29529
+ case 9:
29530
+ _e.sent();
29531
+ return [4 /*yield*/, hookTimeInfo('processTextures', function () { return _this.processTextures(loadedImages_1, loadedBins_1, jsonScene_1); })];
29532
+ case 10:
29533
+ loadedTextures = _e.sent();
29512
29534
  scene = {
29513
- jsonScene: jsonScene,
29514
- images: loadedImages,
29515
- textureOptions: loadedTextures,
29516
- bins: loadedBins,
29517
- storage: {},
29518
- pluginSystem: this.pluginSystem,
29519
- renderLevel: this.options.renderLevel,
29520
- totalTime: 0,
29521
- startTime: 0,
29522
29535
  url: url,
29536
+ renderLevel: this.options.renderLevel,
29537
+ storage: {},
29538
+ pluginSystem: pluginSystem_1,
29539
+ jsonScene: jsonScene_1,
29540
+ usedImages: usedImages_1,
29541
+ images: loadedImages_1,
29542
+ textureOptions: loadedTextures,
29543
+ bins: loadedBins_1,
29523
29544
  };
29524
29545
  // 触发插件系统 pluginSystem 的回调 prepareResource
29525
- return [4 /*yield*/, hookTimeInfo('processPlugins', function () { return _this.pluginSystem.loadResources(scene, _this.options); })];
29526
- case 8:
29546
+ return [4 /*yield*/, hookTimeInfo('processPlugins', function () { return pluginSystem_1.loadResources(scene, _this.options); })];
29547
+ case 11:
29527
29548
  // 触发插件系统 pluginSystem 的回调 prepareResource
29528
- _d.sent();
29549
+ _e.sent();
29550
+ _e.label = 12;
29551
+ case 12:
29529
29552
  totalTime = performance.now() - startTime;
29530
29553
  console.info({
29531
29554
  content: "".concat(timeLabel, ": ").concat(totalTime.toFixed(4), "ms, ").concat(timeInfos.join(' ')),
@@ -29542,7 +29565,7 @@ var AssetManager = /** @class */ (function () {
29542
29565
  });
29543
29566
  });
29544
29567
  };
29545
- AssetManager.prototype.precompile = function (compositions, renderer, options) {
29568
+ AssetManager.prototype.precompile = function (compositions, pluginSystem, renderer, options) {
29546
29569
  return __awaiter(this, void 0, void 0, function () {
29547
29570
  var shaderLibrary;
29548
29571
  return __generator(this, function (_a) {
@@ -29552,7 +29575,7 @@ var AssetManager = /** @class */ (function () {
29552
29575
  return [2 /*return*/];
29553
29576
  }
29554
29577
  shaderLibrary = renderer === null || renderer === void 0 ? void 0 : renderer.getShaderLibrary();
29555
- return [4 /*yield*/, this.pluginSystem.precompile(compositions, renderer, options)];
29578
+ return [4 /*yield*/, (pluginSystem === null || pluginSystem === void 0 ? void 0 : pluginSystem.precompile(compositions, renderer, options))];
29556
29579
  case 1:
29557
29580
  _a.sent();
29558
29581
  return [4 /*yield*/, new Promise(function (resolve) {
@@ -29569,7 +29592,7 @@ var AssetManager = /** @class */ (function () {
29569
29592
  };
29570
29593
  AssetManager.prototype.processJSON = function (json) {
29571
29594
  return __awaiter(this, void 0, void 0, function () {
29572
- var jsonScene, _a, plugins, sceneCompositions, imgUsage, images, renderLevel, usedImages;
29595
+ var jsonScene, _a, plugins, sceneCompositions, imgUsage, images, pluginSystem, renderLevel, usedImages;
29573
29596
  return __generator(this, function (_b) {
29574
29597
  switch (_b.label) {
29575
29598
  case 0:
@@ -29583,8 +29606,8 @@ var AssetManager = /** @class */ (function () {
29583
29606
  }
29584
29607
  });
29585
29608
  _a = jsonScene.plugins, plugins = _a === void 0 ? [] : _a, sceneCompositions = jsonScene.compositions, imgUsage = jsonScene.imgUsage, images = jsonScene.images;
29586
- this.pluginSystem = new PluginSystem(plugins);
29587
- return [4 /*yield*/, this.pluginSystem.processRawJSON(jsonScene, this.options)];
29609
+ pluginSystem = new PluginSystem(plugins);
29610
+ return [4 /*yield*/, pluginSystem.processRawJSON(jsonScene, this.options)];
29588
29611
  case 1:
29589
29612
  _b.sent();
29590
29613
  renderLevel = this.options.renderLevel;
@@ -29601,6 +29624,7 @@ var AssetManager = /** @class */ (function () {
29601
29624
  return [2 /*return*/, {
29602
29625
  usedImages: usedImages,
29603
29626
  jsonScene: jsonScene,
29627
+ pluginSystem: pluginSystem,
29604
29628
  }];
29605
29629
  }
29606
29630
  });
@@ -29984,7 +30008,8 @@ var CompVFXItem = /** @class */ (function (_super) {
29984
30008
  }
29985
30009
  else {
29986
30010
  item = createVFXItem(this.itemProps[i], this.composition);
29987
- item.transform.parentTransform = this.transform;
30011
+ // 相机不跟随合成移动
30012
+ item.transform.parentTransform = VFXItem.isCamera(item) ? new Transform() : this.transform;
29988
30013
  }
29989
30014
  if (VFXItem.isExtraCamera(item)) {
29990
30015
  this.extraCamera = item;
@@ -30170,7 +30195,7 @@ var CompVFXItem = /** @class */ (function (_super) {
30170
30195
  if (!parentItem) {
30171
30196
  itemNode.parentId = undefined;
30172
30197
  item.parent = undefined;
30173
- item.transform.parentTransform = this.transform;
30198
+ item.transform.parentTransform = VFXItem.isExtraCamera(item) ? new Transform() : this.transform;
30174
30199
  }
30175
30200
  else {
30176
30201
  var parentNode = this.itemCacheMap.get(parentItem.id);
@@ -32785,9 +32810,9 @@ Geometry.create = function (engine, options) {
32785
32810
  Mesh.create = function (engine, props) {
32786
32811
  return new ThreeMesh(engine, props);
32787
32812
  };
32788
- var version = "1.1.3";
32813
+ var version = "1.1.4";
32789
32814
  console.info({
32790
- content: '[Galacean Effects THREEJS] version: ' + "1.1.3",
32815
+ content: '[Galacean Effects THREEJS] version: ' + "1.1.4",
32791
32816
  type: LOG_TYPE,
32792
32817
  });
32793
32818