UMassBattleATADataAsset
Source/MassBattleEditor/Public/SpritePrep/MassBattleATADataAsset.h
概述Overview
Anim-to-Atlas 源资产:有序帧轨道加上把它们排成一张网格图的布局参数。这是 sprite 族的预填资产——图集纹理由 Creator 的 Generate 产出并回写到这里,因此资产同时记录「输入了什么」与「产出了什么」,且不依赖会被重导出冲掉的贴图元数据、也不依赖会被 BC 压缩/mip/逐格采样破坏的像素边带。
The Anim-to-Atlas source asset: ordered frame tracks plus the layout parameters that turn them into one grid sheet. This is the sprite family's prep asset — the atlas texture is produced by the Creator's Generate and written back here, so the asset records both what went in and what came out without depending on raster metadata (which dies on re-export) or pixel sidebands (destroyed by BC compression, mips and per-cell UV sampling).
Details 面板自上而下读作「输入什么 → 怎么排 → 出了什么」,分类名与 Sprite Prep 窗口的词汇一致:Sprite Source(有序帧轨道)、Cell(格子尺寸)、Grid(列数)、Texture(2 的幂、sRGB、过滤、尺寸上限)、Render(sprite 渲染管线画什么、多快)、Atlas(Generate 写入:图集纹理、网格尺寸、推导区间)。可手调的全部在 Atlas 之前,Generate 产出全部在 Atlas 里。
The Details panel reads top-down as “what goes in → how it is laid out → what came out”, and its categories mirror the Sprite Prep window's own vocabulary: Sprite Source (the ordered frame tracks), Cell (cell size), Grid (column count), Texture (power-of-two, sRGB, filtering, size cap), Render (what the sprite render pipeline draws and how fast) and Atlas (written by Generate: atlas texture, grid size, derived ranges). Everything hand-editable sits above Atlas; everything Generate produces sits in it.
继承Inheritance
FMassBattleATALayout struct
解析出的图集布局:格子尺寸、网格、以及每条轨道的起始行主序格号。Sprite Prep 面板(推导区间)与 Generate(合成像素)共用同一份结果,二者的落格因此永远一致。它是普通 C++ 结构体(非 USTRUCT),只在内存里传递。
The resolved atlas layout: cell size, grid, and the row-major cell each track starts at. The Sprite Prep panel (deriving ranges) and Generate (compositing pixels) share one result, so both always agree on where a track lands. It is a plain C++ struct (not a USTRUCT), carried in memory only.
成员变量Members
| 名称Name | 类型Type | 默认值Default | 说明Description |
|---|---|---|---|
CellW | int32 | 0 | 单格宽度(像素)。自动格子取全帧最大宽,手动值取配置值(下限 1);开启 2 的幂时会被向上取整。Cell width in pixels. Auto takes the largest frame width; the manual value is clamped to at least 1; power-of-two mode rounds it up. |
CellH | int32 | 0 | 单格高度(像素),规则与 CellW 相同。Cell height in pixels, with the same rules as CellW. |
Cols | int32 | 0 | 网格列数。自动 = ceil(√总帧数),手动 = 配置值;开启 2 的幂时向上取整。Grid column count. Auto = ceil(√total frames), manual = the configured value; rounded up in power-of-two mode. |
Rows | int32 | 0 | 网格行数 = ceil(总帧数 / 列数),所以最后一行可以不满;开启 2 的幂时向上取整。Grid row count = ceil(total frames / columns), so the last row may be partial; rounded up in power-of-two mode. |
TotalCells | int32 | 0 | Cols × Rows,即图集的格子总数。未被使用的格子保持透明。Cols × Rows, the atlas cell count. Unused cells stay transparent. |
CellFrames | TArray<TObjectPtr<UTexture2D>> | 空empty | 按落格顺序拼接的全部帧:数组下标就是行主序格号(自左上角起)。空轨不贡献任何帧。Every frame concatenated in placement order: the array index is the row-major cell index (from the top-left). Empty tracks contribute nothing. |
TrackStarts | TArray<int32> | 空empty | 每条已用轨道的首帧格号,与 UsedTrackIndices 平行。First-frame cell index of each used track, parallel to UsedTrackIndices. |
UsedTrackIndices | TArray<int32> | 空empty | 真正落进图集的轨道下标(按轨道顺序)。调用方据此把 StartFrame 精确写回那几条轨道。Indices of the tracks that actually landed in the sheet, in track order. Callers use it to write StartFrame back to exactly those tracks. |
成员变量Members
Sprite 源Sprite Source
| 名称Name | 类型Type | 默认值Default | 说明Description |
|---|---|---|---|
Tracks | TArray<FMassBattleATAFrameTrack> | 空empty | 动画轨:桶 + 槽位 + 有序源帧。数组顺序即落格顺序,也是播放顺序。轨道结构的字段见 MassBattleEditorStructs.h 的 FMassBattleATAFrameTrack(桶、槽位 0–7、帧数组、作为布局结果的 StartFrame)。Animation tracks: bucket + slot + ordered source frames. Array order is both placement order and playback order. The track fields live in MassBattleEditorStructs.h's FMassBattleATAFrameTrack (bucket, slot 0–7, frame array, and the layout result StartFrame). |
格子Cell
| 名称Name | 类型Type | 默认值Default | 说明Description |
|---|---|---|---|
bAutoCellSize | bool | true | 开启时格子 = 全部帧的最大宽高;关闭后用手动宽高。帧必须放得下——绝不缩放:任何一帧超出格子都让布局失败。On: cell = the largest frame width/height across all frames. Off: the manual sizes. Frames must fit and are never scaled: any frame larger than the cell fails the layout. |
CellWidth | int32 | 128 | 手动格子宽(像素),仅自动格子关闭时生效;源码下限 1。Manual cell width in pixels, used only when auto cell size is off; source minimum 1. |
CellHeight | int32 | 128 | 手动格子高(像素),仅自动格子关闭时生效;源码下限 1。Manual cell height in pixels, used only when auto cell size is off; source minimum 1. |
网格Grid
| 名称Name | 类型Type | 默认值Default | 说明Description |
|---|---|---|---|
bAutoColumns | bool | true | 开启时列数 = ceil(√总帧数);关闭时用手动列数。行数始终由帧总数与列数推出。On: columns = ceil(√total frames). Off: the manual count. Rows are always derived from the frame total and the column count. |
Columns | int32 | 8 | 手动列数,仅自动列数关闭时生效;源码下限 1。Manual column count, used only when auto columns is off; source minimum 1. |
纹理Texture
| 名称Name | 类型Type | 默认值Default | 说明Description |
|---|---|---|---|
bPowerOfTwo | bool | true | 把格子宽高、列数、行数依次向上取到 2 的幂,图集宽高因此也是 2 的幂;可能留下未使用的透明格子。Snaps cell width/height, then columns, then rows up to powers of two, which makes the atlas width/height powers of two as well; unused cells may remain. |
bSRGB | bool | true | 把生成的图集标记为 sRGB 颜色数据。Marks the generated atlas as sRGB colour data. |
bNearestFilter | bool | true | 点采样——帧像素锐利,无插值。Point filtering — crisp frame pixels, no interpolation. |
MaxAtlasSize | int32 | 4096 | 生成的图集宽高硬上限(像素),源码范围 256–16384。宽或高任一维超出即让布局失败,不裁剪、不自动缩格子。Hard cap on generated atlas width/height in pixels, source range 256–16384. Either dimension exceeding it fails the layout; nothing is cropped or auto-shrunk. |
渲染Render
| 名称Name | 类型Type | 默认值Default | 说明Description |
|---|---|---|---|
MasterMaterial | TObjectPtr<UMaterialInterface> | nullptr | 逐版本 sprite 材质实例的母材质。它必须暴露 MB_AtlasTexture / MB_AtlasCols / MB_AtlasRows 与 MB_SpriteMode 开关——sprite 烘焙按这三个参数把帧号映射到格子。Master material the per-version sprite material instances parent to. It must expose MB_AtlasTexture / MB_AtlasCols / MB_AtlasRows and the MB_SpriteMode switch — the sprite bake maps a frame index to a cell through those parameters. |
QuadMesh | TObjectPtr<UStaticMesh> | nullptr | sprite renderer 绘制的四边形(每 renderer 一个网格;逐部件尺寸走网格条目的缩放)。四边形的局部 +X 必须是法线,构建器按它把 renderer 转向相机。The quad every sprite renderer draws (one mesh per renderer; per-part size rides the mesh entry's scale). The quad's local +X must be its normal — the builder uses it to turn the renderer toward the camera. |
PlaybackFPS | double | 12.0 | 图集播放帧率,源码范围 1–120。烘焙写进动画数据的 PlayLength = 帧数 / 本值,因此每段动画的时长由帧数与它共同决定。Atlas playback frame rate, source range 1–120. The bake writes PlayLength = frame count / this value into the animation data, so a clip's length is decided by its frame count and this rate. |
Atlas(Generate / 布局写入,只读展示)Atlas (written by Generate / layout, read-only)
| 名称Name | 类型Type | 默认值Default | 说明Description |
|---|---|---|---|
AtlasTexture | TObjectPtr<UTexture2D> | nullptr | 上次 Generate 产出的图集纹理;此前为空。Atlas texture produced by the last Generate; null until then. |
AtlasCols | int32 | 0 | 产出图集的网格列数,由 ApplyLayout 写入。Grid column count of the produced atlas, written by ApplyLayout. |
AtlasRows | int32 | 0 | 产出图集的网格行数,由 ApplyLayout 写入。Grid row count of the produced atlas, written by ApplyLayout. |
SpriteAnims | FSpriteAnimRangesEd | 空(八桶各 0 槽)empty (eight buckets, 0 slots each) | 由轨道与布局推导出的逐桶帧区间:八个固定桶,每桶最多 8 个槽,每个槽记录起始格号与帧数。它是烘焙出的区间表,不是作者面;ApplyLayout 每次重建它。Per-bucket frame ranges derived from the tracks and the layout: eight fixed buckets with up to 8 slots each, every slot recording a start cell and a frame count. It is the baked range table, not an authoring surface; ApplyLayout rebuilds it every time. |
公开方法Public Methods
布局算法本体:把一组轨道与一组参数解成 FMassBattleATALayout。逐轨道跳过空轨,记录「哪些轨道真的落进了图集」以及每条的首帧格号;任一帧为空、没有源像素数据或尺寸超出格子都立即失败。格子/列/行按上面的规则计算,开启 2 的幂时依次上取整,最后用 MaxAtlasSize 否决过大的图集。Out 在入口被重置,失败时视为无效。
The layout algorithm itself: resolves a set of tracks and parameters into a FMassBattleATALayout. Empty tracks are skipped while the tracks that really land in the sheet — and each one's first cell — are recorded; a null frame, a frame with no source pixel data or a frame larger than the cell fails immediately. Cell/columns/rows follow the rules above, power-of-two mode rounds each up in turn, and MaxAtlasSize vetoes an oversized sheet at the end. Out is reset on entry; on failure treat it as invalid.
Input
| 参数Param | 类型Type | 说明Description |
|---|---|---|
InTracks | const TArray<FMassBattleATAFrameTrack>& | 有序帧轨道;数组顺序即落格顺序。Ordered frame tracks; array order is placement order. |
bInAutoCellSize | bool | 为真取全帧最大尺寸,为假使用手动宽高。True takes the largest frame size; false uses the manual width/height. |
InCellWidth / InCellHeight | int32 | 手动格子宽高(像素),使用时钳到至少 1。Manual cell width/height in pixels, clamped to at least 1 when used. |
bInAutoColumns | bool | 为真按 ceil(√总帧数) 取列数,为假使用 InColumns。True derives columns from ceil(√total frames); false uses InColumns. |
InColumns | int32 | 手动列数,使用时钳到至少 1。Manual column count, clamped to at least 1 when used. |
bInPowerOfTwo | bool | 是否把格子、列、行依次向上取到 2 的幂。Whether to round cell, columns and rows up to powers of two, in that order. |
InMaxAtlasSize | int32 | 图集宽高硬上限(像素)。Hard cap on atlas width/height in pixels. |
Out | FMassBattleATALayout& | 输出布局;入口先被重置。Output layout; reset on entry. |
Err | FString& | 失败原因(成功时不被写入)。Failure reason (not written on success). |
Output
返回是否解析成功。失败时 Err 给出可读原因(无帧、空帧、无源像素数据、帧超出格子、图集超过上限),Out 的内容不可用。无磁盘副作用。
Returns whether the layout resolved. On failure Err carries a readable reason (no frames, a null frame, no source pixel data, a frame exceeding the cell, an atlas over the cap) and Out is unusable. No disk side effects.
使用本资产自己的参数(Tracks、bAutoCellSize、CellWidth/CellHeight、bAutoColumns、Columns、bPowerOfTwo、MaxAtlasSize)调用上面的静态版本。用于「只看结果、不写字」的场合。
Calls the static version above with this asset's own parameters (Tracks, bAutoCellSize, CellWidth/CellHeight, bAutoColumns, Columns, bPowerOfTwo, MaxAtlasSize). Use it when you only want the result, not a write.
Input
| 参数Param | 类型Type | 说明Description |
|---|---|---|
Out | FMassBattleATALayout& | 输出布局。Output layout. |
Err | FString& | 失败原因。Failure reason. |
Output
返回是否解析成功;不修改本资产的任何字段。
Returns whether the layout resolved; no field of this asset is modified.
把布局结果写进资产:先算布局(失败则立即返回、不写任何字段),给每条已用轨道写回首帧格号 StartFrame;随后把 SpriteAnims 的八个桶重建为各 8 个空槽,再按轨道顺序把每条已用轨道放进它所属的(桶, 槽位),写入起始格号与帧数(帧数 = 该轨帧数组长度)。桶与槽位越界时被钳到合法范围,因此两条轨道指向同一(桶, 槽位)时,后写的一条覆盖先写的。最后写入 AtlasCols / AtlasRows。
Writes the layout result into the asset: the layout is computed first (on failure it returns immediately and writes nothing), each used track receives its first cell in StartFrame; then SpriteAnims' eight buckets are rebuilt as 8 empty slots each, and every used track is placed into its (bucket, slot) in track order with the start cell and frame count (frame count = that track's frame-array length). Bucket and slot are clamped into range, so when two tracks target the same (bucket, slot) the later one wins. Finally AtlasCols / AtlasRows are written.
Input
无参数(读取本资产的轨道与布局参数)。
No parameters (reads this asset's tracks and layout parameters).
Output
返回是否写入成功;失败时资产保持原样。副作用:改写每条已用轨道的 StartFrame、整体重建 SpriteAnims、写入网格列/行数。不创建纹理、不写像素。
Returns whether the write happened; on failure the asset is untouched. Side effects: rewrites StartFrame on every used track, rebuilds SpriteAnims wholesale, and writes the grid column/row counts. It creates no texture and writes no pixels.
统计区间表里的总帧数:遍历八个桶的 8 个槽,把每个槽的帧数相加(负值按 0 计)。它读的是 SpriteAnims(布局产物),不是轨道数组。
Counts the total frames in the range table: iterates the eight buckets' 8 slots and sums each slot's frame count (negatives count as 0). It reads SpriteAnims (the layout output), not the track array.
Input
无参数(BlueprintPure,可在蓝图里直接取)。
No parameters (BlueprintPure, callable straight from Blueprint).
Output
返回总帧数;区间表全空时返回 0。无副作用。
Returns the frame total, or 0 when the range table is empty. No side effects.
保存本资产所在的包。先把包标记为 dirty;包名不是合法的长包名时(瞬态资产,没有可保存的磁盘位置)直接返回成功。包没有完整载入时先补齐载入——补不齐会记一条 Error 并拒绝保存,因为未完整载入的包进 SavePackage 会让引擎报错甚至崩溃。随后补上 RF_Public | RF_Standalone 标志(SavePackage2 会检查顶层资产的标志),再按资产的包扩展名保存。
Saves this asset's package. The package is marked dirty first; when the package name is not a valid long package name (a transient asset with no on-disk home) it returns success immediately. A package that is not fully loaded is fully loaded first — if that cannot complete, it logs an Error and refuses to save, because feeding a partially loaded package to SavePackage makes the engine report a failure or crash. It then sets RF_Public | RF_Standalone (SavePackage2 checks the top-level asset's flags) and saves under the asset package extension.
Input
无参数。
No parameters.
Output
返回 SavePackage 的结果;无包或包无法完整载入时返回 false,瞬态包返回 true(无事可做)。副作用:标记 dirty、必要时补齐载入、设置资产标志、写盘。
Returns SavePackage's result; false when there is no package or it cannot be fully loaded, true for a transient package (nothing to do). Side effects: marks dirty, completes the load when needed, sets the asset flags and writes to disk.
管线角色Pipeline Role
本资产是 sprite 族的唯一输入面:作者在这里登记有序帧轨道,ApplyLayout 把布局结果写回轨道与区间表。烘侧通过 Creator 状态的 SpriteAsset 读它——sprite 复合烘焙要求它有 QuadMesh(每个 renderer 画这颗四边形),并用 MasterMaterial 为没有自带材质的版本建 MI_<名>_P<部件>_V<版本>;单位级帧区间则直接取它的 SpriteAnims。声明上,布局结果由 Sprite Prep 面板(推导区间)与 Generate(合成像素)共用,所以面板里看到的格子与最终图集的格子一致。
This asset is the sprite family's single authoring surface: tracks are registered here, and ApplyLayout writes the layout result back into the tracks and the range table. The bake reads it through the creator state's SpriteAsset — the sprite composite bake requires its QuadMesh (every renderer draws that quad) and uses its MasterMaterial to build MI_<name>_P<part>_V<version> for versions without their own material; the unit-level frame ranges come straight from its SpriteAnims. By declaration the layout result is shared by the Sprite Prep panel (deriving ranges) and Generate (compositing pixels), so the cells the panel shows and the final atlas cells always agree.
补充说明Notes
① 空轨既不占格也不进区间表:只有至少一帧的轨道参与布局,因此删空一条轨道不会在图上留下空位。② 帧绝不缩放:手动格子装不下某帧时布局直接失败,并指出是哪一帧、多大、格子多大——不会静默拉伸。③ 2 的幂会留下空格:格子/列/行依次上取整可能让 TotalCells 大于帧数,多余格子保持透明。④ 槽位容量每桶 8 个:桶与槽位越界会被钳制,两条轨道落到同一槽时后写的覆盖先写的。⑤ Save 只写包:它不创建图集纹理、也不改像素;图集内容来自 Generate。
① Empty tracks take no cell and no range: only tracks with at least one frame participate, so emptying a track leaves no hole in the sheet. ② Frames are never scaled: a frame that does not fit the manual cell fails the layout and names the frame, its size and the cell size — no silent stretch. ③ Power-of-two leaves spare cells: rounding cell/columns/rows up can make TotalCells exceed the frame count; the extra cells stay transparent. ④ Slot capacity is 8 per bucket: bucket and slot are clamped, and when two tracks land in the same slot the later write wins. ⑤ Save writes the package only: it creates no atlas texture and touches no pixels; the atlas content comes from Generate.