@galacean/effects-threejs 2.8.2 → 2.8.4

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: v2.8.2
6
+ * Version: v2.8.4
7
7
  */
8
8
 
9
9
  'use strict';
@@ -2687,6 +2687,11 @@ function asserts(condition, msg) {
2687
2687
  * @returns
2688
2688
  */ function isValidFontFamily(fontFamily) {
2689
2689
  // iOS 11/12 不支持自定义字体开头为数字的名称,特殊字符也有风险
2690
+ return isSafeFontFamily(fontFamily) || !isSimulatorCellPhone();
2691
+ }
2692
+ /**
2693
+ * @internal
2694
+ */ function isSafeFontFamily(fontFamily) {
2690
2695
  return /^[^\d.][\w-]*$/.test(fontFamily);
2691
2696
  }
2692
2697
 
@@ -18392,6 +18397,15 @@ exports.PostProcessVolume = __decorate([
18392
18397
  });
18393
18398
  })();
18394
18399
  };
18400
+ _proto.onUpdate = function onUpdate(dt) {
18401
+ for(var i = 0; i < this.materials.length; i++){
18402
+ var material = this.materials[i];
18403
+ material.setVector2("_Size", this.transform.size);
18404
+ if (this.renderer.renderMode === RenderMode.BILLBOARD || this.renderer.renderMode === RenderMode.VERTICAL_BILLBOARD || this.renderer.renderMode === RenderMode.HORIZONTAL_BILLBOARD) {
18405
+ material.setVector3("_Scale", this.transform.scale);
18406
+ }
18407
+ }
18408
+ };
18395
18409
  _proto.render = function render(renderer) {
18396
18410
  if (!this.getVisible()) {
18397
18411
  return;
@@ -18453,12 +18467,7 @@ exports.PostProcessVolume = __decorate([
18453
18467
  };
18454
18468
  _proto.draw = function draw(renderer) {
18455
18469
  for(var i = 0; i < this.materials.length; i++){
18456
- var material = this.materials[i];
18457
- material.setVector2("_Size", this.transform.size);
18458
- if (this.renderer.renderMode === RenderMode.BILLBOARD || this.renderer.renderMode === RenderMode.VERTICAL_BILLBOARD || this.renderer.renderMode === RenderMode.HORIZONTAL_BILLBOARD) {
18459
- material.setVector3("_Scale", this.transform.scale);
18460
- }
18461
- renderer.drawGeometry(this.geometry, this.transform.getWorldMatrix(), material, i);
18470
+ renderer.drawGeometry(this.geometry, this.transform.getWorldMatrix(), this.materials[i], i);
18462
18471
  }
18463
18472
  };
18464
18473
  _proto.fromData = function fromData(data) {
@@ -25716,6 +25725,7 @@ exports.SpriteComponent = /*#__PURE__*/ function(MaskableGraphic) {
25716
25725
  var _proto = SpriteComponent.prototype;
25717
25726
  _proto.onUpdate = function onUpdate(dt) {
25718
25727
  var _this = this;
25728
+ MaskableGraphic.prototype.onUpdate.call(this, dt);
25719
25729
  var time = this.time;
25720
25730
  var duration = this.duration;
25721
25731
  var textureAnimation = this.textureSheetAnimation;
@@ -28709,11 +28719,11 @@ var TextLayout = /*#__PURE__*/ function() {
28709
28719
  * @param totalLineHeight - 可选的实际总行高,用于替代默认计算
28710
28720
  * @returns - 行高偏移值
28711
28721
  */ _proto.getOffsetY = function getOffsetY(style, lineCount, lineHeight, fontSize, totalLineHeight) {
28712
- var outlineWidth = style.outlineWidth, fontScale = style.fontScale;
28722
+ var fontScale = style.fontScale;
28713
28723
  // /3 计算Y轴偏移量,以匹配编辑器行为
28714
28724
  var offsetY = (lineHeight - fontSize) / 3;
28715
28725
  // 计算基础偏移量
28716
- var baseOffset = fontSize + outlineWidth * fontScale;
28726
+ var baseOffset = fontSize;
28717
28727
  var commonCalculation = totalLineHeight !== undefined ? totalLineHeight : lineHeight * (lineCount - 1);
28718
28728
  var offsetResult = 0;
28719
28729
  switch(this.textVerticalAlign){
@@ -28729,11 +28739,16 @@ var TextLayout = /*#__PURE__*/ function() {
28729
28739
  }
28730
28740
  return offsetResult;
28731
28741
  };
28732
- _proto.getOffsetX = function getOffsetX(style, maxWidth) {
28742
+ /**
28743
+ * 获取初始的水平偏移值
28744
+ * @param style - 字体基础数据
28745
+ * @param maxWidth - 最大行宽
28746
+ * @returns - 水平偏移值
28747
+ */ _proto.getOffsetX = function getOffsetX(style, maxWidth) {
28733
28748
  var offsetX = 0;
28734
28749
  switch(this.textAlign){
28735
28750
  case TextAlignment.left:
28736
- offsetX = style.outlineWidth * style.fontScale;
28751
+ offsetX = 0;
28737
28752
  break;
28738
28753
  case TextAlignment.middle:
28739
28754
  offsetX = (this.width * style.fontScale - maxWidth) / 2;
@@ -28809,7 +28824,8 @@ var TextStyle = /*#__PURE__*/ function() {
28809
28824
  1
28810
28825
  ];
28811
28826
  this.outlineWidth = 0;
28812
- if (outline) {
28827
+ var _outline_outlineWidth;
28828
+ if (outline && ((_outline_outlineWidth = outline.outlineWidth) != null ? _outline_outlineWidth : 0) > 0) {
28813
28829
  this.isOutlined = true;
28814
28830
  var _outline_outlineColor;
28815
28831
  this.outlineColor = [].concat((_outline_outlineColor = outline.outlineColor) != null ? _outline_outlineColor : [
@@ -28818,8 +28834,8 @@ var TextStyle = /*#__PURE__*/ function() {
28818
28834
  1,
28819
28835
  1
28820
28836
  ]);
28821
- var _outline_outlineWidth;
28822
- this.outlineWidth = (_outline_outlineWidth = outline.outlineWidth) != null ? _outline_outlineWidth : 1;
28837
+ var _outline_outlineWidth1;
28838
+ this.outlineWidth = (_outline_outlineWidth1 = outline.outlineWidth) != null ? _outline_outlineWidth1 : 0;
28823
28839
  }
28824
28840
  // 重置阴影状态
28825
28841
  this.hasShadow = false;
@@ -29080,6 +29096,10 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29080
29096
  * 文本行数
29081
29097
  */ _this.lineCount = 0;
29082
29098
  /**
29099
+ * 描边/阴影等特效导致的纹理扩容比例 X/Y
29100
+ */ _this.effectScaleX = 1;
29101
+ _this.effectScaleY = 1;
29102
+ /**
29083
29103
  * 每一行文本的最大宽度
29084
29104
  */ _this.maxLineWidth = 0;
29085
29105
  /**
@@ -29141,6 +29161,16 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29141
29161
  _proto.onUpdate = function onUpdate(dt) {
29142
29162
  MaskableGraphic.prototype.onUpdate.call(this, dt);
29143
29163
  this.updateTexture();
29164
+ // 覆盖基类每帧更新 size 行为,应用扩容比例
29165
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.materials), _step; !(_step = _iterator()).done;){
29166
+ var material = _step.value;
29167
+ var sizeX = this.transform.size.x;
29168
+ var sizeY = this.transform.size.y;
29169
+ var _this_getTextureExpandScale = this.getTextureExpandScale(), scalex = _this_getTextureExpandScale[0], scaley = _this_getTextureExpandScale[1];
29170
+ sizeX *= scalex;
29171
+ sizeY *= scaley;
29172
+ material.setVector2("_Size", new Vector2(sizeX, sizeY));
29173
+ }
29144
29174
  };
29145
29175
  _proto.onDestroy = function onDestroy() {
29146
29176
  MaskableGraphic.prototype.onDestroy.call(this);
@@ -29330,23 +29360,32 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29330
29360
  var style = this.textStyle;
29331
29361
  var layout = this.textLayout;
29332
29362
  var fontScale = style.fontScale;
29333
- var width = (layout.width + style.fontOffset) * fontScale;
29363
+ var baseWidth = (layout.width + style.fontOffset) * fontScale;
29334
29364
  var finalHeight = layout.lineHeight * this.lineCount;
29335
29365
  var fontSize = style.fontSize * fontScale;
29336
29366
  var lineHeight = layout.lineHeight * fontScale;
29337
29367
  style.fontDesc = this.getFontDesc(fontSize);
29338
29368
  var char = (this.text || "").split("");
29369
+ var baseHeight = 0;
29339
29370
  if (layout.autoWidth) {
29340
- this.canvas.height = finalHeight * fontScale;
29371
+ baseHeight = finalHeight * fontScale;
29341
29372
  this.item.transform.size.set(1, finalHeight / layout.height);
29342
29373
  } else {
29343
- this.canvas.height = layout.height * fontScale;
29344
- }
29345
- var height = this.canvas.height;
29346
- this.renderToTexture(width, height, flipY, function(context) {
29374
+ baseHeight = layout.height * fontScale;
29375
+ }
29376
+ var _this_getEffectPadding = this.getEffectPadding(), padL = _this_getEffectPadding.padL, padR = _this_getEffectPadding.padR, padT = _this_getEffectPadding.padT, padB = _this_getEffectPadding.padB;
29377
+ var hasEffect = (padL | padR | padT | padB) !== 0;
29378
+ var texWidth = hasEffect ? Math.ceil(baseWidth + padL + padR) : baseWidth;
29379
+ var texHeight = hasEffect ? Math.ceil(baseHeight + padT + padB) : baseHeight;
29380
+ var shiftX = hasEffect ? padL : 0;
29381
+ var shiftY = hasEffect ? flipY ? padT : padB : 0;
29382
+ // 给渲染层用:扩容比例
29383
+ this.effectScaleX = baseWidth > 0 ? texWidth / baseWidth : 1;
29384
+ this.effectScaleY = baseHeight > 0 ? texHeight / baseHeight : 1;
29385
+ this.renderToTexture(texWidth, texHeight, flipY, function(context) {
29347
29386
  // canvas size 变化后重新刷新 context
29348
- if (_this.maxLineWidth > width && layout.overflow === TextOverflow.display) {
29349
- context.font = _this.getFontDesc(fontSize * width / _this.maxLineWidth);
29387
+ if (_this.maxLineWidth > baseWidth && layout.overflow === TextOverflow.display) {
29388
+ context.font = _this.getFontDesc(fontSize * baseWidth / _this.maxLineWidth);
29350
29389
  } else {
29351
29390
  context.font = style.fontDesc;
29352
29391
  }
@@ -29369,7 +29408,7 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29369
29408
  var textMetrics = context.measureText(str);
29370
29409
  // 和浏览器行为保持一致
29371
29410
  x += layout.letterSpace * fontScale;
29372
- if (x + textMetrics.width > width && i > 0 || str === "\n") {
29411
+ if (x + textMetrics.width > baseWidth && i > 0 || str === "\n") {
29373
29412
  charsInfo.push({
29374
29413
  y: y,
29375
29414
  width: x,
@@ -29393,14 +29432,27 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29393
29432
  chars: charsArray,
29394
29433
  charOffsetX: charOffsetX
29395
29434
  });
29396
- charsInfo.forEach(function(charInfo) {
29397
- var x = layout.getOffsetX(style, charInfo.width);
29398
- charInfo.chars.forEach(function(str, i) {
29399
- if (style.isOutlined) {
29400
- context.strokeText(str, x + charInfo.charOffsetX[i], charInfo.y);
29435
+ // 先描边
29436
+ if (style.isOutlined && style.outlineWidth > 0) {
29437
+ charsInfo.forEach(function(charInfo) {
29438
+ var ox = layout.getOffsetX(style, charInfo.width);
29439
+ for(var i = 0; i < charInfo.chars.length; i++){
29440
+ var str = charInfo.chars[i];
29441
+ var drawX = shiftX + ox + charInfo.charOffsetX[i];
29442
+ var drawY = shiftY + charInfo.y;
29443
+ context.strokeText(str, drawX, drawY);
29401
29444
  }
29402
- context.fillText(str, x + charInfo.charOffsetX[i], charInfo.y);
29403
29445
  });
29446
+ }
29447
+ // 再填充
29448
+ charsInfo.forEach(function(charInfo) {
29449
+ var ox = layout.getOffsetX(style, charInfo.width);
29450
+ for(var i = 0; i < charInfo.chars.length; i++){
29451
+ var str = charInfo.chars[i];
29452
+ var drawX = shiftX + ox + charInfo.charOffsetX[i];
29453
+ var drawY = shiftY + charInfo.y;
29454
+ context.fillText(str, drawX, drawY);
29455
+ }
29404
29456
  });
29405
29457
  if (style.hasShadow) {
29406
29458
  context.shadowColor = "transparent";
@@ -29411,6 +29463,32 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29411
29463
  _proto.renderText = function renderText(options) {
29412
29464
  this.updateTexture();
29413
29465
  };
29466
+ /**
29467
+ * 给渲染层用:获取特效扩容比例(描边/阴影导致的纹理扩容)
29468
+ * @returns
29469
+ */ _proto.getTextureExpandScale = function getTextureExpandScale() {
29470
+ return [
29471
+ this.effectScaleX,
29472
+ this.effectScaleY
29473
+ ];
29474
+ };
29475
+ /**
29476
+ * 获取描边和阴影的 padding 值(单位:px)
29477
+ * @returns
29478
+ */ _proto.getEffectPadding = function getEffectPadding() {
29479
+ var style = this.textStyle;
29480
+ var hasDrawOutline = style.isOutlined && style.outlineWidth > 0;
29481
+ var outlinePad = hasDrawOutline ? Math.ceil(style.outlineWidth * 2 * style.fontScale) : 0;
29482
+ var hasShadow = style.hasShadow && (style.shadowBlur > 0 || style.shadowOffsetX !== 0 || style.shadowOffsetY !== 0);
29483
+ var shadowPad = hasShadow ? Math.ceil((Math.abs(style.shadowOffsetX) + Math.abs(style.shadowOffsetY) + style.shadowBlur) * style.fontScale) : 0;
29484
+ var pad = outlinePad + shadowPad;
29485
+ return {
29486
+ padL: pad,
29487
+ padR: pad,
29488
+ padT: pad,
29489
+ padB: pad
29490
+ };
29491
+ };
29414
29492
  _proto.setAutoWidth = function setAutoWidth(value) {
29415
29493
  var layout = this.textLayout;
29416
29494
  var normalizedValue = !!value;
@@ -31559,7 +31637,7 @@ function getStandardSpriteContent(sprite, transform) {
31559
31637
  return ret;
31560
31638
  }
31561
31639
 
31562
- var version$2 = "2.8.2";
31640
+ var version$2 = "2.8.4";
31563
31641
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
31564
31642
  var standardVersion = /^(\d+)\.(\d+)$/;
31565
31643
  var reverseParticle = false;
@@ -35259,7 +35337,7 @@ registerPlugin("text", TextLoader);
35259
35337
  registerPlugin("sprite", SpriteLoader);
35260
35338
  registerPlugin("particle", ParticleLoader);
35261
35339
  registerPlugin("interact", InteractLoader);
35262
- var version$1 = "2.8.2";
35340
+ var version$1 = "2.8.4";
35263
35341
  logger.info("Core version: " + version$1 + ".");
35264
35342
 
35265
35343
  var _obj;
@@ -36836,7 +36914,7 @@ applyMixins(exports.ThreeTextComponent, [
36836
36914
  */ Mesh.create = function(engine, props) {
36837
36915
  return new ThreeMesh(engine, props);
36838
36916
  };
36839
- var version = "2.8.2";
36917
+ var version = "2.8.4";
36840
36918
  logger.info("THREEJS plugin version: " + version + ".");
36841
36919
 
36842
36920
  exports.ActivationMixerPlayable = ActivationMixerPlayable;
@@ -37091,6 +37169,7 @@ exports.isObject = isObject;
37091
37169
  exports.isOpenHarmony = isOpenHarmony;
37092
37170
  exports.isPlainObject = isPlainObject;
37093
37171
  exports.isPowerOfTwo = isPowerOfTwo;
37172
+ exports.isSafeFontFamily = isSafeFontFamily;
37094
37173
  exports.isSimulatorCellPhone = isSimulatorCellPhone;
37095
37174
  exports.isString = isString;
37096
37175
  exports.isUniformStruct = isUniformStruct;