@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/index.mjs 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.2
6
+ * Version: v2.8.3
7
7
  */
8
8
 
9
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
@@ -18366,6 +18366,15 @@ PostProcessVolume = __decorate([
18366
18366
  });
18367
18367
  })();
18368
18368
  };
18369
+ _proto.onUpdate = function onUpdate(dt) {
18370
+ for(var i = 0; i < this.materials.length; i++){
18371
+ var material = this.materials[i];
18372
+ material.setVector2("_Size", this.transform.size);
18373
+ if (this.renderer.renderMode === RenderMode.BILLBOARD || this.renderer.renderMode === RenderMode.VERTICAL_BILLBOARD || this.renderer.renderMode === RenderMode.HORIZONTAL_BILLBOARD) {
18374
+ material.setVector3("_Scale", this.transform.scale);
18375
+ }
18376
+ }
18377
+ };
18369
18378
  _proto.render = function render(renderer) {
18370
18379
  if (!this.getVisible()) {
18371
18380
  return;
@@ -18427,12 +18436,7 @@ PostProcessVolume = __decorate([
18427
18436
  };
18428
18437
  _proto.draw = function draw(renderer) {
18429
18438
  for(var i = 0; i < this.materials.length; i++){
18430
- var material = this.materials[i];
18431
- material.setVector2("_Size", this.transform.size);
18432
- if (this.renderer.renderMode === RenderMode.BILLBOARD || this.renderer.renderMode === RenderMode.VERTICAL_BILLBOARD || this.renderer.renderMode === RenderMode.HORIZONTAL_BILLBOARD) {
18433
- material.setVector3("_Scale", this.transform.scale);
18434
- }
18435
- renderer.drawGeometry(this.geometry, this.transform.getWorldMatrix(), material, i);
18439
+ renderer.drawGeometry(this.geometry, this.transform.getWorldMatrix(), this.materials[i], i);
18436
18440
  }
18437
18441
  };
18438
18442
  _proto.fromData = function fromData(data) {
@@ -25690,6 +25694,7 @@ var SpriteComponent = /*#__PURE__*/ function(MaskableGraphic) {
25690
25694
  var _proto = SpriteComponent.prototype;
25691
25695
  _proto.onUpdate = function onUpdate(dt) {
25692
25696
  var _this = this;
25697
+ MaskableGraphic.prototype.onUpdate.call(this, dt);
25693
25698
  var time = this.time;
25694
25699
  var duration = this.duration;
25695
25700
  var textureAnimation = this.textureSheetAnimation;
@@ -28683,11 +28688,11 @@ var TextLayout = /*#__PURE__*/ function() {
28683
28688
  * @param totalLineHeight - 可选的实际总行高,用于替代默认计算
28684
28689
  * @returns - 行高偏移值
28685
28690
  */ _proto.getOffsetY = function getOffsetY(style, lineCount, lineHeight, fontSize, totalLineHeight) {
28686
- var outlineWidth = style.outlineWidth, fontScale = style.fontScale;
28691
+ var fontScale = style.fontScale;
28687
28692
  // /3 计算Y轴偏移量,以匹配编辑器行为
28688
28693
  var offsetY = (lineHeight - fontSize) / 3;
28689
28694
  // 计算基础偏移量
28690
- var baseOffset = fontSize + outlineWidth * fontScale;
28695
+ var baseOffset = fontSize;
28691
28696
  var commonCalculation = totalLineHeight !== undefined ? totalLineHeight : lineHeight * (lineCount - 1);
28692
28697
  var offsetResult = 0;
28693
28698
  switch(this.textVerticalAlign){
@@ -28703,11 +28708,16 @@ var TextLayout = /*#__PURE__*/ function() {
28703
28708
  }
28704
28709
  return offsetResult;
28705
28710
  };
28706
- _proto.getOffsetX = function getOffsetX(style, maxWidth) {
28711
+ /**
28712
+ * 获取初始的水平偏移值
28713
+ * @param style - 字体基础数据
28714
+ * @param maxWidth - 最大行宽
28715
+ * @returns - 水平偏移值
28716
+ */ _proto.getOffsetX = function getOffsetX(style, maxWidth) {
28707
28717
  var offsetX = 0;
28708
28718
  switch(this.textAlign){
28709
28719
  case TextAlignment.left:
28710
- offsetX = style.outlineWidth * style.fontScale;
28720
+ offsetX = 0;
28711
28721
  break;
28712
28722
  case TextAlignment.middle:
28713
28723
  offsetX = (this.width * style.fontScale - maxWidth) / 2;
@@ -28783,7 +28793,8 @@ var TextStyle = /*#__PURE__*/ function() {
28783
28793
  1
28784
28794
  ];
28785
28795
  this.outlineWidth = 0;
28786
- if (outline) {
28796
+ var _outline_outlineWidth;
28797
+ if (outline && ((_outline_outlineWidth = outline.outlineWidth) != null ? _outline_outlineWidth : 0) > 0) {
28787
28798
  this.isOutlined = true;
28788
28799
  var _outline_outlineColor;
28789
28800
  this.outlineColor = [].concat((_outline_outlineColor = outline.outlineColor) != null ? _outline_outlineColor : [
@@ -28792,8 +28803,8 @@ var TextStyle = /*#__PURE__*/ function() {
28792
28803
  1,
28793
28804
  1
28794
28805
  ]);
28795
- var _outline_outlineWidth;
28796
- this.outlineWidth = (_outline_outlineWidth = outline.outlineWidth) != null ? _outline_outlineWidth : 1;
28806
+ var _outline_outlineWidth1;
28807
+ this.outlineWidth = (_outline_outlineWidth1 = outline.outlineWidth) != null ? _outline_outlineWidth1 : 0;
28797
28808
  }
28798
28809
  // 重置阴影状态
28799
28810
  this.hasShadow = false;
@@ -29054,6 +29065,10 @@ var TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29054
29065
  * 文本行数
29055
29066
  */ _this.lineCount = 0;
29056
29067
  /**
29068
+ * 描边/阴影等特效导致的纹理扩容比例 X/Y
29069
+ */ _this.effectScaleX = 1;
29070
+ _this.effectScaleY = 1;
29071
+ /**
29057
29072
  * 每一行文本的最大宽度
29058
29073
  */ _this.maxLineWidth = 0;
29059
29074
  /**
@@ -29115,6 +29130,16 @@ var TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29115
29130
  _proto.onUpdate = function onUpdate(dt) {
29116
29131
  MaskableGraphic.prototype.onUpdate.call(this, dt);
29117
29132
  this.updateTexture();
29133
+ // 覆盖基类每帧更新 size 行为,应用扩容比例
29134
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.materials), _step; !(_step = _iterator()).done;){
29135
+ var material = _step.value;
29136
+ var sizeX = this.transform.size.x;
29137
+ var sizeY = this.transform.size.y;
29138
+ var _this_getTextureExpandScale = this.getTextureExpandScale(), scalex = _this_getTextureExpandScale[0], scaley = _this_getTextureExpandScale[1];
29139
+ sizeX *= scalex;
29140
+ sizeY *= scaley;
29141
+ material.setVector2("_Size", new Vector2(sizeX, sizeY));
29142
+ }
29118
29143
  };
29119
29144
  _proto.onDestroy = function onDestroy() {
29120
29145
  MaskableGraphic.prototype.onDestroy.call(this);
@@ -29304,23 +29329,32 @@ var TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29304
29329
  var style = this.textStyle;
29305
29330
  var layout = this.textLayout;
29306
29331
  var fontScale = style.fontScale;
29307
- var width = (layout.width + style.fontOffset) * fontScale;
29332
+ var baseWidth = (layout.width + style.fontOffset) * fontScale;
29308
29333
  var finalHeight = layout.lineHeight * this.lineCount;
29309
29334
  var fontSize = style.fontSize * fontScale;
29310
29335
  var lineHeight = layout.lineHeight * fontScale;
29311
29336
  style.fontDesc = this.getFontDesc(fontSize);
29312
29337
  var char = (this.text || "").split("");
29338
+ var baseHeight = 0;
29313
29339
  if (layout.autoWidth) {
29314
- this.canvas.height = finalHeight * fontScale;
29340
+ baseHeight = finalHeight * fontScale;
29315
29341
  this.item.transform.size.set(1, finalHeight / layout.height);
29316
29342
  } else {
29317
- this.canvas.height = layout.height * fontScale;
29318
- }
29319
- var height = this.canvas.height;
29320
- this.renderToTexture(width, height, flipY, function(context) {
29343
+ baseHeight = layout.height * fontScale;
29344
+ }
29345
+ var _this_getEffectPadding = this.getEffectPadding(), padL = _this_getEffectPadding.padL, padR = _this_getEffectPadding.padR, padT = _this_getEffectPadding.padT, padB = _this_getEffectPadding.padB;
29346
+ var hasEffect = (padL | padR | padT | padB) !== 0;
29347
+ var texWidth = hasEffect ? Math.ceil(baseWidth + padL + padR) : baseWidth;
29348
+ var texHeight = hasEffect ? Math.ceil(baseHeight + padT + padB) : baseHeight;
29349
+ var shiftX = hasEffect ? padL : 0;
29350
+ var shiftY = hasEffect ? flipY ? padT : padB : 0;
29351
+ // 给渲染层用:扩容比例
29352
+ this.effectScaleX = baseWidth > 0 ? texWidth / baseWidth : 1;
29353
+ this.effectScaleY = baseHeight > 0 ? texHeight / baseHeight : 1;
29354
+ this.renderToTexture(texWidth, texHeight, flipY, function(context) {
29321
29355
  // canvas size 变化后重新刷新 context
29322
- if (_this.maxLineWidth > width && layout.overflow === TextOverflow.display) {
29323
- context.font = _this.getFontDesc(fontSize * width / _this.maxLineWidth);
29356
+ if (_this.maxLineWidth > baseWidth && layout.overflow === TextOverflow.display) {
29357
+ context.font = _this.getFontDesc(fontSize * baseWidth / _this.maxLineWidth);
29324
29358
  } else {
29325
29359
  context.font = style.fontDesc;
29326
29360
  }
@@ -29343,7 +29377,7 @@ var TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29343
29377
  var textMetrics = context.measureText(str);
29344
29378
  // 和浏览器行为保持一致
29345
29379
  x += layout.letterSpace * fontScale;
29346
- if (x + textMetrics.width > width && i > 0 || str === "\n") {
29380
+ if (x + textMetrics.width > baseWidth && i > 0 || str === "\n") {
29347
29381
  charsInfo.push({
29348
29382
  y: y,
29349
29383
  width: x,
@@ -29367,14 +29401,27 @@ var TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29367
29401
  chars: charsArray,
29368
29402
  charOffsetX: charOffsetX
29369
29403
  });
29370
- charsInfo.forEach(function(charInfo) {
29371
- var x = layout.getOffsetX(style, charInfo.width);
29372
- charInfo.chars.forEach(function(str, i) {
29373
- if (style.isOutlined) {
29374
- context.strokeText(str, x + charInfo.charOffsetX[i], charInfo.y);
29404
+ // 先描边
29405
+ if (style.isOutlined) {
29406
+ charsInfo.forEach(function(charInfo) {
29407
+ var ox = layout.getOffsetX(style, charInfo.width);
29408
+ for(var i = 0; i < charInfo.chars.length; i++){
29409
+ var str = charInfo.chars[i];
29410
+ var drawX = shiftX + ox + charInfo.charOffsetX[i];
29411
+ var drawY = shiftY + charInfo.y;
29412
+ context.strokeText(str, drawX, drawY);
29375
29413
  }
29376
- context.fillText(str, x + charInfo.charOffsetX[i], charInfo.y);
29377
29414
  });
29415
+ }
29416
+ // 再填充
29417
+ charsInfo.forEach(function(charInfo) {
29418
+ var ox = layout.getOffsetX(style, charInfo.width);
29419
+ for(var i = 0; i < charInfo.chars.length; i++){
29420
+ var str = charInfo.chars[i];
29421
+ var drawX = shiftX + ox + charInfo.charOffsetX[i];
29422
+ var drawY = shiftY + charInfo.y;
29423
+ context.fillText(str, drawX, drawY);
29424
+ }
29378
29425
  });
29379
29426
  if (style.hasShadow) {
29380
29427
  context.shadowColor = "transparent";
@@ -29385,6 +29432,32 @@ var TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29385
29432
  _proto.renderText = function renderText(options) {
29386
29433
  this.updateTexture();
29387
29434
  };
29435
+ /**
29436
+ * 给渲染层用:获取特效扩容比例(描边/阴影导致的纹理扩容)
29437
+ * @returns
29438
+ */ _proto.getTextureExpandScale = function getTextureExpandScale() {
29439
+ return [
29440
+ this.effectScaleX,
29441
+ this.effectScaleY
29442
+ ];
29443
+ };
29444
+ /**
29445
+ * 获取描边和阴影的 padding 值(单位:px)
29446
+ * @returns
29447
+ */ _proto.getEffectPadding = function getEffectPadding() {
29448
+ var style = this.textStyle;
29449
+ var hasDrawOutline = style.isOutlined && style.outlineWidth > 0;
29450
+ var outlinePad = hasDrawOutline ? Math.ceil(style.outlineWidth * 2 * style.fontScale) : 0;
29451
+ var hasShadow = style.hasShadow && (style.shadowBlur > 0 || style.shadowOffsetX !== 0 || style.shadowOffsetY !== 0);
29452
+ var shadowPad = hasShadow ? Math.ceil((Math.abs(style.shadowOffsetX) + Math.abs(style.shadowOffsetY) + style.shadowBlur) * style.fontScale) : 0;
29453
+ var pad = outlinePad + shadowPad;
29454
+ return {
29455
+ padL: pad,
29456
+ padR: pad,
29457
+ padT: pad,
29458
+ padB: pad
29459
+ };
29460
+ };
29388
29461
  _proto.setAutoWidth = function setAutoWidth(value) {
29389
29462
  var layout = this.textLayout;
29390
29463
  var normalizedValue = !!value;
@@ -31533,7 +31606,7 @@ function getStandardSpriteContent(sprite, transform) {
31533
31606
  return ret;
31534
31607
  }
31535
31608
 
31536
- var version$1 = "2.8.2";
31609
+ var version$1 = "2.8.3";
31537
31610
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
31538
31611
  var standardVersion = /^(\d+)\.(\d+)$/;
31539
31612
  var reverseParticle = false;
@@ -35233,7 +35306,7 @@ registerPlugin("text", TextLoader);
35233
35306
  registerPlugin("sprite", SpriteLoader);
35234
35307
  registerPlugin("particle", ParticleLoader);
35235
35308
  registerPlugin("interact", InteractLoader);
35236
- var version = "2.8.2";
35309
+ var version = "2.8.3";
35237
35310
  logger.info("Core version: " + version + ".");
35238
35311
 
35239
35312
  export { ActivationMixerPlayable, ActivationPlayable, ActivationPlayableAsset, ActivationTrack, AndNode, AndNodeData, Animatable, AnimationClip, AnimationClipNode, AnimationClipNodeData, AnimationGraphAsset, Animator, ApplyAdditiveNode, ApplyAdditiveNodeData, Asset, AssetLoader, AssetManager, AssetService, BYTES_TYPE_MAP, Behaviour, BezierCurve, BezierCurvePath, BezierCurveQuat, BinaryAsset, BlendNode, BlendNodeData, BoolValueNode, COPY_FRAGMENT_SHADER, COPY_MESH_SHADER_ID, COPY_VERTEX_SHADER, Camera, CameraController, CameraVFXItemLoader, ColorCurve, ColorPlayable, ColorPropertyMixerPlayable, ColorPropertyPlayableAsset, ColorPropertyTrack, Component, ComponentTimePlayable, ComponentTimePlayableAsset, ComponentTimeTrack, Composition, CompositionComponent, CompressTextureCapabilityType, ConstBoolNode, ConstBoolNodeData, ConstFloatNode, ConstFloatNodeData, ConstraintTarget, ControlParameterBoolNode, ControlParameterBoolNodeData, ControlParameterFloatNode, ControlParameterFloatNodeData, ControlParameterTriggerNode, ControlParameterTriggerNodeData, DEFAULT_FONTS, DEFAULT_FPS, Database, Deferred, DestroyOptions, Downloader, DrawObjectPass, EFFECTS_COPY_MESH_NAME, EVENT_TYPE_CLICK, EVENT_TYPE_TOUCH_END, EVENT_TYPE_TOUCH_MOVE, EVENT_TYPE_TOUCH_START, EffectComponent, EffectComponentTimeTrack, EffectsObject, EffectsPackage, Ellipse, Engine, EqualNodeData, EventEmitter, EventSystem, Fake3DAnimationMode, Fake3DComponent, FilterMode, Float16ArrayWrapper, FloatComparisonNode, FloatComparisonNodeData, FloatPropertyMixerPlayable, FloatPropertyPlayableAsset, FloatPropertyTrack, FloatValueNode, Framebuffer, GLSLVersion, GPUCapability, Geometry, GlobalUniforms, GradientValue, GraphInstance, GraphNode, GraphNodeData, GraphicsPath, GreaterNodeData, HELP_LINK, HitTestType, InteractComponent, InteractLoader, InteractMesh, InvalidIndex, Item, LayerBlendNode, LayerBlendNodeData, LessNodeData, LineSegments, LinearValue, MaskMode, MaskProcessor, MaskableGraphic, Material, MaterialDataBlock, MaterialRenderType, MaterialTrack, Mesh, MeshCollider, NodeTransform, NotNode, NotNodeData, ObjectBindingTrack, OrNode, OrNodeData, OrderType, PLAYER_OPTIONS_ENV_EDITOR, POST_PROCESS_SETTINGS, ParticleBehaviourPlayable, ParticleBehaviourPlayableAsset, ParticleLoader, ParticleMesh, ParticleMixerPlayable, ParticleSystem, ParticleSystemRenderer, ParticleTrack, PassTextureCache, PathSegments, PlayState, Playable, PlayableAsset, PlayableOutput, Plugin, PluginSystem, PointerEventData, PointerEventType, PolyStar, Polygon, Pose, PoseNode, PositionConstraint, PostProcessVolume, PropertyClipPlayable, PropertyTrack, RENDER_PREFER_LOOKUP_TEXTURE, RUNTIME_ENV, RandomSetValue, RandomValue, RandomVectorValue, RaycastResult, RenderFrame, RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, RenderTargetHandle, RenderTargetPool, RenderTextureFormat, Renderbuffer, Renderer, RendererComponent, RuntimeClip, 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, Scene, SceneLoader, SerializationHelper, Shader, ShaderCompileResultStatus, ShaderFactory, ShaderType, ShaderVariant, ShapeComponent, ShapePath, SourceType, SpriteColorMixerPlayable, SpriteColorPlayableAsset, SpriteColorTrack, SpriteComponent, SpriteComponentTimeTrack, SpriteLoader, StarType, StateMachineNode, StateMachineNodeData, StateNode, StateNodeData, StaticValue, SubCompositionClipPlayable, SubCompositionMixerPlayable, SubCompositionPlayableAsset, SubCompositionTrack, TEMPLATE_USE_OFFSCREEN_CANVAS, TangentMode, TextComponent, TextComponentBase, TextLayout, TextLoader, TextStyle, Texture, TextureFactory, TextureLoadAction, TexturePaintScaleMode, TextureSourceType, TextureStoreAction, Ticker, TimelineAsset, TimelineClip, TimelineInstance, TrackAsset, TrackMixerPlayable, TrackType, Transform, TransformMixerPlayable, TransformPlayable, TransformPlayableAsset, TransformTrack, TransitionNode, TransitionNodeData, TransitionState, VFXItem, ValueGetter, ValueNode, Vector2Curve, Vector2PropertyMixerPlayable, Vector2PropertyPlayableAsset, Vector2PropertyTrack, Vector3Curve, Vector3PropertyMixerPlayable, Vector3PropertyTrack, Vector3ropertyPlayableAsset, Vector4Curve, Vector4PropertyMixerPlayable, Vector4PropertyPlayableAsset, Vector4PropertyTrack, WeightedMode, addByOrder, addItem, addItemWithOrder, applyMixins, assertExist, asserts, base64ToFile, buildLine, calculateTranslation, canUseBOM, canvasPool, closePointEps, colorGradingFrag, colorStopsFromGradient, colorToArr$1 as colorToArr, combineImageTemplate, createGLContext, createKeyFrameMeta, createShape, createValueGetter, curveEps, decimalEqual, deserializeMipmapTexture, earcut, effectsClass, effectsClassStore, enlargeBuffer, ensureFixedNumber, ensureVec3, gaussianDownHFrag, gaussianDownVFrag, gaussianUpFrag, generateEmptyTypedArray, generateGUID, generateHalfFloatTexture, generateTransparentTexture, generateWhiteTexture, getBackgroundImage, getClass, getColorFromGradientStops, getConfig, getDefaultTextureFactory, getGeometryByShape, getGeometryTriangles, getKeyFrameMetaByRawValue, getMergedStore, getNodeDataClass, getParticleMeshShader, getPixelRatio, getPluginUsageInfo, getPreMultiAlpha, getStandardComposition, getStandardImage, getStandardItem, getStandardJSON, getTextureSize, glContext, glType2VertexFormatType, gpuTimer, imageDataFromColor, imageDataFromGradient, initErrors, initGLContext, integrate, interpolateColor, isAlipayMiniApp, isAndroid, isArray, isCanvas, isFunction, isIOS, isIOSByUA, isMiniProgram, isObject, isOpenHarmony, isPlainObject, isPowerOfTwo, isSimulatorCellPhone, isString, isUniformStruct, isUniformStructArray, isValidFontFamily, isWebGL2, isWechatMiniApp, itemFrag, itemVert, loadAVIFOptional, loadBinary, loadBlob, loadImage, loadMedia, loadVideo, loadWebPOptional, logger, index as math, modifyMaxKeyframeShader, nearestPowerOfTwo, nodeDataClass, noop, normalizeColor, numberToFix, oldBezierKeyFramesToNew, parsePercent$1 as parsePercent, particleFrag, particleOriginTranslateMap$1 as particleOriginTranslateMap, particleUniformTypeMap, particleVert, passRenderLevel, pluginLoaderMap, randomInRange, registerPlugin, removeItem, rotateVec2, screenMeshVert, serialize, setBlendMode, setConfig, setDefaultTextureFactory, setMaskMode, setRayFromCamera, setSideMode, sortByOrder, index$1 as spec, textureLoaderRegistry, thresholdFrag, throwDestroyedError, trailVert, translatePoint, trianglesFromRect, unregisterPlugin, valIfUndefined, value, valueDefine, vecFill, vecMulCombine, version, vertexFormatType2GLType };