@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.mjs 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-beta.1
6
+ * Version: v1.6.0
7
7
  */
8
8
 
9
9
  import * as THREE from 'three';
@@ -20282,32 +20282,37 @@ var TextLayout = /** @class */ (function () {
20282
20282
  this.textAlign = textAlign;
20283
20283
  this.lineHeight = lineHeight;
20284
20284
  }
20285
- TextLayout.prototype.getOffsetY = function (style) {
20286
- var offsetY = 0;
20287
- var offset = (style.fontSize + style.outlineWidth) * style.fontScale;
20285
+ TextLayout.prototype.getOffsetY = function (style, lineCount, lineHeight) {
20286
+ var offsetResult = 0;
20287
+ var fontSize = style.fontSize, outlineWidth = style.outlineWidth, fontScale = style.fontScale;
20288
+ // 计算基础偏移量
20289
+ var baseOffset = (fontSize + outlineWidth) * fontScale;
20290
+ // /3 计算Y轴偏移量,以匹配编辑器行为
20291
+ var offsetY = (lineHeight - fontSize) / 3;
20292
+ var commonCalculation = lineHeight * (lineCount - 1);
20288
20293
  switch (this.textBaseline) {
20289
- case 0:
20290
- offsetY = offset;
20294
+ case TextBaseline$1.top:
20295
+ offsetResult = baseOffset + offsetY;
20291
20296
  break;
20292
- case 1:
20293
- offsetY = (this.height + offset) / 2; // fonSize;
20297
+ case TextBaseline$1.middle:
20298
+ offsetResult = (this.height * fontScale - commonCalculation + baseOffset) / 2;
20294
20299
  break;
20295
- case 2:
20296
- offsetY = this.height - offset / 2;
20300
+ case TextBaseline$1.bottom:
20301
+ offsetResult = (this.height * fontScale - commonCalculation) - offsetY;
20297
20302
  break;
20298
20303
  }
20299
- return offsetY;
20304
+ return offsetResult;
20300
20305
  };
20301
20306
  TextLayout.prototype.getOffsetX = function (style, maxWidth) {
20302
20307
  var offsetX = 0;
20303
20308
  switch (this.textAlign) {
20304
- case 0:
20309
+ case TextAlignment$1.left:
20305
20310
  offsetX = style.outlineWidth * style.fontScale;
20306
20311
  break;
20307
- case 1:
20312
+ case TextAlignment$1.middle:
20308
20313
  offsetX = (this.width * style.fontScale - maxWidth) / 2;
20309
20314
  break;
20310
- case 2:
20315
+ case TextAlignment$1.right:
20311
20316
  offsetX = (this.width * style.fontScale - maxWidth);
20312
20317
  break;
20313
20318
  }
@@ -20330,6 +20335,10 @@ var TextItem = /** @class */ (function (_super) {
20330
20335
  function TextItem(props, opts, vfxItem) {
20331
20336
  var _this = _super.call(this, props, opts, vfxItem) || this;
20332
20337
  _this.isDirty = true;
20338
+ /**
20339
+ * 文本行数
20340
+ */
20341
+ _this.lineCount = 0;
20333
20342
  var options = props.options;
20334
20343
  _this.canvas = canvasPool.getCanvas();
20335
20344
  canvasPool.saveCanvas(_this.canvas);
@@ -20338,10 +20347,34 @@ var TextItem = /** @class */ (function (_super) {
20338
20347
  _this.textStyle = new TextStyle(options);
20339
20348
  _this.textLayout = new TextLayout(options);
20340
20349
  _this.text = options.text;
20350
+ _this.lineCount = _this.getLineCount(options.text, true);
20341
20351
  // Text
20342
20352
  _this.mesh = new TextMesh(_this.engine, _this.renderInfo, vfxItem.composition);
20343
20353
  return _this;
20344
20354
  }
20355
+ TextItem.prototype.getLineCount = function (text, init) {
20356
+ var _a, _b;
20357
+ var context = this.context;
20358
+ var letterSpace = this.textLayout.letterSpace;
20359
+ var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
20360
+ var width = (this.textLayout.width + this.textStyle.fontOffset);
20361
+ var lineCount = 1;
20362
+ var x = 0;
20363
+ for (var i = 0; i < text.length; i++) {
20364
+ var str = text[i];
20365
+ 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;
20366
+ // 和浏览器行为保持一致
20367
+ x += letterSpace;
20368
+ if (((x + textMetrics) > width && i > 0) || str === '\n') {
20369
+ lineCount++;
20370
+ x = 0;
20371
+ }
20372
+ if (str !== '\n') {
20373
+ x += textMetrics;
20374
+ }
20375
+ }
20376
+ return lineCount;
20377
+ };
20345
20378
  /**
20346
20379
  * 设置字号大小
20347
20380
  * @param value - 字号
@@ -20391,6 +20424,7 @@ var TextItem = /** @class */ (function (_super) {
20391
20424
  return;
20392
20425
  }
20393
20426
  this.text = value;
20427
+ this.lineCount = this.getLineCount(value, false);
20394
20428
  this.isDirty = true;
20395
20429
  };
20396
20430
  /**
@@ -20541,7 +20575,7 @@ var TextItem = /** @class */ (function (_super) {
20541
20575
  var fontScale = style.fontScale;
20542
20576
  var width = (layout.width + style.fontOffset) * fontScale;
20543
20577
  var height = layout.height * fontScale;
20544
- var fontSize = style.fontSize * fontScale;
20578
+ style.fontSize * fontScale;
20545
20579
  var lineHeight = layout.lineHeight * fontScale;
20546
20580
  this.char = (this.text || '').split('');
20547
20581
  this.canvas.width = width;
@@ -20561,10 +20595,8 @@ var TextItem = /** @class */ (function (_super) {
20561
20595
  // 文本颜色
20562
20596
  context.fillStyle = "rgba(".concat(style.textColor[0], ", ").concat(style.textColor[1], ", ").concat(style.textColor[2], ", ").concat(style.textColor[3], ")");
20563
20597
  var charsInfo = [];
20564
- // /3 为了和编辑器行为保持一致
20565
- var offsetY = (lineHeight - fontSize) / 3;
20566
20598
  var x = 0;
20567
- var y = layout.getOffsetY(style) + offsetY;
20599
+ var y = layout.getOffsetY(style, this.lineCount, lineHeight);
20568
20600
  var charsArray = [];
20569
20601
  var charOffsetX = [];
20570
20602
  for (var i = 0; i < this.char.length; i++) {
@@ -27454,7 +27486,7 @@ Geometry.create = function (engine, options) {
27454
27486
  Mesh.create = function (engine, props) {
27455
27487
  return new ThreeMesh(engine, props);
27456
27488
  };
27457
- var version = "1.6.0-beta.1";
27489
+ var version = "1.6.0";
27458
27490
  logger.info('THREEJS plugin version: ' + version);
27459
27491
 
27460
27492
  export { AbstractPlugin, AssetManager, BYTES_TYPE_MAP, BezierCurve, BezierCurvePath, COMPRESSED_TEXTURE, CONSTANT_MAP_BLEND, CONSTANT_MAP_DEPTH, CONSTANT_MAP_STENCIL_FUNC, CONSTANT_MAP_STENCIL_OP, COPY_FRAGMENT_SHADER, COPY_MESH_SHADER_ID, COPY_VERTEX_SHADER, CalculateItem, CalculateLoader, CalculateVFXItem, Camera, CameraController, CameraVFXItem, CameraVFXItemLoader, Composition, CompositionSourceManager, DEFAULT_FONTS, DestroyOptions, Downloader, EFFECTS_COPY_MESH_NAME, EVENT_TYPE_CLICK, EVENT_TYPE_TOUCH_END, EVENT_TYPE_TOUCH_MOVE, EVENT_TYPE_TOUCH_START, Engine, EventSystem, FILTER_NAME_NONE, FilterMode, FilterSpriteVFXItem, Float16ArrayWrapper, FrameBuffer, GLSLVersion, GPUCapability, Geometry, GlobalUniforms, GradientValue, HELP_LINK, HitTestType, InteractBehavior$1 as InteractBehavior, InteractItem, InteractLoader, InteractMesh, InteractVFXItem, Item, KTXTexture, LineSegments, LinearValue, Material, MaterialDataBlock, MaterialRenderType, Mesh, OrderType, PLAYER_OPTIONS_ENV_EDITOR, POST_PROCESS_SETTINGS, ParticleLoader, ParticleMesh, ParticleSystem, ParticleVFXItem, PassTextureCache, PluginSystem, QCanvasViewer, QText, QTextWrapMode, RENDER_PASS_NAME_PREFIX, RENDER_PREFER_LOOKUP_TEXTURE, RUNTIME_ENV, RandomSetValue, RandomValue, RandomVectorValue, RenderBuffer, RenderFrame, RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, RenderTargetHandle, RenderTextureFormat, Renderer, SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_0, SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_SIZE_0, SEMANTIC_PRE_COLOR_ATTACHMENT_0, SEMANTIC_PRE_COLOR_ATTACHMENT_SIZE_0, SPRITE_VERTEX_STRIDE, SemanticMap, Shader, ShaderCompileResultStatus, ShaderType, SpriteItem, SpriteLoader, SpriteMesh, SpriteVFXItem, StaticValue, TEMPLATE_USE_OFFSCREEN_CANVAS, TEXTURE_UNIFORM_MAP, TextItem, TextLoader, TextMesh, TextVFXItem, Texture, TextureFactory, TextureLoadAction, TextureSourceType, TextureStoreAction, ThreeComposition, ThreeDisplayObject, ThreeMaterial, ThreeTexture, Ticker, TimelineComponent, Transform, VFXItem, ValueGetter, addByOrder, addItem, addItemWithOrder, alphaFrameFrag, alphaMaskFrag, assertExist, asserts, blend, bloomMixVert, bloomThresholdVert, calculateTranslation, cameraMove_frag as cameraMoveFrag, cameraMoveVert, canvasPool, colorGradingFrag, colorStopsFromGradient, colorToArr$1 as colorToArr, combineImageTemplate, combineImageTemplate1, combineImageTemplate1Async, combineImageTemplate2, combineImageTemplate2Async, combineImageTemplateAsync, compatible_frag as compatibleFrag, compatible_vert as compatibleVert, convertAnchor, copyFrag, createCopyShader, createFilter, createFilterShaders, createGLContext, createKeyFrameMeta, createShaderWithMarcos, createShape, createVFXItem, createValueGetter, decimalEqual, deepClone, defaultGlobalVolume, defaultPlugins, delayFrag, deserializeMipmapTexture, distortionFrag, distortionVert, earcut, enlargeBuffer, ensureVec3, filters, findPreviousRenderPass, gaussianDown_frag as gaussianDownFrag, gaussianDownHFrag, gaussianDownVFrag, gaussianUpFrag, generateEmptyTypedArray, generateHalfFloatTexture, getBackgroundImage, getColorFromGradientStops, getConfig, getDefaultTemplateCanvasPool, getDefaultTextureFactory, getGeometryByShape, getGeometryTriangles, getImageItemRenderInfo, getKTXTextureOptions, getKeyFrameMetaByRawValue, getParticleMeshShader, getPixelRatio, getPreMultiAlpha, getStandardComposition, getStandardImage, getStandardItem, getStandardJSON, getTextureSize, glContext, gpuTimer, imageDataFromColor, imageDataFromGradient, initErrors, initGLContext, integrate, interpolateColor, isAlipayMiniApp, isAndroid, isArray, isFunction, isIOS, isObject, isScene, isSimulatorCellPhone, isString, isUniformStruct, isUniformStructArray, isValidFontFamily, isWebGL2, itemFrag, itemFrameFrag, itemVert, loadBinary, loadBlob, loadImage, loadMedia, loadVideo, loadWebPOptional, logger, index as math, maxSpriteMeshItemCount, maxSpriteTextureCount, modifyMaxKeyframeShader, nearestPowerOfTwo, noop, numberToFix, parsePercent$1 as parsePercent, particleFrag, particleOriginTranslateMap, particleUniformTypeMap, particleVert, pluginLoaderMap, pointOnLine, random, registerFilter, registerFilters, registerPlugin, removeItem, requestAsync, rotateVec2, screenMeshVert, setBlendMode, setConfig, setDefaultTextureFactory, setMaskMode, setMaxSpriteMeshItemCount, setRayFromCamera, setSideMode, setSpriteMeshMaxFragmentTextures, setSpriteMeshMaxItemCountByGPU, setUniformValue, sortByOrder, index$1 as spec, spriteMeshShaderFromFilter, spriteMeshShaderFromRenderInfo, spriteMeshShaderIdFromRenderInfo, thresholdFrag, throwDestroyedError, trailVert, translatePoint, trianglesFromRect, unregisterPlugin, valIfUndefined, value, valueDefine, vecAssign, vecFill, vecMulCombine, vecNormalize, version };