@galacean/effects-threejs 1.6.0-beta.1 → 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 +51 -19
- 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 +51 -19
- 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';
|
|
@@ -20306,32 +20306,37 @@ var TextLayout = /** @class */ (function () {
|
|
|
20306
20306
|
this.textAlign = textAlign;
|
|
20307
20307
|
this.lineHeight = lineHeight;
|
|
20308
20308
|
}
|
|
20309
|
-
TextLayout.prototype.getOffsetY = function (style) {
|
|
20310
|
-
var
|
|
20311
|
-
var
|
|
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);
|
|
20312
20317
|
switch (this.textBaseline) {
|
|
20313
|
-
case
|
|
20314
|
-
|
|
20318
|
+
case TextBaseline$1.top:
|
|
20319
|
+
offsetResult = baseOffset + offsetY;
|
|
20315
20320
|
break;
|
|
20316
|
-
case 1:
|
|
20317
|
-
|
|
20321
|
+
case TextBaseline$1.middle:
|
|
20322
|
+
offsetResult = (this.height * fontScale - commonCalculation + baseOffset) / 2;
|
|
20318
20323
|
break;
|
|
20319
|
-
case
|
|
20320
|
-
|
|
20324
|
+
case TextBaseline$1.bottom:
|
|
20325
|
+
offsetResult = (this.height * fontScale - commonCalculation) - offsetY;
|
|
20321
20326
|
break;
|
|
20322
20327
|
}
|
|
20323
|
-
return
|
|
20328
|
+
return offsetResult;
|
|
20324
20329
|
};
|
|
20325
20330
|
TextLayout.prototype.getOffsetX = function (style, maxWidth) {
|
|
20326
20331
|
var offsetX = 0;
|
|
20327
20332
|
switch (this.textAlign) {
|
|
20328
|
-
case
|
|
20333
|
+
case TextAlignment$1.left:
|
|
20329
20334
|
offsetX = style.outlineWidth * style.fontScale;
|
|
20330
20335
|
break;
|
|
20331
|
-
case 1:
|
|
20336
|
+
case TextAlignment$1.middle:
|
|
20332
20337
|
offsetX = (this.width * style.fontScale - maxWidth) / 2;
|
|
20333
20338
|
break;
|
|
20334
|
-
case
|
|
20339
|
+
case TextAlignment$1.right:
|
|
20335
20340
|
offsetX = (this.width * style.fontScale - maxWidth);
|
|
20336
20341
|
break;
|
|
20337
20342
|
}
|
|
@@ -20354,6 +20359,10 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20354
20359
|
function TextItem(props, opts, vfxItem) {
|
|
20355
20360
|
var _this = _super.call(this, props, opts, vfxItem) || this;
|
|
20356
20361
|
_this.isDirty = true;
|
|
20362
|
+
/**
|
|
20363
|
+
* 文本行数
|
|
20364
|
+
*/
|
|
20365
|
+
_this.lineCount = 0;
|
|
20357
20366
|
var options = props.options;
|
|
20358
20367
|
_this.canvas = canvasPool.getCanvas();
|
|
20359
20368
|
canvasPool.saveCanvas(_this.canvas);
|
|
@@ -20362,10 +20371,34 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20362
20371
|
_this.textStyle = new TextStyle(options);
|
|
20363
20372
|
_this.textLayout = new TextLayout(options);
|
|
20364
20373
|
_this.text = options.text;
|
|
20374
|
+
_this.lineCount = _this.getLineCount(options.text, true);
|
|
20365
20375
|
// Text
|
|
20366
20376
|
_this.mesh = new TextMesh(_this.engine, _this.renderInfo, vfxItem.composition);
|
|
20367
20377
|
return _this;
|
|
20368
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
|
+
};
|
|
20369
20402
|
/**
|
|
20370
20403
|
* 设置字号大小
|
|
20371
20404
|
* @param value - 字号
|
|
@@ -20415,6 +20448,7 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20415
20448
|
return;
|
|
20416
20449
|
}
|
|
20417
20450
|
this.text = value;
|
|
20451
|
+
this.lineCount = this.getLineCount(value, false);
|
|
20418
20452
|
this.isDirty = true;
|
|
20419
20453
|
};
|
|
20420
20454
|
/**
|
|
@@ -20565,7 +20599,7 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20565
20599
|
var fontScale = style.fontScale;
|
|
20566
20600
|
var width = (layout.width + style.fontOffset) * fontScale;
|
|
20567
20601
|
var height = layout.height * fontScale;
|
|
20568
|
-
|
|
20602
|
+
style.fontSize * fontScale;
|
|
20569
20603
|
var lineHeight = layout.lineHeight * fontScale;
|
|
20570
20604
|
this.char = (this.text || '').split('');
|
|
20571
20605
|
this.canvas.width = width;
|
|
@@ -20585,10 +20619,8 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20585
20619
|
// 文本颜色
|
|
20586
20620
|
context.fillStyle = "rgba(".concat(style.textColor[0], ", ").concat(style.textColor[1], ", ").concat(style.textColor[2], ", ").concat(style.textColor[3], ")");
|
|
20587
20621
|
var charsInfo = [];
|
|
20588
|
-
// /3 为了和编辑器行为保持一致
|
|
20589
|
-
var offsetY = (lineHeight - fontSize) / 3;
|
|
20590
20622
|
var x = 0;
|
|
20591
|
-
var y = layout.getOffsetY(style
|
|
20623
|
+
var y = layout.getOffsetY(style, this.lineCount, lineHeight);
|
|
20592
20624
|
var charsArray = [];
|
|
20593
20625
|
var charOffsetX = [];
|
|
20594
20626
|
for (var i = 0; i < this.char.length; i++) {
|
|
@@ -27478,7 +27510,7 @@ Geometry.create = function (engine, options) {
|
|
|
27478
27510
|
Mesh.create = function (engine, props) {
|
|
27479
27511
|
return new ThreeMesh(engine, props);
|
|
27480
27512
|
};
|
|
27481
|
-
var version = "1.6.0
|
|
27513
|
+
var version = "1.6.0";
|
|
27482
27514
|
logger.info('THREEJS plugin version: ' + version);
|
|
27483
27515
|
|
|
27484
27516
|
exports.AbstractPlugin = AbstractPlugin;
|