@galacean/effects 1.2.2 → 1.2.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 player for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v1.2.2
6
+ * Version: v1.2.4
7
7
  */
8
8
 
9
9
  'use strict';
@@ -9247,10 +9247,10 @@ var VFXItem = /** @class */ (function () {
9247
9247
  };
9248
9248
  VFXItem.prototype.translateByPixel = function (x, y) {
9249
9249
  if (this.composition) {
9250
+ // @ts-expect-error
9251
+ var _a = this.composition.renderer.canvas.getBoundingClientRect(), width = _a.width, height = _a.height;
9250
9252
  var z = this.transform.getWorldPosition().z;
9251
- var _a = this.composition.camera.getInverseVPRatio(z), rx = _a.x, ry = _a.y;
9252
- var width = this.composition.renderer.getWidth() / 2;
9253
- var height = this.composition.renderer.getHeight() / 2;
9253
+ var _b = this.composition.camera.getInverseVPRatio(z), rx = _b.x, ry = _b.y;
9254
9254
  this.transform.translate(2 * x * rx / width, -2 * y * ry / height, 0);
9255
9255
  }
9256
9256
  };
@@ -21356,8 +21356,9 @@ var Camera = /** @class */ (function () {
21356
21356
  Camera.prototype.getInverseVPRatio = function (z) {
21357
21357
  var pos = new Vector3(0, 0, z);
21358
21358
  var mat = this.getViewProjectionMatrix();
21359
- var nz = pos.applyMatrix(mat).z;
21360
- return new Vector3(1, 1, nz).applyMatrix(mat);
21359
+ var inverseVP = this.getInverseViewProjectionMatrix();
21360
+ var nz = mat.projectPoint(pos).z;
21361
+ return inverseVP.projectPoint(new Vector3(1, 1, nz));
21361
21362
  };
21362
21363
  /**
21363
21364
  * 设置相机的旋转四元数
@@ -21369,7 +21370,6 @@ var Camera = /** @class */ (function () {
21369
21370
  this.dirty = true;
21370
21371
  }
21371
21372
  else {
21372
- this.options.quat;
21373
21373
  if (!this.options.quat.equals(value)) {
21374
21374
  this.options.quat.copyFrom(value);
21375
21375
  this.dirty = true;
@@ -23470,6 +23470,26 @@ var AssetManager = /** @class */ (function () {
23470
23470
  var _a = options.timeout, timeout = _a === void 0 ? 10 : _a;
23471
23471
  this.timeout = timeout;
23472
23472
  };
23473
+ /**
23474
+ * 根据用户传入的参数修改场景数据
23475
+ */
23476
+ AssetManager.prototype.updateSceneData = function (compositions) {
23477
+ var variables = this.options.variables;
23478
+ if (!variables || Object.keys(variables).length <= 0) {
23479
+ return compositions;
23480
+ }
23481
+ compositions.forEach(function (composition) {
23482
+ composition.items.forEach(function (item) {
23483
+ if (item.type === ItemType$1.text) {
23484
+ var textVariable = variables[item.name];
23485
+ if (textVariable) {
23486
+ item.content.options.text = textVariable;
23487
+ }
23488
+ }
23489
+ });
23490
+ });
23491
+ return compositions;
23492
+ };
23473
23493
  /**
23474
23494
  * 场景创建,通过 json 创建出场景对象,并进行提前编译等工作
23475
23495
  * @param url - json 的 URL 链接或者 json 对象
@@ -23561,6 +23581,7 @@ var AssetManager = /** @class */ (function () {
23561
23581
  for (i = 0; i < scene.images.length; i++) {
23562
23582
  scene.textureOptions[i].image = scene.images[i];
23563
23583
  }
23584
+ scene.jsonScene.compositions = this.updateSceneData(scene.jsonScene.compositions);
23564
23585
  _e.label = 5;
23565
23586
  case 5: return [3 /*break*/, 12];
23566
23587
  case 6: return [4 /*yield*/, hookTimeInfo('processJSON', function () { return _this.processJSON(rawJSON); })];
@@ -23580,6 +23601,7 @@ var AssetManager = /** @class */ (function () {
23580
23601
  return [4 /*yield*/, hookTimeInfo('processTextures', function () { return _this.processTextures(loadedImages_1, loadedBins_1, jsonScene_1); })];
23581
23602
  case 10:
23582
23603
  loadedTextures = _e.sent();
23604
+ jsonScene_1.compositions = this.updateSceneData(jsonScene_1.compositions);
23583
23605
  scene = {
23584
23606
  url: url,
23585
23607
  renderLevel: this.options.renderLevel,
@@ -23679,16 +23701,17 @@ var AssetManager = /** @class */ (function () {
23679
23701
  };
23680
23702
  AssetManager.prototype.processBins = function (bins) {
23681
23703
  return __awaiter(this, void 0, void 0, function () {
23682
- var renderLevel, jobs;
23704
+ var renderLevel, baseUrl, jobs;
23683
23705
  var _this = this;
23684
23706
  return __generator(this, function (_a) {
23685
23707
  renderLevel = this.options.renderLevel;
23708
+ baseUrl = this.baseUrl;
23686
23709
  jobs = bins.map(function (bin) {
23687
23710
  if (bin instanceof ArrayBuffer) {
23688
23711
  return bin;
23689
23712
  }
23690
23713
  if (passRenderLevel(bin.renderLevel, renderLevel)) {
23691
- return _this.loadBins(bin.url);
23714
+ return _this.loadBins(new URL(bin.url, baseUrl).href);
23692
23715
  }
23693
23716
  throw new Error("Invalid bins source: ".concat(JSON.stringify(bins)));
23694
23717
  });
@@ -23706,13 +23729,14 @@ var AssetManager = /** @class */ (function () {
23706
23729
  return [2 /*return*/];
23707
23730
  }
23708
23731
  jobs = fonts.map(function (font) { return __awaiter(_this, void 0, void 0, function () {
23709
- var fontFace;
23732
+ var url, fontFace;
23710
23733
  var _a;
23711
23734
  return __generator(this, function (_b) {
23712
23735
  switch (_b.label) {
23713
23736
  case 0:
23714
23737
  if (!(font.fontURL && !AssetManager.fonts.has(font.fontFamily))) return [3 /*break*/, 4];
23715
- fontFace = new FontFace((_a = font.fontFamily) !== null && _a !== void 0 ? _a : '', 'url(' + font.fontURL + ')');
23738
+ url = new URL(font.fontURL, this.baseUrl).href;
23739
+ fontFace = new FontFace((_a = font.fontFamily) !== null && _a !== void 0 ? _a : '', 'url(' + url + ')');
23716
23740
  _b.label = 1;
23717
23741
  case 1:
23718
23742
  _b.trys.push([1, 3, , 4]);
@@ -23725,7 +23749,7 @@ var AssetManager = /** @class */ (function () {
23725
23749
  return [3 /*break*/, 4];
23726
23750
  case 3:
23727
23751
  _b.sent();
23728
- logger.warn("Invalid fonts source: ".concat(JSON.stringify(font.fontURL)));
23752
+ logger.warn("Invalid fonts source: ".concat(JSON.stringify(url)));
23729
23753
  return [3 /*break*/, 4];
23730
23754
  case 4: return [2 /*return*/];
23731
23755
  }
@@ -23957,7 +23981,7 @@ function createTextureOptionsBySource(image, sourceFrom) {
23957
23981
  return image.source;
23958
23982
  }
23959
23983
  else if (image instanceof HTMLImageElement ||
23960
- image instanceof HTMLCanvasElement) {
23984
+ isCanvas(image)) {
23961
23985
  return {
23962
23986
  image: image,
23963
23987
  sourceType: exports.TextureSourceType.image,
@@ -23994,6 +24018,11 @@ function createTextureOptionsBySource(image, sourceFrom) {
23994
24018
  }
23995
24019
  throw new Error('Invalid texture options');
23996
24020
  }
24021
+ function isCanvas(cavnas) {
24022
+ var _a;
24023
+ // 小程序 Canvas 无法使用 instanceof HTMLCanvasElement 判断
24024
+ return typeof cavnas === 'object' && cavnas !== null && ((_a = cavnas.tagName) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'CANVAS';
24025
+ }
23997
24026
 
23998
24027
  var CompVFXItem = /** @class */ (function (_super) {
23999
24028
  __extends(CompVFXItem, _super);
@@ -29577,6 +29606,7 @@ var Player = /** @class */ (function () {
29577
29606
  this.displayScale = 1;
29578
29607
  this.resumePending = false;
29579
29608
  this.disposed = false;
29609
+ this.assetManagers = [];
29580
29610
  this.speed = 1;
29581
29611
  this.baseCompositionIndex = 0;
29582
29612
  /**
@@ -29859,7 +29889,7 @@ var Player = /** @class */ (function () {
29859
29889
  Player.prototype.createComposition = function (url, options) {
29860
29890
  if (options === void 0) { options = {}; }
29861
29891
  return __awaiter(this, void 0, void 0, function () {
29862
- var renderer, last, opts, source, scene, composition, firstFrameTime;
29892
+ var renderer, last, opts, source, assetManager, scene, composition, firstFrameTime;
29863
29893
  var _this = this;
29864
29894
  return __generator(this, function (_a) {
29865
29895
  switch (_a.label) {
@@ -29874,13 +29904,9 @@ var Player = /** @class */ (function () {
29874
29904
  else {
29875
29905
  source = url;
29876
29906
  }
29877
- if (this.assetManager) {
29878
- this.assetManager.updateOptions(opts);
29879
- }
29880
- else {
29881
- this.assetManager = new AssetManager(opts);
29882
- }
29883
- return [4 /*yield*/, this.assetManager.loadScene(source, this.renderer, { env: this.env })];
29907
+ assetManager = new AssetManager(opts);
29908
+ this.assetManagers.push(assetManager);
29909
+ return [4 /*yield*/, assetManager.loadScene(source, this.renderer, { env: this.env })];
29884
29910
  case 1:
29885
29911
  scene = _a.sent();
29886
29912
  // 加载期间 player 销毁
@@ -30210,7 +30236,7 @@ var Player = /** @class */ (function () {
30210
30236
  * @param keepCanvas - 是否保留 canvas 画面,默认不保留,canvas 不能再被使用
30211
30237
  */
30212
30238
  Player.prototype.dispose = function (keepCanvas) {
30213
- var _a, _b;
30239
+ var _a;
30214
30240
  logger.info("call player destroy: ".concat(this.name));
30215
30241
  if (this.disposed) {
30216
30242
  return;
@@ -30218,7 +30244,7 @@ var Player = /** @class */ (function () {
30218
30244
  playerMap.delete(this.canvas);
30219
30245
  this.pause();
30220
30246
  (_a = this.ticker) === null || _a === void 0 ? void 0 : _a.stop();
30221
- (_b = this.assetManager) === null || _b === void 0 ? void 0 : _b.dispose();
30247
+ this.assetManagers.forEach(function (assetManager) { return assetManager.dispose(); });
30222
30248
  this.compositions.forEach(function (comp) { return comp.dispose(); });
30223
30249
  this.compositions.length = 0;
30224
30250
  this.renderer.context.removeLostHandler({ lost: this.lost });
@@ -30424,7 +30450,7 @@ Renderer.create = function (canvas, framework, renderOptions) {
30424
30450
  Engine.create = function (gl) {
30425
30451
  return new GLEngine(gl);
30426
30452
  };
30427
- var version = "1.2.2";
30453
+ var version = "1.2.4";
30428
30454
  logger.info('player version: ' + version);
30429
30455
 
30430
30456
  exports.AbstractPlugin = AbstractPlugin;