@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/player.d.ts CHANGED
@@ -163,7 +163,7 @@ export declare class Player implements Disposable, LostHandler, RestoreHandler {
163
163
  private resumePending;
164
164
  private offscreenMode;
165
165
  private disposed;
166
- private assetManager;
166
+ private assetManagers;
167
167
  private speed;
168
168
  private baseCompositionIndex;
169
169
  /**
package/dist/weapp.js CHANGED
@@ -9241,10 +9241,10 @@ var VFXItem = /** @class */ (function () {
9241
9241
  };
9242
9242
  VFXItem.prototype.translateByPixel = function (x, y) {
9243
9243
  if (this.composition) {
9244
+ // @ts-expect-error
9245
+ var _a = this.composition.renderer.canvas.getBoundingClientRect(), width = _a.width, height = _a.height;
9244
9246
  var z = this.transform.getWorldPosition().z;
9245
- var _a = this.composition.camera.getInverseVPRatio(z), rx = _a.x, ry = _a.y;
9246
- var width = this.composition.renderer.getWidth() / 2;
9247
- var height = this.composition.renderer.getHeight() / 2;
9247
+ var _b = this.composition.camera.getInverseVPRatio(z), rx = _b.x, ry = _b.y;
9248
9248
  this.transform.translate(2 * x * rx / width, -2 * y * ry / height, 0);
9249
9249
  }
9250
9250
  };
@@ -21350,8 +21350,9 @@ var Camera = /** @class */ (function () {
21350
21350
  Camera.prototype.getInverseVPRatio = function (z) {
21351
21351
  var pos = new Vector3(0, 0, z);
21352
21352
  var mat = this.getViewProjectionMatrix();
21353
- var nz = pos.applyMatrix(mat).z;
21354
- return new Vector3(1, 1, nz).applyMatrix(mat);
21353
+ var inverseVP = this.getInverseViewProjectionMatrix();
21354
+ var nz = mat.projectPoint(pos).z;
21355
+ return inverseVP.projectPoint(new Vector3(1, 1, nz));
21355
21356
  };
21356
21357
  /**
21357
21358
  * 设置相机的旋转四元数
@@ -21363,7 +21364,6 @@ var Camera = /** @class */ (function () {
21363
21364
  this.dirty = true;
21364
21365
  }
21365
21366
  else {
21366
- this.options.quat;
21367
21367
  if (!this.options.quat.equals(value)) {
21368
21368
  this.options.quat.copyFrom(value);
21369
21369
  this.dirty = true;
@@ -23695,16 +23695,17 @@ var AssetManager = /** @class */ (function () {
23695
23695
  };
23696
23696
  AssetManager.prototype.processBins = function (bins) {
23697
23697
  return __awaiter(this, void 0, void 0, function () {
23698
- var renderLevel, jobs;
23698
+ var renderLevel, baseUrl, jobs;
23699
23699
  var _this = this;
23700
23700
  return __generator(this, function (_a) {
23701
23701
  renderLevel = this.options.renderLevel;
23702
+ baseUrl = this.baseUrl;
23702
23703
  jobs = bins.map(function (bin) {
23703
23704
  if (bin instanceof ArrayBuffer) {
23704
23705
  return bin;
23705
23706
  }
23706
23707
  if (passRenderLevel(bin.renderLevel, renderLevel)) {
23707
- return _this.loadBins(bin.url);
23708
+ return _this.loadBins(new weapp.URL(bin.url, baseUrl).href);
23708
23709
  }
23709
23710
  throw new Error("Invalid bins source: ".concat(JSON.stringify(bins)));
23710
23711
  });
@@ -23722,13 +23723,14 @@ var AssetManager = /** @class */ (function () {
23722
23723
  return [2 /*return*/];
23723
23724
  }
23724
23725
  jobs = fonts.map(function (font) { return __awaiter(_this, void 0, void 0, function () {
23725
- var fontFace;
23726
+ var url, fontFace;
23726
23727
  var _a;
23727
23728
  return __generator(this, function (_b) {
23728
23729
  switch (_b.label) {
23729
23730
  case 0:
23730
23731
  if (!(font.fontURL && !AssetManager.fonts.has(font.fontFamily))) return [3 /*break*/, 4];
23731
- fontFace = new FontFace((_a = font.fontFamily) !== null && _a !== void 0 ? _a : '', 'url(' + font.fontURL + ')');
23732
+ url = new weapp.URL(font.fontURL, this.baseUrl).href;
23733
+ fontFace = new FontFace((_a = font.fontFamily) !== null && _a !== void 0 ? _a : '', 'url(' + url + ')');
23732
23734
  _b.label = 1;
23733
23735
  case 1:
23734
23736
  _b.trys.push([1, 3, , 4]);
@@ -23741,7 +23743,7 @@ var AssetManager = /** @class */ (function () {
23741
23743
  return [3 /*break*/, 4];
23742
23744
  case 3:
23743
23745
  _b.sent();
23744
- logger.warn("Invalid fonts source: ".concat(JSON.stringify(font.fontURL)));
23746
+ logger.warn("Invalid fonts source: ".concat(JSON.stringify(url)));
23745
23747
  return [3 /*break*/, 4];
23746
23748
  case 4: return [2 /*return*/];
23747
23749
  }
@@ -23973,7 +23975,7 @@ function createTextureOptionsBySource(image, sourceFrom) {
23973
23975
  return image.source;
23974
23976
  }
23975
23977
  else if (image instanceof weapp.HTMLImageElement ||
23976
- image instanceof weapp.HTMLCanvasElement) {
23978
+ isCanvas(image)) {
23977
23979
  return {
23978
23980
  image: image,
23979
23981
  sourceType: exports.TextureSourceType.image,
@@ -24010,6 +24012,11 @@ function createTextureOptionsBySource(image, sourceFrom) {
24010
24012
  }
24011
24013
  throw new Error('Invalid texture options');
24012
24014
  }
24015
+ function isCanvas(cavnas) {
24016
+ var _a;
24017
+ // 小程序 Canvas 无法使用 instanceof HTMLCanvasElement 判断
24018
+ return typeof cavnas === 'object' && cavnas !== null && ((_a = cavnas.tagName) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'CANVAS';
24019
+ }
24013
24020
 
24014
24021
  var CompVFXItem = /** @class */ (function (_super) {
24015
24022
  __extends(CompVFXItem, _super);
@@ -29593,6 +29600,7 @@ var Player = /** @class */ (function () {
29593
29600
  this.displayScale = 1;
29594
29601
  this.resumePending = false;
29595
29602
  this.disposed = false;
29603
+ this.assetManagers = [];
29596
29604
  this.speed = 1;
29597
29605
  this.baseCompositionIndex = 0;
29598
29606
  /**
@@ -29875,7 +29883,7 @@ var Player = /** @class */ (function () {
29875
29883
  Player.prototype.createComposition = function (url, options) {
29876
29884
  if (options === void 0) { options = {}; }
29877
29885
  return __awaiter(this, void 0, void 0, function () {
29878
- var renderer, last, opts, source, scene, composition, firstFrameTime;
29886
+ var renderer, last, opts, source, assetManager, scene, composition, firstFrameTime;
29879
29887
  var _this = this;
29880
29888
  return __generator(this, function (_a) {
29881
29889
  switch (_a.label) {
@@ -29890,13 +29898,9 @@ var Player = /** @class */ (function () {
29890
29898
  else {
29891
29899
  source = url;
29892
29900
  }
29893
- if (this.assetManager) {
29894
- this.assetManager.updateOptions(opts);
29895
- }
29896
- else {
29897
- this.assetManager = new AssetManager(opts);
29898
- }
29899
- return [4 /*yield*/, this.assetManager.loadScene(source, this.renderer, { env: this.env })];
29901
+ assetManager = new AssetManager(opts);
29902
+ this.assetManagers.push(assetManager);
29903
+ return [4 /*yield*/, assetManager.loadScene(source, this.renderer, { env: this.env })];
29900
29904
  case 1:
29901
29905
  scene = _a.sent();
29902
29906
  // 加载期间 player 销毁
@@ -30226,7 +30230,7 @@ var Player = /** @class */ (function () {
30226
30230
  * @param keepCanvas - 是否保留 canvas 画面,默认不保留,canvas 不能再被使用
30227
30231
  */
30228
30232
  Player.prototype.dispose = function (keepCanvas) {
30229
- var _a, _b;
30233
+ var _a;
30230
30234
  logger.info("call player destroy: ".concat(this.name));
30231
30235
  if (this.disposed) {
30232
30236
  return;
@@ -30234,7 +30238,7 @@ var Player = /** @class */ (function () {
30234
30238
  playerMap.delete(this.canvas);
30235
30239
  this.pause();
30236
30240
  (_a = this.ticker) === null || _a === void 0 ? void 0 : _a.stop();
30237
- (_b = this.assetManager) === null || _b === void 0 ? void 0 : _b.dispose();
30241
+ this.assetManagers.forEach(function (assetManager) { return assetManager.dispose(); });
30238
30242
  this.compositions.forEach(function (comp) { return comp.dispose(); });
30239
30243
  this.compositions.length = 0;
30240
30244
  this.renderer.context.removeLostHandler({ lost: this.lost });
@@ -30440,7 +30444,7 @@ Renderer.create = function (canvas, framework, renderOptions) {
30440
30444
  Engine.create = function (gl) {
30441
30445
  return new GLEngine(gl);
30442
30446
  };
30443
- var version = "1.2.3";
30447
+ var version = "1.2.4";
30444
30448
  logger.info('player version: ' + version);
30445
30449
 
30446
30450
  exports.AbstractPlugin = AbstractPlugin;