@galacean/effects-core 1.6.0-beta.0 → 1.6.0-beta.1

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.
@@ -19,6 +19,7 @@ export interface CompositionStatistic {
19
19
  loadTime: number;
20
20
  loadStart: number;
21
21
  firstFrameTime: number;
22
+ precompileTime: number;
22
23
  }
23
24
  export interface MessageItem {
24
25
  id: string;
package/dist/index.js 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.6.0-beta.0
6
+ * Version: v1.6.0-beta.1
7
7
  */
8
8
 
9
9
  'use strict';
@@ -13520,6 +13520,14 @@ var InteractVFXItem = /** @class */ (function (_super) {
13520
13520
  function InteractVFXItem(props, composition) {
13521
13521
  var _a;
13522
13522
  var _this = _super.call(this, props, composition) || this;
13523
+ /**
13524
+ * 拖拽的惯性衰减系数,范围[0, 1], 越大惯性越强
13525
+ */
13526
+ _this.downgrade = 0.95;
13527
+ /**
13528
+ * 拖拽的距离映射系数,越大越容易拖动
13529
+ */
13530
+ _this.dragRatio = [1, 1];
13523
13531
  _this.engine = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.getEngine();
13524
13532
  return _this;
13525
13533
  }
@@ -13530,8 +13538,23 @@ var InteractVFXItem = /** @class */ (function (_super) {
13530
13538
  enumerable: false,
13531
13539
  configurable: true
13532
13540
  });
13541
+ Object.defineProperty(InteractVFXItem.prototype, "enable", {
13542
+ get: function () {
13543
+ return this.enabled;
13544
+ },
13545
+ set: function (enable) {
13546
+ this.enabled = enable;
13547
+ if (!enable) {
13548
+ // 立刻停止惯性滑动
13549
+ this.bouncingArg = null;
13550
+ }
13551
+ },
13552
+ enumerable: false,
13553
+ configurable: true
13554
+ });
13533
13555
  InteractVFXItem.prototype.onConstructed = function (options) {
13534
13556
  this.ui = options.content;
13557
+ this.enabled = true;
13535
13558
  };
13536
13559
  InteractVFXItem.prototype.onLifetimeBegin = function (composition) {
13537
13560
  var _a, _b, _c;
@@ -13550,9 +13573,8 @@ var InteractVFXItem = /** @class */ (function (_super) {
13550
13573
  if (!this.dragEvent || !this.bouncingArg) {
13551
13574
  return;
13552
13575
  }
13553
- var downgrade = 0.95;
13554
- this.bouncingArg.vx *= downgrade;
13555
- this.bouncingArg.vy *= downgrade;
13576
+ this.bouncingArg.vx *= this.downgrade;
13577
+ this.bouncingArg.vy *= this.downgrade;
13556
13578
  this.bouncingArg.dy += this.bouncingArg.vy;
13557
13579
  this.bouncingArg.dx += this.bouncingArg.vx;
13558
13580
  if (shouldIgnoreBouncing(this.bouncingArg)) {
@@ -13588,7 +13610,7 @@ var InteractVFXItem = /** @class */ (function (_super) {
13588
13610
  };
13589
13611
  };
13590
13612
  InteractVFXItem.prototype.getHitTestParams = function () {
13591
- if (!this.clickable) {
13613
+ if (!this.clickable || !this.canInteract()) {
13592
13614
  return;
13593
13615
  }
13594
13616
  var behavior = this.ui.options.behavior;
@@ -13624,13 +13646,13 @@ var InteractVFXItem = /** @class */ (function (_super) {
13624
13646
  var dragEvent;
13625
13647
  var handlerMap = {
13626
13648
  touchstart: function (event) {
13627
- var _a, _b;
13628
- if (!((_a = _this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
13649
+ var _a;
13650
+ if (!_this.canInteract()) {
13629
13651
  return;
13630
13652
  }
13631
13653
  _this.dragEvent = null;
13632
13654
  _this.bouncingArg = null;
13633
- var camera = (_b = _this.composition) === null || _b === void 0 ? void 0 : _b.camera;
13655
+ var camera = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.camera;
13634
13656
  dragEvent = {
13635
13657
  x: event.x,
13636
13658
  y: event.y,
@@ -13645,8 +13667,7 @@ var InteractVFXItem = /** @class */ (function (_super) {
13645
13667
  _this.bouncingArg = event;
13646
13668
  },
13647
13669
  touchend: function (event) {
13648
- var _a;
13649
- if (!((_a = _this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
13670
+ if (!_this.canInteract()) {
13650
13671
  return;
13651
13672
  }
13652
13673
  var bouncingArg = _this.bouncingArg;
@@ -13673,36 +13694,40 @@ var InteractVFXItem = /** @class */ (function (_super) {
13673
13694
  // OVERRIDE
13674
13695
  };
13675
13696
  InteractVFXItem.prototype.handleDragMove = function (evt, event) {
13676
- var _a, _b, _c;
13677
- if (!(evt && evt.cameraParam) || !((_a = this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
13697
+ var _a, _b;
13698
+ if (!(evt === null || evt === void 0 ? void 0 : evt.cameraParam) || !this.canInteract() || !this.composition) {
13678
13699
  return;
13679
13700
  }
13680
13701
  var options = this.ui.options;
13681
- var _d = evt.cameraParam, position = _d.position, fov = _d.fov;
13702
+ var _c = evt.cameraParam, position = _c.position, fov = _c.fov;
13682
13703
  var dy = event.dy;
13683
13704
  var dx = event.dx * event.width / event.height;
13684
13705
  var depth = position[2];
13685
13706
  var sp = Math.tan(fov * Math.PI / 180 / 2) * Math.abs(depth);
13686
13707
  var height = dy * sp;
13687
13708
  var width = dx * sp;
13688
- var nx = position[0] - width;
13689
- var ny = position[1] - height;
13709
+ var nx = position[0] - this.dragRatio[0] * width;
13710
+ var ny = position[1] - this.dragRatio[1] * height;
13690
13711
  if (options.dxRange) {
13691
- var _e = __read$3(options.dxRange, 2), min = _e[0], max = _e[1];
13712
+ var _d = __read$3(options.dxRange, 2), min = _d[0], max = _d[1];
13692
13713
  nx = clamp$1(nx, min, max);
13693
13714
  if (nx !== min && nx !== max && min !== max) {
13694
- (_b = event.origin) === null || _b === void 0 ? void 0 : _b.preventDefault();
13715
+ (_a = event.origin) === null || _a === void 0 ? void 0 : _a.preventDefault();
13695
13716
  }
13696
13717
  }
13697
13718
  if (options.dyRange) {
13698
- var _f = __read$3(options.dyRange, 2), min = _f[0], max = _f[1];
13719
+ var _e = __read$3(options.dyRange, 2), min = _e[0], max = _e[1];
13699
13720
  ny = clamp$1(ny, min, max);
13700
13721
  if (ny !== min && ny !== max && min !== max) {
13701
- (_c = event.origin) === null || _c === void 0 ? void 0 : _c.preventDefault();
13722
+ (_b = event.origin) === null || _b === void 0 ? void 0 : _b.preventDefault();
13702
13723
  }
13703
13724
  }
13704
13725
  this.composition.camera.position = new Vector3(nx, ny, depth);
13705
13726
  };
13727
+ InteractVFXItem.prototype.canInteract = function () {
13728
+ var _a;
13729
+ return Boolean((_a = this.composition) === null || _a === void 0 ? void 0 : _a.interactive) && this.enabled;
13730
+ };
13706
13731
  return InteractVFXItem;
13707
13732
  }(VFXItem));
13708
13733
  function shouldIgnoreBouncing(arg, mul) {
@@ -24008,27 +24033,28 @@ var AssetManager = /** @class */ (function () {
24008
24033
  AssetManager.prototype.loadScene = function (url, renderer, options) {
24009
24034
  var _a, _b, _c;
24010
24035
  return __awaiter(this, void 0, void 0, function () {
24011
- var rawJSON, assetUrl, startTime, timeInfos, gpuInstance, asyncShaderCompile, compressedTexture, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
24036
+ var rawJSON, assetUrl, startTime, timeInfoMessages, gpuInstance, asyncShaderCompile, compressedTexture, timeInfos, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
24012
24037
  var _this = this;
24013
24038
  return __generator(this, function (_d) {
24014
24039
  assetUrl = isString(url) ? url : this.id;
24015
24040
  startTime = performance.now();
24016
- timeInfos = [];
24041
+ timeInfoMessages = [];
24017
24042
  gpuInstance = renderer === null || renderer === void 0 ? void 0 : renderer.engine.gpuCapability;
24018
24043
  asyncShaderCompile = (_b = (_a = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail) === null || _a === void 0 ? void 0 : _a.asyncShaderCompile) !== null && _b !== void 0 ? _b : false;
24019
24044
  compressedTexture = (_c = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail.compressedTexture) !== null && _c !== void 0 ? _c : 0;
24045
+ timeInfos = {};
24020
24046
  cancelLoading = false;
24021
24047
  waitPromise = new Promise(function (resolve, reject) {
24022
24048
  loadTimer = window.setTimeout(function () {
24023
24049
  cancelLoading = true;
24024
24050
  _this.removeTimer(loadTimer);
24025
24051
  var totalTime = performance.now() - startTime;
24026
- reject("Load time out: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfos.join(' '), ", url: ").concat(assetUrl));
24052
+ reject("Load time out: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfoMessages.join(' '), ", url: ").concat(assetUrl));
24027
24053
  }, _this.timeout * 1000);
24028
24054
  _this.timers.push(loadTimer);
24029
24055
  });
24030
24056
  hookTimeInfo = function (label, func) { return __awaiter(_this, void 0, void 0, function () {
24031
- var st, result, e_1;
24057
+ var st, result, time, e_1;
24032
24058
  return __generator(this, function (_a) {
24033
24059
  switch (_a.label) {
24034
24060
  case 0:
@@ -24040,7 +24066,9 @@ var AssetManager = /** @class */ (function () {
24040
24066
  return [4 /*yield*/, func()];
24041
24067
  case 2:
24042
24068
  result = _a.sent();
24043
- timeInfos.push("[".concat(label, ": ").concat((performance.now() - st).toFixed(2), "]"));
24069
+ time = performance.now() - st;
24070
+ timeInfoMessages.push("[".concat(label, ": ").concat(time.toFixed(2), "]"));
24071
+ timeInfos[label] = time;
24044
24072
  return [2 /*return*/, result];
24045
24073
  case 3:
24046
24074
  e_1 = _a.sent();
@@ -24099,7 +24127,7 @@ var AssetManager = /** @class */ (function () {
24099
24127
  return [4 /*yield*/, Promise.all([
24100
24128
  hookTimeInfo('processBins', function () { return _this.processBins(bins_1); }),
24101
24129
  hookTimeInfo('processImages', function () { return _this.processImages(images_2, usedImages_1, compressedTexture); }),
24102
- hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', " compile"), function () { return _this.precompile(compositions_1, pluginSystem_1, renderer, options); }),
24130
+ hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', "Compile"), function () { return _this.precompile(compositions_1, pluginSystem_1, renderer, options); }),
24103
24131
  ])];
24104
24132
  case 8:
24105
24133
  _d = __read$3.apply(void 0, [_e.sent(), 2]), loadedBins_1 = _d[0], loadedImages_1 = _d[1];
@@ -24111,6 +24139,7 @@ var AssetManager = /** @class */ (function () {
24111
24139
  loadedTextures = _e.sent();
24112
24140
  jsonScene_1.compositions = this.updateSceneData(jsonScene_1.compositions);
24113
24141
  scene = {
24142
+ timeInfos: timeInfos,
24114
24143
  url: url,
24115
24144
  renderLevel: this.options.renderLevel,
24116
24145
  storage: {},
@@ -24129,11 +24158,13 @@ var AssetManager = /** @class */ (function () {
24129
24158
  _e.label = 12;
24130
24159
  case 12:
24131
24160
  totalTime = performance.now() - startTime;
24132
- logger.info("Load asset: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfos.join(' '), ", url: ").concat(assetUrl));
24161
+ logger.info("Load asset: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfoMessages.join(' '), ", url: ").concat(assetUrl));
24133
24162
  window.clearTimeout(loadTimer);
24134
24163
  this.removeTimer(loadTimer);
24135
24164
  scene.totalTime = totalTime;
24136
24165
  scene.startTime = startTime;
24166
+ // 各部分分段时长
24167
+ scene.timeInfos = timeInfos;
24137
24168
  return [2 /*return*/, scene];
24138
24169
  }
24139
24170
  });
@@ -24981,7 +25012,7 @@ var Composition = /** @class */ (function () {
24981
25012
  * @param props - composition 的创建参数
24982
25013
  */
24983
25014
  function Composition(props, scene) {
24984
- var _a;
25015
+ var _a, _b;
24985
25016
  /**
24986
25017
  * 动画播放速度
24987
25018
  */
@@ -25010,7 +25041,7 @@ var Composition = /** @class */ (function () {
25010
25041
  this.paused = false;
25011
25042
  this.lastVideoUpdateTime = 0;
25012
25043
  this.postLoaders = [];
25013
- var _b = props.reusable, reusable = _b === void 0 ? false : _b, _c = props.speed, speed = _c === void 0 ? 1 : _c, _d = props.baseRenderOrder, baseRenderOrder = _d === void 0 ? 0 : _d, renderer = props.renderer, onPlayerPause = props.onPlayerPause, onMessageItem = props.onMessageItem, onEnd = props.onEnd, event = props.event, width = props.width, height = props.height;
25044
+ var _c = props.reusable, reusable = _c === void 0 ? false : _c, _d = props.speed, speed = _d === void 0 ? 1 : _d, _e = props.baseRenderOrder, baseRenderOrder = _e === void 0 ? 0 : _e, renderer = props.renderer, onPlayerPause = props.onPlayerPause, onMessageItem = props.onMessageItem, onEnd = props.onEnd, event = props.event, width = props.width, height = props.height;
25014
25045
  this.compositionSourceManager = new CompositionSourceManager(scene, renderer.engine);
25015
25046
  scene.jsonScene.imgUsage = undefined;
25016
25047
  if (reusable) {
@@ -25018,7 +25049,7 @@ var Composition = /** @class */ (function () {
25018
25049
  scene.textures = undefined;
25019
25050
  scene.consumed = true;
25020
25051
  }
25021
- var _e = this.compositionSourceManager, sourceContent = _e.sourceContent, pluginSystem = _e.pluginSystem, imgUsage = _e.imgUsage, totalTime = _e.totalTime, renderLevel = _e.renderLevel, refCompositionProps = _e.refCompositionProps;
25052
+ var _f = this.compositionSourceManager, sourceContent = _f.sourceContent, pluginSystem = _f.pluginSystem, imgUsage = _f.imgUsage, totalTime = _f.totalTime, renderLevel = _f.renderLevel, refCompositionProps = _f.refCompositionProps;
25022
25053
  assertExist(sourceContent);
25023
25054
  this.refCompositionProps = refCompositionProps;
25024
25055
  var vfxItem = new CompVFXItem(sourceContent, this);
@@ -25035,7 +25066,7 @@ var Composition = /** @class */ (function () {
25035
25066
  this.renderer = renderer;
25036
25067
  this.texInfo = imageUsage !== null && imageUsage !== void 0 ? imageUsage : {};
25037
25068
  this.event = event;
25038
- this.statistic = { loadTime: totalTime !== null && totalTime !== void 0 ? totalTime : 0, loadStart: (_a = scene.startTime) !== null && _a !== void 0 ? _a : 0, firstFrameTime: 0 };
25069
+ this.statistic = { loadTime: totalTime !== null && totalTime !== void 0 ? totalTime : 0, loadStart: (_a = scene.startTime) !== null && _a !== void 0 ? _a : 0, firstFrameTime: 0, precompileTime: (_b = scene.timeInfos['asyncCompile']) !== null && _b !== void 0 ? _b : scene.timeInfos['syncCompile'] };
25039
25070
  this.reusable = reusable;
25040
25071
  this.speed = speed;
25041
25072
  this.renderLevel = renderLevel;