@galacean/effects-threejs 1.6.0-beta.0 → 1.6.0-beta.2

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.6.0-beta.0
6
+ * Version: v1.6.0-beta.2
7
7
  */
8
8
 
9
9
  'use strict';
@@ -13542,6 +13542,14 @@ var InteractVFXItem = /** @class */ (function (_super) {
13542
13542
  function InteractVFXItem(props, composition) {
13543
13543
  var _a;
13544
13544
  var _this = _super.call(this, props, composition) || this;
13545
+ /**
13546
+ * 拖拽的惯性衰减系数,范围[0, 1], 越大惯性越强
13547
+ */
13548
+ _this.downgrade = 0.95;
13549
+ /**
13550
+ * 拖拽的距离映射系数,越大越容易拖动
13551
+ */
13552
+ _this.dragRatio = [1, 1];
13545
13553
  _this.engine = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.getEngine();
13546
13554
  return _this;
13547
13555
  }
@@ -13552,8 +13560,23 @@ var InteractVFXItem = /** @class */ (function (_super) {
13552
13560
  enumerable: false,
13553
13561
  configurable: true
13554
13562
  });
13563
+ Object.defineProperty(InteractVFXItem.prototype, "enable", {
13564
+ get: function () {
13565
+ return this.enabled;
13566
+ },
13567
+ set: function (enable) {
13568
+ this.enabled = enable;
13569
+ if (!enable) {
13570
+ // 立刻停止惯性滑动
13571
+ this.bouncingArg = null;
13572
+ }
13573
+ },
13574
+ enumerable: false,
13575
+ configurable: true
13576
+ });
13555
13577
  InteractVFXItem.prototype.onConstructed = function (options) {
13556
13578
  this.ui = options.content;
13579
+ this.enabled = true;
13557
13580
  };
13558
13581
  InteractVFXItem.prototype.onLifetimeBegin = function (composition) {
13559
13582
  var _a, _b, _c;
@@ -13572,9 +13595,8 @@ var InteractVFXItem = /** @class */ (function (_super) {
13572
13595
  if (!this.dragEvent || !this.bouncingArg) {
13573
13596
  return;
13574
13597
  }
13575
- var downgrade = 0.95;
13576
- this.bouncingArg.vx *= downgrade;
13577
- this.bouncingArg.vy *= downgrade;
13598
+ this.bouncingArg.vx *= this.downgrade;
13599
+ this.bouncingArg.vy *= this.downgrade;
13578
13600
  this.bouncingArg.dy += this.bouncingArg.vy;
13579
13601
  this.bouncingArg.dx += this.bouncingArg.vx;
13580
13602
  if (shouldIgnoreBouncing(this.bouncingArg)) {
@@ -13610,7 +13632,7 @@ var InteractVFXItem = /** @class */ (function (_super) {
13610
13632
  };
13611
13633
  };
13612
13634
  InteractVFXItem.prototype.getHitTestParams = function () {
13613
- if (!this.clickable) {
13635
+ if (!this.clickable || !this.canInteract()) {
13614
13636
  return;
13615
13637
  }
13616
13638
  var behavior = this.ui.options.behavior;
@@ -13646,13 +13668,13 @@ var InteractVFXItem = /** @class */ (function (_super) {
13646
13668
  var dragEvent;
13647
13669
  var handlerMap = {
13648
13670
  touchstart: function (event) {
13649
- var _a, _b;
13650
- if (!((_a = _this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
13671
+ var _a;
13672
+ if (!_this.canInteract()) {
13651
13673
  return;
13652
13674
  }
13653
13675
  _this.dragEvent = null;
13654
13676
  _this.bouncingArg = null;
13655
- var camera = (_b = _this.composition) === null || _b === void 0 ? void 0 : _b.camera;
13677
+ var camera = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.camera;
13656
13678
  dragEvent = {
13657
13679
  x: event.x,
13658
13680
  y: event.y,
@@ -13667,8 +13689,7 @@ var InteractVFXItem = /** @class */ (function (_super) {
13667
13689
  _this.bouncingArg = event;
13668
13690
  },
13669
13691
  touchend: function (event) {
13670
- var _a;
13671
- if (!((_a = _this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
13692
+ if (!_this.canInteract()) {
13672
13693
  return;
13673
13694
  }
13674
13695
  var bouncingArg = _this.bouncingArg;
@@ -13695,36 +13716,40 @@ var InteractVFXItem = /** @class */ (function (_super) {
13695
13716
  // OVERRIDE
13696
13717
  };
13697
13718
  InteractVFXItem.prototype.handleDragMove = function (evt, event) {
13698
- var _a, _b, _c;
13699
- if (!(evt && evt.cameraParam) || !((_a = this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
13719
+ var _a, _b;
13720
+ if (!(evt === null || evt === void 0 ? void 0 : evt.cameraParam) || !this.canInteract() || !this.composition) {
13700
13721
  return;
13701
13722
  }
13702
13723
  var options = this.ui.options;
13703
- var _d = evt.cameraParam, position = _d.position, fov = _d.fov;
13724
+ var _c = evt.cameraParam, position = _c.position, fov = _c.fov;
13704
13725
  var dy = event.dy;
13705
13726
  var dx = event.dx * event.width / event.height;
13706
13727
  var depth = position[2];
13707
13728
  var sp = Math.tan(fov * Math.PI / 180 / 2) * Math.abs(depth);
13708
13729
  var height = dy * sp;
13709
13730
  var width = dx * sp;
13710
- var nx = position[0] - width;
13711
- var ny = position[1] - height;
13731
+ var nx = position[0] - this.dragRatio[0] * width;
13732
+ var ny = position[1] - this.dragRatio[1] * height;
13712
13733
  if (options.dxRange) {
13713
- var _e = __read$3(options.dxRange, 2), min = _e[0], max = _e[1];
13734
+ var _d = __read$3(options.dxRange, 2), min = _d[0], max = _d[1];
13714
13735
  nx = clamp$1(nx, min, max);
13715
13736
  if (nx !== min && nx !== max && min !== max) {
13716
- (_b = event.origin) === null || _b === void 0 ? void 0 : _b.preventDefault();
13737
+ (_a = event.origin) === null || _a === void 0 ? void 0 : _a.preventDefault();
13717
13738
  }
13718
13739
  }
13719
13740
  if (options.dyRange) {
13720
- var _f = __read$3(options.dyRange, 2), min = _f[0], max = _f[1];
13741
+ var _e = __read$3(options.dyRange, 2), min = _e[0], max = _e[1];
13721
13742
  ny = clamp$1(ny, min, max);
13722
13743
  if (ny !== min && ny !== max && min !== max) {
13723
- (_c = event.origin) === null || _c === void 0 ? void 0 : _c.preventDefault();
13744
+ (_b = event.origin) === null || _b === void 0 ? void 0 : _b.preventDefault();
13724
13745
  }
13725
13746
  }
13726
13747
  this.composition.camera.position = new Vector3(nx, ny, depth);
13727
13748
  };
13749
+ InteractVFXItem.prototype.canInteract = function () {
13750
+ var _a;
13751
+ return Boolean((_a = this.composition) === null || _a === void 0 ? void 0 : _a.interactive) && this.enabled;
13752
+ };
13728
13753
  return InteractVFXItem;
13729
13754
  }(VFXItem));
13730
13755
  function shouldIgnoreBouncing(arg, mul) {
@@ -20281,32 +20306,37 @@ var TextLayout = /** @class */ (function () {
20281
20306
  this.textAlign = textAlign;
20282
20307
  this.lineHeight = lineHeight;
20283
20308
  }
20284
- TextLayout.prototype.getOffsetY = function (style) {
20285
- var offsetY = 0;
20286
- var offset = (style.fontSize + style.outlineWidth) * style.fontScale;
20309
+ TextLayout.prototype.getOffsetY = function (style, lineCount, lineHeight) {
20310
+ var offsetResult = 0;
20311
+ var fontSize = style.fontSize, outlineWidth = style.outlineWidth, fontScale = style.fontScale;
20312
+ // 计算基础偏移量
20313
+ var baseOffset = (fontSize + outlineWidth) * fontScale;
20314
+ // /3 计算Y轴偏移量,以匹配编辑器行为
20315
+ var offsetY = (lineHeight - fontSize) / 3;
20316
+ var commonCalculation = lineHeight * (lineCount - 1);
20287
20317
  switch (this.textBaseline) {
20288
- case 0:
20289
- offsetY = offset;
20318
+ case TextBaseline$1.top:
20319
+ offsetResult = baseOffset + offsetY;
20290
20320
  break;
20291
- case 1:
20292
- offsetY = (this.height + offset) / 2; // fonSize;
20321
+ case TextBaseline$1.middle:
20322
+ offsetResult = (this.height * fontScale - commonCalculation + baseOffset) / 2;
20293
20323
  break;
20294
- case 2:
20295
- offsetY = this.height - offset / 2;
20324
+ case TextBaseline$1.bottom:
20325
+ offsetResult = (this.height * fontScale - commonCalculation) - offsetY;
20296
20326
  break;
20297
20327
  }
20298
- return offsetY;
20328
+ return offsetResult;
20299
20329
  };
20300
20330
  TextLayout.prototype.getOffsetX = function (style, maxWidth) {
20301
20331
  var offsetX = 0;
20302
20332
  switch (this.textAlign) {
20303
- case 0:
20333
+ case TextAlignment$1.left:
20304
20334
  offsetX = style.outlineWidth * style.fontScale;
20305
20335
  break;
20306
- case 1:
20336
+ case TextAlignment$1.middle:
20307
20337
  offsetX = (this.width * style.fontScale - maxWidth) / 2;
20308
20338
  break;
20309
- case 2:
20339
+ case TextAlignment$1.right:
20310
20340
  offsetX = (this.width * style.fontScale - maxWidth);
20311
20341
  break;
20312
20342
  }
@@ -20540,7 +20570,7 @@ var TextItem = /** @class */ (function (_super) {
20540
20570
  var fontScale = style.fontScale;
20541
20571
  var width = (layout.width + style.fontOffset) * fontScale;
20542
20572
  var height = layout.height * fontScale;
20543
- var fontSize = style.fontSize * fontScale;
20573
+ style.fontSize * fontScale;
20544
20574
  var lineHeight = layout.lineHeight * fontScale;
20545
20575
  this.char = (this.text || '').split('');
20546
20576
  this.canvas.width = width;
@@ -20560,10 +20590,9 @@ var TextItem = /** @class */ (function (_super) {
20560
20590
  // 文本颜色
20561
20591
  context.fillStyle = "rgba(".concat(style.textColor[0], ", ").concat(style.textColor[1], ", ").concat(style.textColor[2], ", ").concat(style.textColor[3], ")");
20562
20592
  var charsInfo = [];
20563
- // /3 为了和编辑器行为保持一致
20564
- var offsetY = (lineHeight - fontSize) / 3;
20565
20593
  var x = 0;
20566
- var y = layout.getOffsetY(style) + offsetY;
20594
+ var lineCount = this.text.split('\n').length;
20595
+ var y = layout.getOffsetY(style, lineCount, lineHeight);
20567
20596
  var charsArray = [];
20568
20597
  var charOffsetX = [];
20569
20598
  for (var i = 0; i < this.char.length; i++) {
@@ -24030,27 +24059,28 @@ var AssetManager = /** @class */ (function () {
24030
24059
  AssetManager.prototype.loadScene = function (url, renderer, options) {
24031
24060
  var _a, _b, _c;
24032
24061
  return __awaiter(this, void 0, void 0, function () {
24033
- var rawJSON, assetUrl, startTime, timeInfos, gpuInstance, asyncShaderCompile, compressedTexture, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
24062
+ var rawJSON, assetUrl, startTime, timeInfoMessages, gpuInstance, asyncShaderCompile, compressedTexture, timeInfos, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
24034
24063
  var _this = this;
24035
24064
  return __generator(this, function (_d) {
24036
24065
  assetUrl = isString(url) ? url : this.id;
24037
24066
  startTime = performance.now();
24038
- timeInfos = [];
24067
+ timeInfoMessages = [];
24039
24068
  gpuInstance = renderer === null || renderer === void 0 ? void 0 : renderer.engine.gpuCapability;
24040
24069
  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;
24041
24070
  compressedTexture = (_c = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail.compressedTexture) !== null && _c !== void 0 ? _c : 0;
24071
+ timeInfos = {};
24042
24072
  cancelLoading = false;
24043
24073
  waitPromise = new Promise(function (resolve, reject) {
24044
24074
  loadTimer = window.setTimeout(function () {
24045
24075
  cancelLoading = true;
24046
24076
  _this.removeTimer(loadTimer);
24047
24077
  var totalTime = performance.now() - startTime;
24048
- reject("Load time out: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfos.join(' '), ", url: ").concat(assetUrl));
24078
+ reject("Load time out: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfoMessages.join(' '), ", url: ").concat(assetUrl));
24049
24079
  }, _this.timeout * 1000);
24050
24080
  _this.timers.push(loadTimer);
24051
24081
  });
24052
24082
  hookTimeInfo = function (label, func) { return __awaiter(_this, void 0, void 0, function () {
24053
- var st, result, e_1;
24083
+ var st, result, time, e_1;
24054
24084
  return __generator(this, function (_a) {
24055
24085
  switch (_a.label) {
24056
24086
  case 0:
@@ -24062,7 +24092,9 @@ var AssetManager = /** @class */ (function () {
24062
24092
  return [4 /*yield*/, func()];
24063
24093
  case 2:
24064
24094
  result = _a.sent();
24065
- timeInfos.push("[".concat(label, ": ").concat((performance.now() - st).toFixed(2), "]"));
24095
+ time = performance.now() - st;
24096
+ timeInfoMessages.push("[".concat(label, ": ").concat(time.toFixed(2), "]"));
24097
+ timeInfos[label] = time;
24066
24098
  return [2 /*return*/, result];
24067
24099
  case 3:
24068
24100
  e_1 = _a.sent();
@@ -24121,7 +24153,7 @@ var AssetManager = /** @class */ (function () {
24121
24153
  return [4 /*yield*/, Promise.all([
24122
24154
  hookTimeInfo('processBins', function () { return _this.processBins(bins_1); }),
24123
24155
  hookTimeInfo('processImages', function () { return _this.processImages(images_2, usedImages_1, compressedTexture); }),
24124
- hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', " compile"), function () { return _this.precompile(compositions_1, pluginSystem_1, renderer, options); }),
24156
+ hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', "Compile"), function () { return _this.precompile(compositions_1, pluginSystem_1, renderer, options); }),
24125
24157
  ])];
24126
24158
  case 8:
24127
24159
  _d = __read$3.apply(void 0, [_e.sent(), 2]), loadedBins_1 = _d[0], loadedImages_1 = _d[1];
@@ -24133,6 +24165,7 @@ var AssetManager = /** @class */ (function () {
24133
24165
  loadedTextures = _e.sent();
24134
24166
  jsonScene_1.compositions = this.updateSceneData(jsonScene_1.compositions);
24135
24167
  scene = {
24168
+ timeInfos: timeInfos,
24136
24169
  url: url,
24137
24170
  renderLevel: this.options.renderLevel,
24138
24171
  storage: {},
@@ -24151,11 +24184,13 @@ var AssetManager = /** @class */ (function () {
24151
24184
  _e.label = 12;
24152
24185
  case 12:
24153
24186
  totalTime = performance.now() - startTime;
24154
- logger.info("Load asset: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfos.join(' '), ", url: ").concat(assetUrl));
24187
+ logger.info("Load asset: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfoMessages.join(' '), ", url: ").concat(assetUrl));
24155
24188
  window.clearTimeout(loadTimer);
24156
24189
  this.removeTimer(loadTimer);
24157
24190
  scene.totalTime = totalTime;
24158
24191
  scene.startTime = startTime;
24192
+ // 各部分分段时长
24193
+ scene.timeInfos = timeInfos;
24159
24194
  return [2 /*return*/, scene];
24160
24195
  }
24161
24196
  });
@@ -25003,7 +25038,7 @@ var Composition = /** @class */ (function () {
25003
25038
  * @param props - composition 的创建参数
25004
25039
  */
25005
25040
  function Composition(props, scene) {
25006
- var _a;
25041
+ var _a, _b;
25007
25042
  /**
25008
25043
  * 动画播放速度
25009
25044
  */
@@ -25032,7 +25067,7 @@ var Composition = /** @class */ (function () {
25032
25067
  this.paused = false;
25033
25068
  this.lastVideoUpdateTime = 0;
25034
25069
  this.postLoaders = [];
25035
- 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;
25070
+ 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;
25036
25071
  this.compositionSourceManager = new CompositionSourceManager(scene, renderer.engine);
25037
25072
  scene.jsonScene.imgUsage = undefined;
25038
25073
  if (reusable) {
@@ -25040,7 +25075,7 @@ var Composition = /** @class */ (function () {
25040
25075
  scene.textures = undefined;
25041
25076
  scene.consumed = true;
25042
25077
  }
25043
- var _e = this.compositionSourceManager, sourceContent = _e.sourceContent, pluginSystem = _e.pluginSystem, imgUsage = _e.imgUsage, totalTime = _e.totalTime, renderLevel = _e.renderLevel, refCompositionProps = _e.refCompositionProps;
25078
+ var _f = this.compositionSourceManager, sourceContent = _f.sourceContent, pluginSystem = _f.pluginSystem, imgUsage = _f.imgUsage, totalTime = _f.totalTime, renderLevel = _f.renderLevel, refCompositionProps = _f.refCompositionProps;
25044
25079
  assertExist(sourceContent);
25045
25080
  this.refCompositionProps = refCompositionProps;
25046
25081
  var vfxItem = new CompVFXItem(sourceContent, this);
@@ -25057,7 +25092,7 @@ var Composition = /** @class */ (function () {
25057
25092
  this.renderer = renderer;
25058
25093
  this.texInfo = imageUsage !== null && imageUsage !== void 0 ? imageUsage : {};
25059
25094
  this.event = event;
25060
- this.statistic = { loadTime: totalTime !== null && totalTime !== void 0 ? totalTime : 0, loadStart: (_a = scene.startTime) !== null && _a !== void 0 ? _a : 0, firstFrameTime: 0 };
25095
+ 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'] };
25061
25096
  this.reusable = reusable;
25062
25097
  this.speed = speed;
25063
25098
  this.renderLevel = renderLevel;
@@ -27447,7 +27482,7 @@ Geometry.create = function (engine, options) {
27447
27482
  Mesh.create = function (engine, props) {
27448
27483
  return new ThreeMesh(engine, props);
27449
27484
  };
27450
- var version = "1.6.0-beta.0";
27485
+ var version = "1.6.0-beta.2";
27451
27486
  logger.info('THREEJS plugin version: ' + version);
27452
27487
 
27453
27488
  exports.AbstractPlugin = AbstractPlugin;