@galacean/effects-threejs 2.8.6 → 2.8.8

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.6
6
+ * Version: v2.8.8
7
7
  */
8
8
 
9
9
  'use strict';
@@ -2466,11 +2466,8 @@ function parsePercent$1(c) {
2466
2466
  }
2467
2467
 
2468
2468
  function getPixelRatio() {
2469
- if (typeof screen === "object" && typeof document === "object") {
2470
- var viewportWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
2471
- var screenWidth = screen.width;
2472
- var viewportScale = screenWidth / viewportWidth;
2473
- return Math.min(2 * viewportScale, 2);
2469
+ if (typeof window === "object") {
2470
+ return Math.min(2, window.devicePixelRatio || 1);
2474
2471
  }
2475
2472
  return 1;
2476
2473
  }
@@ -17216,22 +17213,6 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
17216
17213
  this.transform.scaleBy(x, y, z);
17217
17214
  };
17218
17215
  /**
17219
- * 设置元素在画布上的像素位置
17220
- * Tips:
17221
- * - 坐标原点在 canvas 左上角,x 正方向水平向右, y 正方向垂直向下
17222
- * - 设置后会覆盖原有的位置信息
17223
- * @param x - x 坐标
17224
- * @param y - y 坐标
17225
- */ _proto.setPositionByPixel = function setPositionByPixel(x, y) {
17226
- if (this.composition) {
17227
- var z = this.transform.getWorldPosition().z;
17228
- var _this_composition_camera_getInverseVPRatio = this.composition.camera.getInverseVPRatio(z), rx = _this_composition_camera_getInverseVPRatio.x, ry = _this_composition_camera_getInverseVPRatio.y;
17229
- var width = this.composition.renderer.getWidth() / 2;
17230
- var height = this.composition.renderer.getHeight() / 2;
17231
- this.transform.setPosition((2 * x / width - 1) * rx, (1 - 2 * y / height) * ry, z);
17232
- }
17233
- };
17234
- /**
17235
17216
  * 设置本地坐标位置
17236
17217
  */ _proto.setPosition = function setPosition(x, y, z) {
17237
17218
  this.transform.setPosition(x, y, z);
@@ -17255,6 +17236,29 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
17255
17236
  this.transform.setWorldPosition(x, y, z);
17256
17237
  };
17257
17238
  /**
17239
+ * 设置元素在画布上的像素位置
17240
+ * Tips:
17241
+ * - 坐标原点在 canvas 左上角,x 正方向水平向右, y 正方向垂直向下
17242
+ * - 设置后会覆盖原有的位置信息
17243
+ * @param x - x 坐标
17244
+ * @param y - y 坐标
17245
+ */ _proto.setPositionByPixel = function setPositionByPixel(x, y) {
17246
+ if (this.composition) {
17247
+ var z = this.transform.getWorldPosition().z;
17248
+ var _this_composition_camera_getInverseVPRatio = this.composition.camera.getInverseVPRatio(z), rx = _this_composition_camera_getInverseVPRatio.x, ry = _this_composition_camera_getInverseVPRatio.y;
17249
+ var _this_composition_getEngine_canvas_getBoundingClientRect = this.composition.getEngine().canvas.getBoundingClientRect(), width = _this_composition_getEngine_canvas_getBoundingClientRect.width, height = _this_composition_getEngine_canvas_getBoundingClientRect.height;
17250
+ this.transform.setPosition((2 * x / width - 1) * rx, (1 - 2 * y / height) * ry, z);
17251
+ }
17252
+ };
17253
+ _proto.translateByPixel = function translateByPixel(x, y) {
17254
+ if (this.composition) {
17255
+ var _this_composition_getEngine_canvas_getBoundingClientRect = this.composition.getEngine().canvas.getBoundingClientRect(), width = _this_composition_getEngine_canvas_getBoundingClientRect.width, height = _this_composition_getEngine_canvas_getBoundingClientRect.height;
17256
+ var z = this.transform.getWorldPosition().z;
17257
+ var _this_composition_camera_getInverseVPRatio = this.composition.camera.getInverseVPRatio(z), rx = _this_composition_camera_getInverseVPRatio.x, ry = _this_composition_camera_getInverseVPRatio.y;
17258
+ this.transform.translate(2 * x * rx / width, -2 * y * ry / height, 0);
17259
+ }
17260
+ };
17261
+ /**
17258
17262
  * 获取元素包围盒
17259
17263
  * @override
17260
17264
  */ _proto.getBoundingBox = function getBoundingBox() {
@@ -17442,14 +17446,6 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
17442
17446
  }
17443
17447
  this.defination.content = {};
17444
17448
  };
17445
- _proto.translateByPixel = function translateByPixel(x, y) {
17446
- if (this.composition) {
17447
- var _this_composition_getEngine_canvas_getBoundingClientRect = this.composition.getEngine().canvas.getBoundingClientRect(), width = _this_composition_getEngine_canvas_getBoundingClientRect.width, height = _this_composition_getEngine_canvas_getBoundingClientRect.height;
17448
- var z = this.transform.getWorldPosition().z;
17449
- var _this_composition_camera_getInverseVPRatio = this.composition.camera.getInverseVPRatio(z), rx = _this_composition_camera_getInverseVPRatio.x, ry = _this_composition_camera_getInverseVPRatio.y;
17450
- this.transform.translate(2 * x * rx / width, -2 * y * ry / height, 0);
17451
- }
17452
- };
17453
17449
  /**
17454
17450
  * 销毁元素
17455
17451
  */ _proto.dispose = function dispose() {
@@ -28890,7 +28886,6 @@ var TextComponentBase = /*#__PURE__*/ function() {
28890
28886
  this.lineCount = 0;
28891
28887
  this.maxLineWidth = 0;
28892
28888
  // 常量
28893
- this.SCALE_FACTOR = 0.1;
28894
28889
  this.ALPHA_FIX_VALUE = 1 / 255;
28895
28890
  }
28896
28891
  var _proto = TextComponentBase.prototype;
@@ -29012,8 +29007,8 @@ var TextComponentBase = /*#__PURE__*/ function() {
29012
29007
  };
29013
29008
  _proto.setupShadow = function setupShadow() {
29014
29009
  var context = this.context;
29015
- var _this_textStyle = this.textStyle, outlineColor = _this_textStyle.outlineColor, shadowBlur = _this_textStyle.shadowBlur, shadowOffsetX = _this_textStyle.shadowOffsetX, shadowOffsetY = _this_textStyle.shadowOffsetY;
29016
- var r = outlineColor[0], g = outlineColor[1], b = outlineColor[2], a = outlineColor[3];
29010
+ var _this_textStyle = this.textStyle, shadowColor = _this_textStyle.shadowColor, shadowBlur = _this_textStyle.shadowBlur, shadowOffsetX = _this_textStyle.shadowOffsetX, shadowOffsetY = _this_textStyle.shadowOffsetY;
29011
+ var r = shadowColor[0], g = shadowColor[1], b = shadowColor[2], a = shadowColor[3];
29017
29012
  if (context) {
29018
29013
  context.shadowColor = "rgba(" + r * 255 + ", " + g * 255 + ", " + b * 255 + ", " + a + ")";
29019
29014
  context.shadowBlur = shadowBlur;
@@ -29238,11 +29233,11 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29238
29233
  _proto.getLineCount = function getLineCount(text) {
29239
29234
  var context = this.context;
29240
29235
  var _this_textLayout = this.textLayout, letterSpace = _this_textLayout.letterSpace, overflow = _this_textLayout.overflow;
29241
- // const fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
29242
29236
  this.maxLineWidth = 0;
29243
29237
  var width = this.textLayout.width + this.textStyle.fontOffset;
29244
29238
  var lineCount = 1;
29245
29239
  var x = 0;
29240
+ var charCountInLine = 0; // 跟踪当前行的字符数
29246
29241
  // 设置 context.font 的字号,确保 measureText 能正确计算字宽
29247
29242
  if (context) {
29248
29243
  context.font = this.getFontDesc(this.textStyle.fontSize);
@@ -29253,14 +29248,19 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29253
29248
  var _context_measureText_width;
29254
29249
  var textMetrics = (_context_measureText_width = context == null ? void 0 : (_context_measureText = context.measureText(str)) == null ? void 0 : _context_measureText.width) != null ? _context_measureText_width : 0;
29255
29250
  // 和浏览器行为保持一致
29256
- x += letterSpace;
29251
+ // 字符间距只应用在字符之间,每行第一个字符不加间距
29252
+ if (charCountInLine > 0) {
29253
+ x += letterSpace;
29254
+ }
29257
29255
  // 处理文本结束行为
29258
29256
  if (overflow === TextOverflow.display) {
29259
29257
  if (str === "\n") {
29260
29258
  lineCount++;
29261
29259
  x = 0;
29260
+ charCountInLine = 0; // 重置行字符计数
29262
29261
  } else {
29263
29262
  x += textMetrics;
29263
+ charCountInLine++;
29264
29264
  this.maxLineWidth = Math.max(this.maxLineWidth, x);
29265
29265
  }
29266
29266
  } else {
@@ -29268,9 +29268,11 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29268
29268
  lineCount++;
29269
29269
  this.maxLineWidth = Math.max(this.maxLineWidth, x);
29270
29270
  x = 0;
29271
+ charCountInLine = 0; // 重置行字符计数
29271
29272
  }
29272
29273
  if (str !== "\n") {
29273
29274
  x += textMetrics;
29275
+ charCountInLine++;
29274
29276
  }
29275
29277
  }
29276
29278
  }
@@ -29417,7 +29419,10 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29417
29419
  var str = char[i];
29418
29420
  var textMetrics = context.measureText(str);
29419
29421
  // 和浏览器行为保持一致
29420
- x += layout.letterSpace * fontScale;
29422
+ // 字符间距只应用在字符之间,每行第一个字符不加间距
29423
+ if (charsArray.length > 0) {
29424
+ x += layout.letterSpace * fontScale;
29425
+ }
29421
29426
  if (x + textMetrics.width > baseWidth && i > 0 || str === "\n") {
29422
29427
  charsInfo.push({
29423
29428
  y: y,
@@ -31647,7 +31652,7 @@ function getStandardSpriteContent(sprite, transform) {
31647
31652
  return ret;
31648
31653
  }
31649
31654
 
31650
- var version$2 = "2.8.6";
31655
+ var version$2 = "2.8.8";
31651
31656
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
31652
31657
  var standardVersion = /^(\d+)\.(\d+)$/;
31653
31658
  var reverseParticle = false;
@@ -35347,7 +35352,7 @@ registerPlugin("text", TextLoader);
35347
35352
  registerPlugin("sprite", SpriteLoader);
35348
35353
  registerPlugin("particle", ParticleLoader);
35349
35354
  registerPlugin("interact", InteractLoader);
35350
- var version$1 = "2.8.6";
35355
+ var version$1 = "2.8.8";
35351
35356
  logger.info("Core version: " + version$1 + ".");
35352
35357
 
35353
35358
  var _obj;
@@ -36924,7 +36929,7 @@ applyMixins(exports.ThreeTextComponent, [
36924
36929
  */ Mesh.create = function(engine, props) {
36925
36930
  return new ThreeMesh(engine, props);
36926
36931
  };
36927
- var version = "2.8.6";
36932
+ var version = "2.8.8";
36928
36933
  logger.info("THREEJS plugin version: " + version + ".");
36929
36934
 
36930
36935
  exports.ActivationMixerPlayable = ActivationMixerPlayable;