@galacean/effects-core 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.mjs 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.2.2
6
+ * Version: v1.2.4
7
7
  */
8
8
 
9
9
  /******************************************************************************
@@ -9243,10 +9243,10 @@ var VFXItem = /** @class */ (function () {
9243
9243
  };
9244
9244
  VFXItem.prototype.translateByPixel = function (x, y) {
9245
9245
  if (this.composition) {
9246
+ // @ts-expect-error
9247
+ var _a = this.composition.renderer.canvas.getBoundingClientRect(), width = _a.width, height = _a.height;
9246
9248
  var z = this.transform.getWorldPosition().z;
9247
- var _a = this.composition.camera.getInverseVPRatio(z), rx = _a.x, ry = _a.y;
9248
- var width = this.composition.renderer.getWidth() / 2;
9249
- var height = this.composition.renderer.getHeight() / 2;
9249
+ var _b = this.composition.camera.getInverseVPRatio(z), rx = _b.x, ry = _b.y;
9250
9250
  this.transform.translate(2 * x * rx / width, -2 * y * ry / height, 0);
9251
9251
  }
9252
9252
  };
@@ -21352,8 +21352,9 @@ var Camera = /** @class */ (function () {
21352
21352
  Camera.prototype.getInverseVPRatio = function (z) {
21353
21353
  var pos = new Vector3(0, 0, z);
21354
21354
  var mat = this.getViewProjectionMatrix();
21355
- var nz = pos.applyMatrix(mat).z;
21356
- return new Vector3(1, 1, nz).applyMatrix(mat);
21355
+ var inverseVP = this.getInverseViewProjectionMatrix();
21356
+ var nz = mat.projectPoint(pos).z;
21357
+ return inverseVP.projectPoint(new Vector3(1, 1, nz));
21357
21358
  };
21358
21359
  /**
21359
21360
  * 设置相机的旋转四元数
@@ -21365,7 +21366,6 @@ var Camera = /** @class */ (function () {
21365
21366
  this.dirty = true;
21366
21367
  }
21367
21368
  else {
21368
- this.options.quat;
21369
21369
  if (!this.options.quat.equals(value)) {
21370
21370
  this.options.quat.copyFrom(value);
21371
21371
  this.dirty = true;
@@ -23466,6 +23466,26 @@ var AssetManager = /** @class */ (function () {
23466
23466
  var _a = options.timeout, timeout = _a === void 0 ? 10 : _a;
23467
23467
  this.timeout = timeout;
23468
23468
  };
23469
+ /**
23470
+ * 根据用户传入的参数修改场景数据
23471
+ */
23472
+ AssetManager.prototype.updateSceneData = function (compositions) {
23473
+ var variables = this.options.variables;
23474
+ if (!variables || Object.keys(variables).length <= 0) {
23475
+ return compositions;
23476
+ }
23477
+ compositions.forEach(function (composition) {
23478
+ composition.items.forEach(function (item) {
23479
+ if (item.type === ItemType$1.text) {
23480
+ var textVariable = variables[item.name];
23481
+ if (textVariable) {
23482
+ item.content.options.text = textVariable;
23483
+ }
23484
+ }
23485
+ });
23486
+ });
23487
+ return compositions;
23488
+ };
23469
23489
  /**
23470
23490
  * 场景创建,通过 json 创建出场景对象,并进行提前编译等工作
23471
23491
  * @param url - json 的 URL 链接或者 json 对象
@@ -23557,6 +23577,7 @@ var AssetManager = /** @class */ (function () {
23557
23577
  for (i = 0; i < scene.images.length; i++) {
23558
23578
  scene.textureOptions[i].image = scene.images[i];
23559
23579
  }
23580
+ scene.jsonScene.compositions = this.updateSceneData(scene.jsonScene.compositions);
23560
23581
  _e.label = 5;
23561
23582
  case 5: return [3 /*break*/, 12];
23562
23583
  case 6: return [4 /*yield*/, hookTimeInfo('processJSON', function () { return _this.processJSON(rawJSON); })];
@@ -23576,6 +23597,7 @@ var AssetManager = /** @class */ (function () {
23576
23597
  return [4 /*yield*/, hookTimeInfo('processTextures', function () { return _this.processTextures(loadedImages_1, loadedBins_1, jsonScene_1); })];
23577
23598
  case 10:
23578
23599
  loadedTextures = _e.sent();
23600
+ jsonScene_1.compositions = this.updateSceneData(jsonScene_1.compositions);
23579
23601
  scene = {
23580
23602
  url: url,
23581
23603
  renderLevel: this.options.renderLevel,
@@ -23675,16 +23697,17 @@ var AssetManager = /** @class */ (function () {
23675
23697
  };
23676
23698
  AssetManager.prototype.processBins = function (bins) {
23677
23699
  return __awaiter(this, void 0, void 0, function () {
23678
- var renderLevel, jobs;
23700
+ var renderLevel, baseUrl, jobs;
23679
23701
  var _this = this;
23680
23702
  return __generator(this, function (_a) {
23681
23703
  renderLevel = this.options.renderLevel;
23704
+ baseUrl = this.baseUrl;
23682
23705
  jobs = bins.map(function (bin) {
23683
23706
  if (bin instanceof ArrayBuffer) {
23684
23707
  return bin;
23685
23708
  }
23686
23709
  if (passRenderLevel(bin.renderLevel, renderLevel)) {
23687
- return _this.loadBins(bin.url);
23710
+ return _this.loadBins(new URL(bin.url, baseUrl).href);
23688
23711
  }
23689
23712
  throw new Error("Invalid bins source: ".concat(JSON.stringify(bins)));
23690
23713
  });
@@ -23702,13 +23725,14 @@ var AssetManager = /** @class */ (function () {
23702
23725
  return [2 /*return*/];
23703
23726
  }
23704
23727
  jobs = fonts.map(function (font) { return __awaiter(_this, void 0, void 0, function () {
23705
- var fontFace;
23728
+ var url, fontFace;
23706
23729
  var _a;
23707
23730
  return __generator(this, function (_b) {
23708
23731
  switch (_b.label) {
23709
23732
  case 0:
23710
23733
  if (!(font.fontURL && !AssetManager.fonts.has(font.fontFamily))) return [3 /*break*/, 4];
23711
- fontFace = new FontFace((_a = font.fontFamily) !== null && _a !== void 0 ? _a : '', 'url(' + font.fontURL + ')');
23734
+ url = new URL(font.fontURL, this.baseUrl).href;
23735
+ fontFace = new FontFace((_a = font.fontFamily) !== null && _a !== void 0 ? _a : '', 'url(' + url + ')');
23712
23736
  _b.label = 1;
23713
23737
  case 1:
23714
23738
  _b.trys.push([1, 3, , 4]);
@@ -23721,7 +23745,7 @@ var AssetManager = /** @class */ (function () {
23721
23745
  return [3 /*break*/, 4];
23722
23746
  case 3:
23723
23747
  _b.sent();
23724
- logger.warn("Invalid fonts source: ".concat(JSON.stringify(font.fontURL)));
23748
+ logger.warn("Invalid fonts source: ".concat(JSON.stringify(url)));
23725
23749
  return [3 /*break*/, 4];
23726
23750
  case 4: return [2 /*return*/];
23727
23751
  }
@@ -23953,7 +23977,7 @@ function createTextureOptionsBySource(image, sourceFrom) {
23953
23977
  return image.source;
23954
23978
  }
23955
23979
  else if (image instanceof HTMLImageElement ||
23956
- image instanceof HTMLCanvasElement) {
23980
+ isCanvas(image)) {
23957
23981
  return {
23958
23982
  image: image,
23959
23983
  sourceType: TextureSourceType.image,
@@ -23990,6 +24014,11 @@ function createTextureOptionsBySource(image, sourceFrom) {
23990
24014
  }
23991
24015
  throw new Error('Invalid texture options');
23992
24016
  }
24017
+ function isCanvas(cavnas) {
24018
+ var _a;
24019
+ // 小程序 Canvas 无法使用 instanceof HTMLCanvasElement 判断
24020
+ return typeof cavnas === 'object' && cavnas !== null && ((_a = cavnas.tagName) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'CANVAS';
24021
+ }
23993
24022
 
23994
24023
  var CompVFXItem = /** @class */ (function (_super) {
23995
24024
  __extends(CompVFXItem, _super);