@galacean/effects-threejs 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 threejs plugin 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';
@@ -9269,10 +9269,10 @@ var VFXItem = /** @class */ (function () {
9269
9269
  };
9270
9270
  VFXItem.prototype.translateByPixel = function (x, y) {
9271
9271
  if (this.composition) {
9272
+ // @ts-expect-error
9273
+ var _a = this.composition.renderer.canvas.getBoundingClientRect(), width = _a.width, height = _a.height;
9272
9274
  var z = this.transform.getWorldPosition().z;
9273
- var _a = this.composition.camera.getInverseVPRatio(z), rx = _a.x, ry = _a.y;
9274
- var width = this.composition.renderer.getWidth() / 2;
9275
- var height = this.composition.renderer.getHeight() / 2;
9275
+ var _b = this.composition.camera.getInverseVPRatio(z), rx = _b.x, ry = _b.y;
9276
9276
  this.transform.translate(2 * x * rx / width, -2 * y * ry / height, 0);
9277
9277
  }
9278
9278
  };
@@ -21378,8 +21378,9 @@ var Camera = /** @class */ (function () {
21378
21378
  Camera.prototype.getInverseVPRatio = function (z) {
21379
21379
  var pos = new Vector3(0, 0, z);
21380
21380
  var mat = this.getViewProjectionMatrix();
21381
- var nz = pos.applyMatrix(mat).z;
21382
- return new Vector3(1, 1, nz).applyMatrix(mat);
21381
+ var inverseVP = this.getInverseViewProjectionMatrix();
21382
+ var nz = mat.projectPoint(pos).z;
21383
+ return inverseVP.projectPoint(new Vector3(1, 1, nz));
21383
21384
  };
21384
21385
  /**
21385
21386
  * 设置相机的旋转四元数
@@ -21391,7 +21392,6 @@ var Camera = /** @class */ (function () {
21391
21392
  this.dirty = true;
21392
21393
  }
21393
21394
  else {
21394
- this.options.quat;
21395
21395
  if (!this.options.quat.equals(value)) {
21396
21396
  this.options.quat.copyFrom(value);
21397
21397
  this.dirty = true;
@@ -23492,6 +23492,26 @@ var AssetManager = /** @class */ (function () {
23492
23492
  var _a = options.timeout, timeout = _a === void 0 ? 10 : _a;
23493
23493
  this.timeout = timeout;
23494
23494
  };
23495
+ /**
23496
+ * 根据用户传入的参数修改场景数据
23497
+ */
23498
+ AssetManager.prototype.updateSceneData = function (compositions) {
23499
+ var variables = this.options.variables;
23500
+ if (!variables || Object.keys(variables).length <= 0) {
23501
+ return compositions;
23502
+ }
23503
+ compositions.forEach(function (composition) {
23504
+ composition.items.forEach(function (item) {
23505
+ if (item.type === ItemType$1.text) {
23506
+ var textVariable = variables[item.name];
23507
+ if (textVariable) {
23508
+ item.content.options.text = textVariable;
23509
+ }
23510
+ }
23511
+ });
23512
+ });
23513
+ return compositions;
23514
+ };
23495
23515
  /**
23496
23516
  * 场景创建,通过 json 创建出场景对象,并进行提前编译等工作
23497
23517
  * @param url - json 的 URL 链接或者 json 对象
@@ -23583,6 +23603,7 @@ var AssetManager = /** @class */ (function () {
23583
23603
  for (i = 0; i < scene.images.length; i++) {
23584
23604
  scene.textureOptions[i].image = scene.images[i];
23585
23605
  }
23606
+ scene.jsonScene.compositions = this.updateSceneData(scene.jsonScene.compositions);
23586
23607
  _e.label = 5;
23587
23608
  case 5: return [3 /*break*/, 12];
23588
23609
  case 6: return [4 /*yield*/, hookTimeInfo('processJSON', function () { return _this.processJSON(rawJSON); })];
@@ -23602,6 +23623,7 @@ var AssetManager = /** @class */ (function () {
23602
23623
  return [4 /*yield*/, hookTimeInfo('processTextures', function () { return _this.processTextures(loadedImages_1, loadedBins_1, jsonScene_1); })];
23603
23624
  case 10:
23604
23625
  loadedTextures = _e.sent();
23626
+ jsonScene_1.compositions = this.updateSceneData(jsonScene_1.compositions);
23605
23627
  scene = {
23606
23628
  url: url,
23607
23629
  renderLevel: this.options.renderLevel,
@@ -23701,16 +23723,17 @@ var AssetManager = /** @class */ (function () {
23701
23723
  };
23702
23724
  AssetManager.prototype.processBins = function (bins) {
23703
23725
  return __awaiter(this, void 0, void 0, function () {
23704
- var renderLevel, jobs;
23726
+ var renderLevel, baseUrl, jobs;
23705
23727
  var _this = this;
23706
23728
  return __generator(this, function (_a) {
23707
23729
  renderLevel = this.options.renderLevel;
23730
+ baseUrl = this.baseUrl;
23708
23731
  jobs = bins.map(function (bin) {
23709
23732
  if (bin instanceof ArrayBuffer) {
23710
23733
  return bin;
23711
23734
  }
23712
23735
  if (passRenderLevel(bin.renderLevel, renderLevel)) {
23713
- return _this.loadBins(bin.url);
23736
+ return _this.loadBins(new URL(bin.url, baseUrl).href);
23714
23737
  }
23715
23738
  throw new Error("Invalid bins source: ".concat(JSON.stringify(bins)));
23716
23739
  });
@@ -23728,13 +23751,14 @@ var AssetManager = /** @class */ (function () {
23728
23751
  return [2 /*return*/];
23729
23752
  }
23730
23753
  jobs = fonts.map(function (font) { return __awaiter(_this, void 0, void 0, function () {
23731
- var fontFace;
23754
+ var url, fontFace;
23732
23755
  var _a;
23733
23756
  return __generator(this, function (_b) {
23734
23757
  switch (_b.label) {
23735
23758
  case 0:
23736
23759
  if (!(font.fontURL && !AssetManager.fonts.has(font.fontFamily))) return [3 /*break*/, 4];
23737
- fontFace = new FontFace((_a = font.fontFamily) !== null && _a !== void 0 ? _a : '', 'url(' + font.fontURL + ')');
23760
+ url = new URL(font.fontURL, this.baseUrl).href;
23761
+ fontFace = new FontFace((_a = font.fontFamily) !== null && _a !== void 0 ? _a : '', 'url(' + url + ')');
23738
23762
  _b.label = 1;
23739
23763
  case 1:
23740
23764
  _b.trys.push([1, 3, , 4]);
@@ -23747,7 +23771,7 @@ var AssetManager = /** @class */ (function () {
23747
23771
  return [3 /*break*/, 4];
23748
23772
  case 3:
23749
23773
  _b.sent();
23750
- logger.warn("Invalid fonts source: ".concat(JSON.stringify(font.fontURL)));
23774
+ logger.warn("Invalid fonts source: ".concat(JSON.stringify(url)));
23751
23775
  return [3 /*break*/, 4];
23752
23776
  case 4: return [2 /*return*/];
23753
23777
  }
@@ -23979,7 +24003,7 @@ function createTextureOptionsBySource(image, sourceFrom) {
23979
24003
  return image.source;
23980
24004
  }
23981
24005
  else if (image instanceof HTMLImageElement ||
23982
- image instanceof HTMLCanvasElement) {
24006
+ isCanvas(image)) {
23983
24007
  return {
23984
24008
  image: image,
23985
24009
  sourceType: exports.TextureSourceType.image,
@@ -24016,6 +24040,11 @@ function createTextureOptionsBySource(image, sourceFrom) {
24016
24040
  }
24017
24041
  throw new Error('Invalid texture options');
24018
24042
  }
24043
+ function isCanvas(cavnas) {
24044
+ var _a;
24045
+ // 小程序 Canvas 无法使用 instanceof HTMLCanvasElement 判断
24046
+ return typeof cavnas === 'object' && cavnas !== null && ((_a = cavnas.tagName) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'CANVAS';
24047
+ }
24019
24048
 
24020
24049
  var CompVFXItem = /** @class */ (function (_super) {
24021
24050
  __extends(CompVFXItem, _super);
@@ -26913,7 +26942,7 @@ Geometry.create = function (engine, options) {
26913
26942
  Mesh.create = function (engine, props) {
26914
26943
  return new ThreeMesh(engine, props);
26915
26944
  };
26916
- var version = "1.2.2";
26945
+ var version = "1.2.4";
26917
26946
  logger.info('THREEJS plugin version: ' + version);
26918
26947
 
26919
26948
  exports.AbstractPlugin = AbstractPlugin;