@galacean/effects-threejs 1.6.0-beta.2 → 1.6.0
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 +32 -4
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +3 -3
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +32 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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
|
|
6
|
+
* Version: v1.6.0
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -20359,6 +20359,10 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20359
20359
|
function TextItem(props, opts, vfxItem) {
|
|
20360
20360
|
var _this = _super.call(this, props, opts, vfxItem) || this;
|
|
20361
20361
|
_this.isDirty = true;
|
|
20362
|
+
/**
|
|
20363
|
+
* 文本行数
|
|
20364
|
+
*/
|
|
20365
|
+
_this.lineCount = 0;
|
|
20362
20366
|
var options = props.options;
|
|
20363
20367
|
_this.canvas = canvasPool.getCanvas();
|
|
20364
20368
|
canvasPool.saveCanvas(_this.canvas);
|
|
@@ -20367,10 +20371,34 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20367
20371
|
_this.textStyle = new TextStyle(options);
|
|
20368
20372
|
_this.textLayout = new TextLayout(options);
|
|
20369
20373
|
_this.text = options.text;
|
|
20374
|
+
_this.lineCount = _this.getLineCount(options.text, true);
|
|
20370
20375
|
// Text
|
|
20371
20376
|
_this.mesh = new TextMesh(_this.engine, _this.renderInfo, vfxItem.composition);
|
|
20372
20377
|
return _this;
|
|
20373
20378
|
}
|
|
20379
|
+
TextItem.prototype.getLineCount = function (text, init) {
|
|
20380
|
+
var _a, _b;
|
|
20381
|
+
var context = this.context;
|
|
20382
|
+
var letterSpace = this.textLayout.letterSpace;
|
|
20383
|
+
var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
|
|
20384
|
+
var width = (this.textLayout.width + this.textStyle.fontOffset);
|
|
20385
|
+
var lineCount = 1;
|
|
20386
|
+
var x = 0;
|
|
20387
|
+
for (var i = 0; i < text.length; i++) {
|
|
20388
|
+
var str = text[i];
|
|
20389
|
+
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;
|
|
20390
|
+
// 和浏览器行为保持一致
|
|
20391
|
+
x += letterSpace;
|
|
20392
|
+
if (((x + textMetrics) > width && i > 0) || str === '\n') {
|
|
20393
|
+
lineCount++;
|
|
20394
|
+
x = 0;
|
|
20395
|
+
}
|
|
20396
|
+
if (str !== '\n') {
|
|
20397
|
+
x += textMetrics;
|
|
20398
|
+
}
|
|
20399
|
+
}
|
|
20400
|
+
return lineCount;
|
|
20401
|
+
};
|
|
20374
20402
|
/**
|
|
20375
20403
|
* 设置字号大小
|
|
20376
20404
|
* @param value - 字号
|
|
@@ -20420,6 +20448,7 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20420
20448
|
return;
|
|
20421
20449
|
}
|
|
20422
20450
|
this.text = value;
|
|
20451
|
+
this.lineCount = this.getLineCount(value, false);
|
|
20423
20452
|
this.isDirty = true;
|
|
20424
20453
|
};
|
|
20425
20454
|
/**
|
|
@@ -20591,8 +20620,7 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20591
20620
|
context.fillStyle = "rgba(".concat(style.textColor[0], ", ").concat(style.textColor[1], ", ").concat(style.textColor[2], ", ").concat(style.textColor[3], ")");
|
|
20592
20621
|
var charsInfo = [];
|
|
20593
20622
|
var x = 0;
|
|
20594
|
-
var
|
|
20595
|
-
var y = layout.getOffsetY(style, lineCount, lineHeight);
|
|
20623
|
+
var y = layout.getOffsetY(style, this.lineCount, lineHeight);
|
|
20596
20624
|
var charsArray = [];
|
|
20597
20625
|
var charOffsetX = [];
|
|
20598
20626
|
for (var i = 0; i < this.char.length; i++) {
|
|
@@ -27482,7 +27510,7 @@ Geometry.create = function (engine, options) {
|
|
|
27482
27510
|
Mesh.create = function (engine, props) {
|
|
27483
27511
|
return new ThreeMesh(engine, props);
|
|
27484
27512
|
};
|
|
27485
|
-
var version = "1.6.0
|
|
27513
|
+
var version = "1.6.0";
|
|
27486
27514
|
logger.info('THREEJS plugin version: ' + version);
|
|
27487
27515
|
|
|
27488
27516
|
exports.AbstractPlugin = AbstractPlugin;
|