@galacean/effects 1.2.3 → 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.3
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;
@@ -23701,16 +23701,17 @@ var AssetManager = /** @class */ (function () {
23701
23701
  };
23702
23702
  AssetManager.prototype.processBins = function (bins) {
23703
23703
  return __awaiter(this, void 0, void 0, function () {
23704
- var renderLevel, jobs;
23704
+ var renderLevel, baseUrl, jobs;
23705
23705
  var _this = this;
23706
23706
  return __generator(this, function (_a) {
23707
23707
  renderLevel = this.options.renderLevel;
23708
+ baseUrl = this.baseUrl;
23708
23709
  jobs = bins.map(function (bin) {
23709
23710
  if (bin instanceof ArrayBuffer) {
23710
23711
  return bin;
23711
23712
  }
23712
23713
  if (passRenderLevel(bin.renderLevel, renderLevel)) {
23713
- return _this.loadBins(bin.url);
23714
+ return _this.loadBins(new URL(bin.url, baseUrl).href);
23714
23715
  }
23715
23716
  throw new Error("Invalid bins source: ".concat(JSON.stringify(bins)));
23716
23717
  });
@@ -23728,13 +23729,14 @@ var AssetManager = /** @class */ (function () {
23728
23729
  return [2 /*return*/];
23729
23730
  }
23730
23731
  jobs = fonts.map(function (font) { return __awaiter(_this, void 0, void 0, function () {
23731
- var fontFace;
23732
+ var url, fontFace;
23732
23733
  var _a;
23733
23734
  return __generator(this, function (_b) {
23734
23735
  switch (_b.label) {
23735
23736
  case 0:
23736
23737
  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 + ')');
23738
+ url = new URL(font.fontURL, this.baseUrl).href;
23739
+ fontFace = new FontFace((_a = font.fontFamily) !== null && _a !== void 0 ? _a : '', 'url(' + url + ')');
23738
23740
  _b.label = 1;
23739
23741
  case 1:
23740
23742
  _b.trys.push([1, 3, , 4]);
@@ -23747,7 +23749,7 @@ var AssetManager = /** @class */ (function () {
23747
23749
  return [3 /*break*/, 4];
23748
23750
  case 3:
23749
23751
  _b.sent();
23750
- logger.warn("Invalid fonts source: ".concat(JSON.stringify(font.fontURL)));
23752
+ logger.warn("Invalid fonts source: ".concat(JSON.stringify(url)));
23751
23753
  return [3 /*break*/, 4];
23752
23754
  case 4: return [2 /*return*/];
23753
23755
  }
@@ -23979,7 +23981,7 @@ function createTextureOptionsBySource(image, sourceFrom) {
23979
23981
  return image.source;
23980
23982
  }
23981
23983
  else if (image instanceof HTMLImageElement ||
23982
- image instanceof HTMLCanvasElement) {
23984
+ isCanvas(image)) {
23983
23985
  return {
23984
23986
  image: image,
23985
23987
  sourceType: exports.TextureSourceType.image,
@@ -24016,6 +24018,11 @@ function createTextureOptionsBySource(image, sourceFrom) {
24016
24018
  }
24017
24019
  throw new Error('Invalid texture options');
24018
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
+ }
24019
24026
 
24020
24027
  var CompVFXItem = /** @class */ (function (_super) {
24021
24028
  __extends(CompVFXItem, _super);
@@ -29599,6 +29606,7 @@ var Player = /** @class */ (function () {
29599
29606
  this.displayScale = 1;
29600
29607
  this.resumePending = false;
29601
29608
  this.disposed = false;
29609
+ this.assetManagers = [];
29602
29610
  this.speed = 1;
29603
29611
  this.baseCompositionIndex = 0;
29604
29612
  /**
@@ -29881,7 +29889,7 @@ var Player = /** @class */ (function () {
29881
29889
  Player.prototype.createComposition = function (url, options) {
29882
29890
  if (options === void 0) { options = {}; }
29883
29891
  return __awaiter(this, void 0, void 0, function () {
29884
- var renderer, last, opts, source, scene, composition, firstFrameTime;
29892
+ var renderer, last, opts, source, assetManager, scene, composition, firstFrameTime;
29885
29893
  var _this = this;
29886
29894
  return __generator(this, function (_a) {
29887
29895
  switch (_a.label) {
@@ -29896,13 +29904,9 @@ var Player = /** @class */ (function () {
29896
29904
  else {
29897
29905
  source = url;
29898
29906
  }
29899
- if (this.assetManager) {
29900
- this.assetManager.updateOptions(opts);
29901
- }
29902
- else {
29903
- this.assetManager = new AssetManager(opts);
29904
- }
29905
- 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 })];
29906
29910
  case 1:
29907
29911
  scene = _a.sent();
29908
29912
  // 加载期间 player 销毁
@@ -30232,7 +30236,7 @@ var Player = /** @class */ (function () {
30232
30236
  * @param keepCanvas - 是否保留 canvas 画面,默认不保留,canvas 不能再被使用
30233
30237
  */
30234
30238
  Player.prototype.dispose = function (keepCanvas) {
30235
- var _a, _b;
30239
+ var _a;
30236
30240
  logger.info("call player destroy: ".concat(this.name));
30237
30241
  if (this.disposed) {
30238
30242
  return;
@@ -30240,7 +30244,7 @@ var Player = /** @class */ (function () {
30240
30244
  playerMap.delete(this.canvas);
30241
30245
  this.pause();
30242
30246
  (_a = this.ticker) === null || _a === void 0 ? void 0 : _a.stop();
30243
- (_b = this.assetManager) === null || _b === void 0 ? void 0 : _b.dispose();
30247
+ this.assetManagers.forEach(function (assetManager) { return assetManager.dispose(); });
30244
30248
  this.compositions.forEach(function (comp) { return comp.dispose(); });
30245
30249
  this.compositions.length = 0;
30246
30250
  this.renderer.context.removeLostHandler({ lost: this.lost });
@@ -30446,7 +30450,7 @@ Renderer.create = function (canvas, framework, renderOptions) {
30446
30450
  Engine.create = function (gl) {
30447
30451
  return new GLEngine(gl);
30448
30452
  };
30449
- var version = "1.2.3";
30453
+ var version = "1.2.4";
30450
30454
  logger.info('player version: ' + version);
30451
30455
 
30452
30456
  exports.AbstractPlugin = AbstractPlugin;