@galacean/effects-core 2.8.2 → 2.8.3
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/components/base-render-component.d.ts +1 -0
- package/dist/index.js +104 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -31
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/text/text-item.d.ts +20 -0
- package/dist/plugins/text/text-layout.d.ts +6 -0
- package/package.json +1 -1
|
@@ -85,6 +85,7 @@ export declare class MaskableGraphic extends RendererComponent implements Maskab
|
|
|
85
85
|
* @since 2.3.0
|
|
86
86
|
*/
|
|
87
87
|
setTexture(input: string): Promise<void>;
|
|
88
|
+
onUpdate(dt: number): void;
|
|
88
89
|
render(renderer: Renderer): void;
|
|
89
90
|
onStart(): void;
|
|
90
91
|
getHitTestParams: (force?: boolean) => HitTestTriangleParams | undefined;
|
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: v2.8.
|
|
6
|
+
* Version: v2.8.3
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -18370,6 +18370,15 @@ exports.PostProcessVolume = __decorate([
|
|
|
18370
18370
|
});
|
|
18371
18371
|
})();
|
|
18372
18372
|
};
|
|
18373
|
+
_proto.onUpdate = function onUpdate(dt) {
|
|
18374
|
+
for(var i = 0; i < this.materials.length; i++){
|
|
18375
|
+
var material = this.materials[i];
|
|
18376
|
+
material.setVector2("_Size", this.transform.size);
|
|
18377
|
+
if (this.renderer.renderMode === RenderMode.BILLBOARD || this.renderer.renderMode === RenderMode.VERTICAL_BILLBOARD || this.renderer.renderMode === RenderMode.HORIZONTAL_BILLBOARD) {
|
|
18378
|
+
material.setVector3("_Scale", this.transform.scale);
|
|
18379
|
+
}
|
|
18380
|
+
}
|
|
18381
|
+
};
|
|
18373
18382
|
_proto.render = function render(renderer) {
|
|
18374
18383
|
if (!this.getVisible()) {
|
|
18375
18384
|
return;
|
|
@@ -18431,12 +18440,7 @@ exports.PostProcessVolume = __decorate([
|
|
|
18431
18440
|
};
|
|
18432
18441
|
_proto.draw = function draw(renderer) {
|
|
18433
18442
|
for(var i = 0; i < this.materials.length; i++){
|
|
18434
|
-
|
|
18435
|
-
material.setVector2("_Size", this.transform.size);
|
|
18436
|
-
if (this.renderer.renderMode === RenderMode.BILLBOARD || this.renderer.renderMode === RenderMode.VERTICAL_BILLBOARD || this.renderer.renderMode === RenderMode.HORIZONTAL_BILLBOARD) {
|
|
18437
|
-
material.setVector3("_Scale", this.transform.scale);
|
|
18438
|
-
}
|
|
18439
|
-
renderer.drawGeometry(this.geometry, this.transform.getWorldMatrix(), material, i);
|
|
18443
|
+
renderer.drawGeometry(this.geometry, this.transform.getWorldMatrix(), this.materials[i], i);
|
|
18440
18444
|
}
|
|
18441
18445
|
};
|
|
18442
18446
|
_proto.fromData = function fromData(data) {
|
|
@@ -25694,6 +25698,7 @@ exports.SpriteComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
25694
25698
|
var _proto = SpriteComponent.prototype;
|
|
25695
25699
|
_proto.onUpdate = function onUpdate(dt) {
|
|
25696
25700
|
var _this = this;
|
|
25701
|
+
MaskableGraphic.prototype.onUpdate.call(this, dt);
|
|
25697
25702
|
var time = this.time;
|
|
25698
25703
|
var duration = this.duration;
|
|
25699
25704
|
var textureAnimation = this.textureSheetAnimation;
|
|
@@ -28687,11 +28692,11 @@ var TextLayout = /*#__PURE__*/ function() {
|
|
|
28687
28692
|
* @param totalLineHeight - 可选的实际总行高,用于替代默认计算
|
|
28688
28693
|
* @returns - 行高偏移值
|
|
28689
28694
|
*/ _proto.getOffsetY = function getOffsetY(style, lineCount, lineHeight, fontSize, totalLineHeight) {
|
|
28690
|
-
var
|
|
28695
|
+
var fontScale = style.fontScale;
|
|
28691
28696
|
// /3 计算Y轴偏移量,以匹配编辑器行为
|
|
28692
28697
|
var offsetY = (lineHeight - fontSize) / 3;
|
|
28693
28698
|
// 计算基础偏移量
|
|
28694
|
-
var baseOffset = fontSize
|
|
28699
|
+
var baseOffset = fontSize;
|
|
28695
28700
|
var commonCalculation = totalLineHeight !== undefined ? totalLineHeight : lineHeight * (lineCount - 1);
|
|
28696
28701
|
var offsetResult = 0;
|
|
28697
28702
|
switch(this.textVerticalAlign){
|
|
@@ -28707,11 +28712,16 @@ var TextLayout = /*#__PURE__*/ function() {
|
|
|
28707
28712
|
}
|
|
28708
28713
|
return offsetResult;
|
|
28709
28714
|
};
|
|
28710
|
-
|
|
28715
|
+
/**
|
|
28716
|
+
* 获取初始的水平偏移值
|
|
28717
|
+
* @param style - 字体基础数据
|
|
28718
|
+
* @param maxWidth - 最大行宽
|
|
28719
|
+
* @returns - 水平偏移值
|
|
28720
|
+
*/ _proto.getOffsetX = function getOffsetX(style, maxWidth) {
|
|
28711
28721
|
var offsetX = 0;
|
|
28712
28722
|
switch(this.textAlign){
|
|
28713
28723
|
case TextAlignment.left:
|
|
28714
|
-
offsetX =
|
|
28724
|
+
offsetX = 0;
|
|
28715
28725
|
break;
|
|
28716
28726
|
case TextAlignment.middle:
|
|
28717
28727
|
offsetX = (this.width * style.fontScale - maxWidth) / 2;
|
|
@@ -28787,7 +28797,8 @@ var TextStyle = /*#__PURE__*/ function() {
|
|
|
28787
28797
|
1
|
|
28788
28798
|
];
|
|
28789
28799
|
this.outlineWidth = 0;
|
|
28790
|
-
|
|
28800
|
+
var _outline_outlineWidth;
|
|
28801
|
+
if (outline && ((_outline_outlineWidth = outline.outlineWidth) != null ? _outline_outlineWidth : 0) > 0) {
|
|
28791
28802
|
this.isOutlined = true;
|
|
28792
28803
|
var _outline_outlineColor;
|
|
28793
28804
|
this.outlineColor = [].concat((_outline_outlineColor = outline.outlineColor) != null ? _outline_outlineColor : [
|
|
@@ -28796,8 +28807,8 @@ var TextStyle = /*#__PURE__*/ function() {
|
|
|
28796
28807
|
1,
|
|
28797
28808
|
1
|
|
28798
28809
|
]);
|
|
28799
|
-
var
|
|
28800
|
-
this.outlineWidth = (
|
|
28810
|
+
var _outline_outlineWidth1;
|
|
28811
|
+
this.outlineWidth = (_outline_outlineWidth1 = outline.outlineWidth) != null ? _outline_outlineWidth1 : 0;
|
|
28801
28812
|
}
|
|
28802
28813
|
// 重置阴影状态
|
|
28803
28814
|
this.hasShadow = false;
|
|
@@ -29058,6 +29069,10 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
29058
29069
|
* 文本行数
|
|
29059
29070
|
*/ _this.lineCount = 0;
|
|
29060
29071
|
/**
|
|
29072
|
+
* 描边/阴影等特效导致的纹理扩容比例 X/Y
|
|
29073
|
+
*/ _this.effectScaleX = 1;
|
|
29074
|
+
_this.effectScaleY = 1;
|
|
29075
|
+
/**
|
|
29061
29076
|
* 每一行文本的最大宽度
|
|
29062
29077
|
*/ _this.maxLineWidth = 0;
|
|
29063
29078
|
/**
|
|
@@ -29119,6 +29134,16 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
29119
29134
|
_proto.onUpdate = function onUpdate(dt) {
|
|
29120
29135
|
MaskableGraphic.prototype.onUpdate.call(this, dt);
|
|
29121
29136
|
this.updateTexture();
|
|
29137
|
+
// 覆盖基类每帧更新 size 行为,应用扩容比例
|
|
29138
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(this.materials), _step; !(_step = _iterator()).done;){
|
|
29139
|
+
var material = _step.value;
|
|
29140
|
+
var sizeX = this.transform.size.x;
|
|
29141
|
+
var sizeY = this.transform.size.y;
|
|
29142
|
+
var _this_getTextureExpandScale = this.getTextureExpandScale(), scalex = _this_getTextureExpandScale[0], scaley = _this_getTextureExpandScale[1];
|
|
29143
|
+
sizeX *= scalex;
|
|
29144
|
+
sizeY *= scaley;
|
|
29145
|
+
material.setVector2("_Size", new Vector2(sizeX, sizeY));
|
|
29146
|
+
}
|
|
29122
29147
|
};
|
|
29123
29148
|
_proto.onDestroy = function onDestroy() {
|
|
29124
29149
|
MaskableGraphic.prototype.onDestroy.call(this);
|
|
@@ -29308,23 +29333,32 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
29308
29333
|
var style = this.textStyle;
|
|
29309
29334
|
var layout = this.textLayout;
|
|
29310
29335
|
var fontScale = style.fontScale;
|
|
29311
|
-
var
|
|
29336
|
+
var baseWidth = (layout.width + style.fontOffset) * fontScale;
|
|
29312
29337
|
var finalHeight = layout.lineHeight * this.lineCount;
|
|
29313
29338
|
var fontSize = style.fontSize * fontScale;
|
|
29314
29339
|
var lineHeight = layout.lineHeight * fontScale;
|
|
29315
29340
|
style.fontDesc = this.getFontDesc(fontSize);
|
|
29316
29341
|
var char = (this.text || "").split("");
|
|
29342
|
+
var baseHeight = 0;
|
|
29317
29343
|
if (layout.autoWidth) {
|
|
29318
|
-
|
|
29344
|
+
baseHeight = finalHeight * fontScale;
|
|
29319
29345
|
this.item.transform.size.set(1, finalHeight / layout.height);
|
|
29320
29346
|
} else {
|
|
29321
|
-
|
|
29322
|
-
}
|
|
29323
|
-
var
|
|
29324
|
-
|
|
29347
|
+
baseHeight = layout.height * fontScale;
|
|
29348
|
+
}
|
|
29349
|
+
var _this_getEffectPadding = this.getEffectPadding(), padL = _this_getEffectPadding.padL, padR = _this_getEffectPadding.padR, padT = _this_getEffectPadding.padT, padB = _this_getEffectPadding.padB;
|
|
29350
|
+
var hasEffect = (padL | padR | padT | padB) !== 0;
|
|
29351
|
+
var texWidth = hasEffect ? Math.ceil(baseWidth + padL + padR) : baseWidth;
|
|
29352
|
+
var texHeight = hasEffect ? Math.ceil(baseHeight + padT + padB) : baseHeight;
|
|
29353
|
+
var shiftX = hasEffect ? padL : 0;
|
|
29354
|
+
var shiftY = hasEffect ? flipY ? padT : padB : 0;
|
|
29355
|
+
// 给渲染层用:扩容比例
|
|
29356
|
+
this.effectScaleX = baseWidth > 0 ? texWidth / baseWidth : 1;
|
|
29357
|
+
this.effectScaleY = baseHeight > 0 ? texHeight / baseHeight : 1;
|
|
29358
|
+
this.renderToTexture(texWidth, texHeight, flipY, function(context) {
|
|
29325
29359
|
// canvas size 变化后重新刷新 context
|
|
29326
|
-
if (_this.maxLineWidth >
|
|
29327
|
-
context.font = _this.getFontDesc(fontSize *
|
|
29360
|
+
if (_this.maxLineWidth > baseWidth && layout.overflow === TextOverflow.display) {
|
|
29361
|
+
context.font = _this.getFontDesc(fontSize * baseWidth / _this.maxLineWidth);
|
|
29328
29362
|
} else {
|
|
29329
29363
|
context.font = style.fontDesc;
|
|
29330
29364
|
}
|
|
@@ -29347,7 +29381,7 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
29347
29381
|
var textMetrics = context.measureText(str);
|
|
29348
29382
|
// 和浏览器行为保持一致
|
|
29349
29383
|
x += layout.letterSpace * fontScale;
|
|
29350
|
-
if (x + textMetrics.width >
|
|
29384
|
+
if (x + textMetrics.width > baseWidth && i > 0 || str === "\n") {
|
|
29351
29385
|
charsInfo.push({
|
|
29352
29386
|
y: y,
|
|
29353
29387
|
width: x,
|
|
@@ -29371,14 +29405,27 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
29371
29405
|
chars: charsArray,
|
|
29372
29406
|
charOffsetX: charOffsetX
|
|
29373
29407
|
});
|
|
29374
|
-
|
|
29375
|
-
|
|
29376
|
-
|
|
29377
|
-
|
|
29378
|
-
|
|
29408
|
+
// 先描边
|
|
29409
|
+
if (style.isOutlined) {
|
|
29410
|
+
charsInfo.forEach(function(charInfo) {
|
|
29411
|
+
var ox = layout.getOffsetX(style, charInfo.width);
|
|
29412
|
+
for(var i = 0; i < charInfo.chars.length; i++){
|
|
29413
|
+
var str = charInfo.chars[i];
|
|
29414
|
+
var drawX = shiftX + ox + charInfo.charOffsetX[i];
|
|
29415
|
+
var drawY = shiftY + charInfo.y;
|
|
29416
|
+
context.strokeText(str, drawX, drawY);
|
|
29379
29417
|
}
|
|
29380
|
-
context.fillText(str, x + charInfo.charOffsetX[i], charInfo.y);
|
|
29381
29418
|
});
|
|
29419
|
+
}
|
|
29420
|
+
// 再填充
|
|
29421
|
+
charsInfo.forEach(function(charInfo) {
|
|
29422
|
+
var ox = layout.getOffsetX(style, charInfo.width);
|
|
29423
|
+
for(var i = 0; i < charInfo.chars.length; i++){
|
|
29424
|
+
var str = charInfo.chars[i];
|
|
29425
|
+
var drawX = shiftX + ox + charInfo.charOffsetX[i];
|
|
29426
|
+
var drawY = shiftY + charInfo.y;
|
|
29427
|
+
context.fillText(str, drawX, drawY);
|
|
29428
|
+
}
|
|
29382
29429
|
});
|
|
29383
29430
|
if (style.hasShadow) {
|
|
29384
29431
|
context.shadowColor = "transparent";
|
|
@@ -29389,6 +29436,32 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
29389
29436
|
_proto.renderText = function renderText(options) {
|
|
29390
29437
|
this.updateTexture();
|
|
29391
29438
|
};
|
|
29439
|
+
/**
|
|
29440
|
+
* 给渲染层用:获取特效扩容比例(描边/阴影导致的纹理扩容)
|
|
29441
|
+
* @returns
|
|
29442
|
+
*/ _proto.getTextureExpandScale = function getTextureExpandScale() {
|
|
29443
|
+
return [
|
|
29444
|
+
this.effectScaleX,
|
|
29445
|
+
this.effectScaleY
|
|
29446
|
+
];
|
|
29447
|
+
};
|
|
29448
|
+
/**
|
|
29449
|
+
* 获取描边和阴影的 padding 值(单位:px)
|
|
29450
|
+
* @returns
|
|
29451
|
+
*/ _proto.getEffectPadding = function getEffectPadding() {
|
|
29452
|
+
var style = this.textStyle;
|
|
29453
|
+
var hasDrawOutline = style.isOutlined && style.outlineWidth > 0;
|
|
29454
|
+
var outlinePad = hasDrawOutline ? Math.ceil(style.outlineWidth * 2 * style.fontScale) : 0;
|
|
29455
|
+
var hasShadow = style.hasShadow && (style.shadowBlur > 0 || style.shadowOffsetX !== 0 || style.shadowOffsetY !== 0);
|
|
29456
|
+
var shadowPad = hasShadow ? Math.ceil((Math.abs(style.shadowOffsetX) + Math.abs(style.shadowOffsetY) + style.shadowBlur) * style.fontScale) : 0;
|
|
29457
|
+
var pad = outlinePad + shadowPad;
|
|
29458
|
+
return {
|
|
29459
|
+
padL: pad,
|
|
29460
|
+
padR: pad,
|
|
29461
|
+
padT: pad,
|
|
29462
|
+
padB: pad
|
|
29463
|
+
};
|
|
29464
|
+
};
|
|
29392
29465
|
_proto.setAutoWidth = function setAutoWidth(value) {
|
|
29393
29466
|
var layout = this.textLayout;
|
|
29394
29467
|
var normalizedValue = !!value;
|
|
@@ -31537,7 +31610,7 @@ function getStandardSpriteContent(sprite, transform) {
|
|
|
31537
31610
|
return ret;
|
|
31538
31611
|
}
|
|
31539
31612
|
|
|
31540
|
-
var version$1 = "2.8.
|
|
31613
|
+
var version$1 = "2.8.3";
|
|
31541
31614
|
var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
|
|
31542
31615
|
var standardVersion = /^(\d+)\.(\d+)$/;
|
|
31543
31616
|
var reverseParticle = false;
|
|
@@ -35237,7 +35310,7 @@ registerPlugin("text", TextLoader);
|
|
|
35237
35310
|
registerPlugin("sprite", SpriteLoader);
|
|
35238
35311
|
registerPlugin("particle", ParticleLoader);
|
|
35239
35312
|
registerPlugin("interact", InteractLoader);
|
|
35240
|
-
var version = "2.8.
|
|
35313
|
+
var version = "2.8.3";
|
|
35241
35314
|
logger.info("Core version: " + version + ".");
|
|
35242
35315
|
|
|
35243
35316
|
exports.ActivationMixerPlayable = ActivationMixerPlayable;
|