@galacean/effects-threejs 1.6.0-beta.2 → 1.6.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.
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.2
6
+ * Version: v1.6.1
7
7
  */
8
8
 
9
9
  'use strict';
@@ -20306,13 +20306,21 @@ var TextLayout = /** @class */ (function () {
20306
20306
  this.textAlign = textAlign;
20307
20307
  this.lineHeight = lineHeight;
20308
20308
  }
20309
- TextLayout.prototype.getOffsetY = function (style, lineCount, lineHeight) {
20309
+ /**
20310
+ * 获取初始的行高偏移值
20311
+ * @param style - 字体基础数据
20312
+ * @param lineCount - 渲染行数
20313
+ * @param lineHeight - 渲染时的字体行高
20314
+ * @param fontSize - 渲染时的字体大小
20315
+ * @returns - 行高偏移值
20316
+ */
20317
+ TextLayout.prototype.getOffsetY = function (style, lineCount, lineHeight, fontSize) {
20310
20318
  var offsetResult = 0;
20311
- var fontSize = style.fontSize, outlineWidth = style.outlineWidth, fontScale = style.fontScale;
20312
- // 计算基础偏移量
20313
- var baseOffset = (fontSize + outlineWidth) * fontScale;
20319
+ var outlineWidth = style.outlineWidth, fontScale = style.fontScale;
20314
20320
  // /3 计算Y轴偏移量,以匹配编辑器行为
20315
20321
  var offsetY = (lineHeight - fontSize) / 3;
20322
+ // 计算基础偏移量
20323
+ var baseOffset = fontSize + outlineWidth * fontScale;
20316
20324
  var commonCalculation = lineHeight * (lineCount - 1);
20317
20325
  switch (this.textBaseline) {
20318
20326
  case TextBaseline$1.top:
@@ -20359,6 +20367,10 @@ var TextItem = /** @class */ (function (_super) {
20359
20367
  function TextItem(props, opts, vfxItem) {
20360
20368
  var _this = _super.call(this, props, opts, vfxItem) || this;
20361
20369
  _this.isDirty = true;
20370
+ /**
20371
+ * 文本行数
20372
+ */
20373
+ _this.lineCount = 0;
20362
20374
  var options = props.options;
20363
20375
  _this.canvas = canvasPool.getCanvas();
20364
20376
  canvasPool.saveCanvas(_this.canvas);
@@ -20367,10 +20379,34 @@ var TextItem = /** @class */ (function (_super) {
20367
20379
  _this.textStyle = new TextStyle(options);
20368
20380
  _this.textLayout = new TextLayout(options);
20369
20381
  _this.text = options.text;
20382
+ _this.lineCount = _this.getLineCount(options.text, true);
20370
20383
  // Text
20371
20384
  _this.mesh = new TextMesh(_this.engine, _this.renderInfo, vfxItem.composition);
20372
20385
  return _this;
20373
20386
  }
20387
+ TextItem.prototype.getLineCount = function (text, init) {
20388
+ var _a, _b;
20389
+ var context = this.context;
20390
+ var letterSpace = this.textLayout.letterSpace;
20391
+ var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
20392
+ var width = (this.textLayout.width + this.textStyle.fontOffset);
20393
+ var lineCount = 1;
20394
+ var x = 0;
20395
+ for (var i = 0; i < text.length; i++) {
20396
+ var str = text[i];
20397
+ var textMetrics = ((_b = (_a = context === null || context === void 0 ? void 0 : context.measureText(str)) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0) * fontScale;
20398
+ // 和浏览器行为保持一致
20399
+ x += letterSpace;
20400
+ if (((x + textMetrics) > width && i > 0) || str === '\n') {
20401
+ lineCount++;
20402
+ x = 0;
20403
+ }
20404
+ if (str !== '\n') {
20405
+ x += textMetrics;
20406
+ }
20407
+ }
20408
+ return lineCount;
20409
+ };
20374
20410
  /**
20375
20411
  * 设置字号大小
20376
20412
  * @param value - 字号
@@ -20420,6 +20456,7 @@ var TextItem = /** @class */ (function (_super) {
20420
20456
  return;
20421
20457
  }
20422
20458
  this.text = value;
20459
+ this.lineCount = this.getLineCount(value, false);
20423
20460
  this.isDirty = true;
20424
20461
  };
20425
20462
  /**
@@ -20570,7 +20607,7 @@ var TextItem = /** @class */ (function (_super) {
20570
20607
  var fontScale = style.fontScale;
20571
20608
  var width = (layout.width + style.fontOffset) * fontScale;
20572
20609
  var height = layout.height * fontScale;
20573
- style.fontSize * fontScale;
20610
+ var fontSize = style.fontSize * fontScale;
20574
20611
  var lineHeight = layout.lineHeight * fontScale;
20575
20612
  this.char = (this.text || '').split('');
20576
20613
  this.canvas.width = width;
@@ -20591,8 +20628,7 @@ var TextItem = /** @class */ (function (_super) {
20591
20628
  context.fillStyle = "rgba(".concat(style.textColor[0], ", ").concat(style.textColor[1], ", ").concat(style.textColor[2], ", ").concat(style.textColor[3], ")");
20592
20629
  var charsInfo = [];
20593
20630
  var x = 0;
20594
- var lineCount = this.text.split('\n').length;
20595
- var y = layout.getOffsetY(style, lineCount, lineHeight);
20631
+ var y = layout.getOffsetY(style, this.lineCount, lineHeight, fontSize);
20596
20632
  var charsArray = [];
20597
20633
  var charOffsetX = [];
20598
20634
  for (var i = 0; i < this.char.length; i++) {
@@ -27482,7 +27518,7 @@ Geometry.create = function (engine, options) {
27482
27518
  Mesh.create = function (engine, props) {
27483
27519
  return new ThreeMesh(engine, props);
27484
27520
  };
27485
- var version = "1.6.0-beta.2";
27521
+ var version = "1.6.1";
27486
27522
  logger.info('THREEJS plugin version: ' + version);
27487
27523
 
27488
27524
  exports.AbstractPlugin = AbstractPlugin;