SMassBattleSpritePrepPanel
Source/MassBattleEditor/Public/SpritePrep/SMassBattleSpritePrepPanel.h
概述Overview
Sprite Prep 工具窗口:把逐动画轨的序列帧纹理打包成一张等分网格图集,并产出逐轨的(桶、槽位、起始格、帧数)元数据;随后一键回填 Agent Creator 的 Sprite 槽位。图集按行主序排格,每帧在自己的格子里居中放置、绝不缩放——sprite 材质只凭列/行数反算格子 UV,所以网格必须均匀铺满、格间没有额外内边距。
The Sprite Prep tool window: packs per-track sequences of texture frames into one uniform-grid atlas and produces per-track metadata (bucket, slot, start cell, frame count), then applies it to the Agent Creator's sprite slots in one click. Cells are row-major and each frame is centered inside its own cell, never scaled — the sprite material derives cell UV from columns/rows alone, so the grid must tile the atlas uniformly with no extra padding between cells.
窗口是非模态的可停靠工具标签:烘焙与回填是两步——Bake Atlas 只生成图集与元数据,Apply to Creator 才把结果写进 Creator。它不修改源纹理,也不参与运行时模拟。
The window is a non-modal dockable tool tab. Baking and applying are two separate steps — Bake Atlas produces the atlas and metadata, and Apply to Creator writes the result into the Creator. It never modifies source textures and takes no part in runtime simulation.
打开方式Opening the Window
标准路径是在 Agent Creator 里把 Tool Mode 切到 Sprite (Atlas),再点工作流入口行的 Open Atlas Baker…。也可以从 Window → Tools → Sprite Prep 直接打开。标签已存在时只聚焦现有标签,不重复开窗。
The standard path is to switch the Agent Creator Tool Mode to Sprite (Atlas) and press Open Atlas Baker… in the workflow entry row. You can also open it directly from Window → Tools → Sprite Prep. An existing tab is focused rather than duplicated.
从 Agent Creator 打开时,窗口在生成瞬间绑定当前 Creator 面板与状态,因此 Apply to Creator 能直接写入当前会话。单独从 Window 菜单打开、没有 Creator 时,烘焙与检查结果都照常,只是 Apply 会提示 Creator 状态已失效。若窗口已打开而 Creator 随后被关闭,Apply 同样会提示重新打开。
When opened from the Agent Creator, the window binds the live creator panel and state at spawn time, so Apply to Creator writes straight into the current session. Opened standalone from the Window menu with no creator, baking and inspecting results still work; only Apply reports that the creator state is unavailable. If the creator is closed after the window is open, Apply likewise asks for it to be reopened.
窗口布局Window Layout
| 区域Region | 内容Content | 说明Description |
|---|---|---|
| 轨道区Tracks area | Tracks 标题、+ Add Animation Track 按钮、轨道卡列表。A Tracks header, an + Add Animation Track button and the list of track cards. | 每条轨对应一个(桶、槽位)位;选中轨用绿色描边标出。空列表显示「No tracks」提示。Each track is one (bucket, slot) pair; the selected track gets a green outline. An empty list shows a "No tracks" hint. |
| 轨道卡Track card | 桶下拉、槽位下拉、帧数、Sort、Clear、红色 × 删除,以及序列帧放置区。Bucket combo, slot combo, frame count, Sort, Clear, a red × delete, and the frame drop zone. | 点卡片任意位置即选中该轨;放置区显示帧缩略图(带序号和逐帧 ×),空轨显示拖入提示。Clicking anywhere on a card selects that track; the drop zone shows frame thumbnails (numbered, each with its own ×), and an empty track shows a drop hint. |
| 参数区Parameters | Bake Parameters:Atlas Name、Output Path、Auto Cell Size 与手动宽高、Auto Columns 与手动列数、Power of Two、sRGB、Nearest Filter、Max Atlas Size。Bake Parameters: Atlas Name, Output Path, Auto Cell Size with manual width/height, Auto Columns with manual count, Power of Two, sRGB, Nearest Filter and Max Atlas Size. | 改动即时生效,日志区上方的实时布局摘要会立刻反映新的格子、网格与图集尺寸。Changes take effect immediately; the live layout summary above the log instantly reflects the new cell, grid and atlas dimensions. |
| 动作区Actions | Bake Atlas(主操作,双倍宽)与 Apply to Creator。Bake Atlas (primary, double width) and Apply to Creator. | Apply 在没有有效图集时不可点。Apply is disabled until a valid atlas exists. |
| 日志区Log dock | 固定的实时布局摘要 + 可滚动控制台。A pinned live layout summary plus a scrollable console. | 摘要格式为 Cell WxH | Grid CxR | Atlas WxH | Cells N (used F, T tracks);校验失败时同一位置直接显示第一条错误。日志显示最近 20 行并自动滚到最新。The summary reads Cell WxH | Grid CxR | Atlas WxH | Cells N (used F, T tracks); when validation fails, the first error is shown in that same spot. The log shows the last 20 lines and auto-scrolls to the newest. |
轨道与拖放Tracks and Drag-and-Drop
一条动画轨就是一个(桶, 槽位)位:桶来自八个枚举值,槽位为 0–7(运行时每个桶打包 8 个槽)。数组顺序即播放顺序,而这个顺序由资产名的数字感知自然排序决定——Frame2 会排在 Frame10 前面。要调整播放顺序就改帧资产的名字;删除帧或清空重拖后仍会按名称归位。
One animation track is one (bucket, slot) pair: the bucket comes from the eight enum values and the slot ranges 0–7 (the runtime packs 8 slots per bucket). Array order is playback order, and that order is the digit-aware natural sort of asset names — Frame2 precedes Frame10. To change playback order, rename the frame assets; removing frames or clearing and re-dropping still snaps them back to name order.
只能拖入内容浏览器里的 UTexture2D 资产,多选可以一次拖入;已在轨内的同一资产会被跳过,不会重复。拖到某条轨的放置区就追加到该轨;拖到窗口其它位置则进入当前选中轨,没有选中轨时进入最后一条轨,一条轨都没有时自动新建一条。
Only UTexture2D assets from the Content Browser can be dropped, and a multi-selection can be dropped at once; an asset already on the track is skipped rather than duplicated. Dropping onto a track's drop zone appends to that track; dropping anywhere else in the window targets the selected track, falls back to the last track when nothing is selected, and creates a track automatically when none exist.
| 操作Control | 行为Behavior |
|---|---|
| + Add Animation Track | 追加一条轨道,默认落到第一个还有空槽的桶与槽位(槽位 0–7);新轨自动成为选中轨。Appends a track, defaulting to the first bucket and slot that still has a free slot (0–7); the new track becomes the selected one. |
| 桶下拉Bucket combo | 选择该轨烘焙进的目标动画桶。Idle / Move 作为循环底轨,其余桶按一次性蒙太奇使用。Selects the target animation bucket this track bakes into. Idle / Move act as looping base tracks; the remaining buckets are used as one-shot montages. |
| 槽位下拉Slot combo | 选择桶内槽位 0–7。Selects the slot inside the bucket, 0–7. |
| Sort | 按资产名重新自然排序,数字段按数值比较。Re-sorts by asset name naturally, comparing digit runs by value. |
| Clear | 清空该轨全部帧,轨道本身保留。Removes every frame from the track while keeping the track itself. |
| 红色 ×Red × | 标题条的 × 删除整条轨;帧缩略图上的 × 只删除该帧。The × in the header deletes the whole track; the × on a frame thumbnail removes only that frame. |
烘焙参数Bake Parameters
| 参数Parameter | 默认Default | 对图集的影响Effect on the Atlas |
|---|---|---|
| Atlas Name | SpriteAtlas |
生成的图集资产名。打开窗口时若 Creator 已填 AssetName,则用它播种;烘焙前会做路径安全清理。Asset name of the baked atlas. Seeded from the creator's AssetName when already set; sanitized for path safety before baking. |
| Output Path | /Game |
图集资产所在的内容路径。打开时从 Creator 的 GeneratePath 播种;必须是合法的长包名,否则拒绝烘焙。Content path for the atlas asset. Seeded from the creator's GeneratePath; it must be a valid long package name or the bake is refused. |
| Auto Cell Size | 开启On | 开启时格子 = 全部帧的最大宽高;关闭后使用手动 Cell W / Cell H。帧绝不缩放,放不进格子的帧会让整次烘焙失败。On: cell = the largest frame width/height across all frames. Off: use manual Cell W / Cell H. Frames are never scaled, and any frame that does not fit fails the whole bake. |
| Cell W / Cell H | 128 / 128 |
仅 Auto Cell Size 关闭时生效,面板内范围 1–4096 像素。每帧在格内居中,空白处透明。Used only when Auto Cell Size is off; the panel clamps them to 1–4096 pixels. Each frame is centered in its cell, with transparent padding. |
| Auto Columns | 开启On | 开启时列数 = ⌈√总帧数⌉;关闭后使用手动列数。行数 = ⌈总帧数 / 列数⌉,所以最后一个可能不是整行。On: columns = ⌈√(total frames)⌉. Off: use the manual count. Rows = ⌈total frames / columns⌉, so the last row may be partially filled. |
| Columns | 8 |
仅 Auto Columns 关闭时生效,面板内范围 1–128。Used only when Auto Columns is off; the panel clamps it to 1–128. |
| Power of Two | 开启On | 把格子宽高、列数、行数依次向上取到 2 的幂,图集宽高因此也是 2 的幂;代价是可能留下空格子。Snaps cell width/height, then columns, then rows up to powers of two, so the atlas width/height are powers of two too; the cost is potentially unused cells. |
| sRGB | 开启On | 把图集标记为 sRGB 颜色数据(默认压缩设置);关闭后按掩码/线性数据压缩。Marks the atlas as sRGB color data (default compression); off compresses it as mask/linear data. |
| Nearest Filter | 开启On | 点采样,帧像素锐利无插值;关闭则使用默认过滤。图集始终不生成 mipmap。Point filtering keeps frame pixels crisp with no interpolation; off uses default filtering. The atlas never generates mipmaps. |
| Max Atlas Size | 4096 |
图集宽和高的硬上限,面板内范围 256–16384 像素。任一维超出即拒绝整次烘焙,不裁剪也不自动缩格子。Hard cap on atlas width and height, clamped by the panel to 256–16384 pixels. Either dimension exceeding it refuses the whole bake; nothing is cropped and no cell is auto-shrunk. |
图集尺寸如何确定How the Atlas Size Is Derived
烘焙前先做一次布局计算:跳过没有帧的轨道,把其余轨道的帧按轨道顺序首尾相接(轨道顺序就是格号顺序),总帧数决定列与行;格子尺寸决定每格像素;两者相乘得到图集宽高。开启 Power of Two 时,格子、列、行都会先向上取 2 的幂,再把乘积与 Max Atlas Size 比较。任何一维超过上限,整次烘焙直接失败。
A layout pass runs before baking: tracks with no frames are skipped, the remaining tracks' frames are concatenated in track order (track order is cell order), and the total frame count determines columns and rows; the cell size determines pixels per cell; the product gives the atlas width and height. With Power of Two on, cell size, columns and rows are first snapped up to powers of two, then the product is compared with Max Atlas Size. If either dimension exceeds the cap, the bake fails outright.
图集尺寸不是唯一会被拒绝的情况:手动格子小于某一帧、帧资产被删或没有源像素数据、输出路径非法,也都会在创建任何资产之前中止,并把原因写到日志与实时摘要。没有帧时同理——先加轨再拖纹理。
Atlas size is not the only rejection case: a manual cell smaller than a frame, a deleted frame asset or one without source pixels, and an invalid output path all abort before any asset is created, with the reason written to the log and the live summary. The same goes for having no frames at all — add a track and drop textures first.
Bake Atlas 与Apply to Creator Bake Atlas and Apply to Creator
烘焙图集Bake Atlas
Bake Atlas 先计算并校验布局,然后创建一张透明底图集:每帧按行主序放进自己的格子并居中,像素原样拷贝、不缩放、不插值。成功后在 Output Path 下创建(或原位更新)以 Atlas Name 命名的纹理资产,同时写入结果:图集纹理、列数、行数,以及每条有帧轨道的起始格号。日志会给出图集尺寸、格子尺寸、网格尺寸,以及逐轨的「起始格 + 帧数」;最后提示用 Apply to Creator 回填。
Bake Atlas first computes and validates the layout, then creates a transparent-based atlas: each frame goes into its row-major cell, centered, with pixels copied verbatim — no scaling, no interpolation. On success it creates (or updates in place) the texture asset named by Atlas Name under Output Path and records the results: atlas texture, columns, rows, and the start cell of every track that has frames. The log reports atlas, cell and grid dimensions plus per-track "start cell + frame count", then points to Apply to Creator.
烘焙只写图集与烘焙结果,不改 Creator。重复烘焙同一名称与路径时,已有纹理资产会原地重新初始化,已指向它的材质实例与渲染器保持引用不变;若名称或路径不同,则生成一张新图集。
Baking writes only the atlas and the bake results; it does not touch the Creator. Re-baking the same name and path re-initializes the existing texture asset in place, so material instances and renderers already pointing at it keep their references; a different name or path produces a new atlas.
回填Creator Apply to Creator
Apply to Creator 把烘焙结果写进当前 Creator 的 Sprite 槽位:设置图集纹理、Atlas Cols 与 Atlas Rows;随后重建全部八个桶的槽位数组(每个桶 8 个槽),因此任何手工编辑过的帧区间都会被本次烘焙结果覆盖;最后逐条把有帧轨道的起始格号与帧数写入对应(桶, 槽位),并刷新 Creator 的详情视图。
Apply to Creator writes the bake result into the live creator's sprite slots: it sets the atlas texture, Atlas Cols and Atlas Rows, then rebuilds all eight buckets' slot arrays (8 slots per bucket), so any hand-edited frame ranges are replaced by this bake's result; finally it writes each non-empty track's start cell and frame count into its (bucket, slot) and refreshes the creator's details view.
回填不会自动生成资产。完成后在 Creator 里点 Generate(Sprite 模式)才会创建渲染器、数据资产与材质实例。图集是源资产:Creator 的 Batch Rename 不会重命名它。
Applying does not generate assets by itself. Back in the Creator, press Generate in Sprite mode to create the renderer, data asset and material instance. The atlas is a source asset: the creator's Batch Rename never renames it.
可撞上的校验与边界Validation and Boundary Errors
布局校验错误会同时写入日志区与实时摘要,烘焙阶段(读像素、建纹理)的错误写入日志区;两者都不会弹模态窗。每条信息给出原因或下一步方向,照做即可继续。
Layout validation errors go to both the log dock and the live summary, while bake-stage errors (reading pixels, creating the texture) go to the log dock; neither ever opens a modal dialog. Each message gives the cause or the next step to take.
| 症状Symptom | 日志Log message | 处理Fix |
|---|---|---|
| 一条轨都没有,或全部轨道为空No tracks, or every track empty | Bake: no frames — add a track and drop textures onto it |
先加轨并拖入纹理。Add a track and drop textures. |
| 帧资产被删除A frame asset was deleted | Bake: a frame resolved to null (deleted asset?) |
删掉空帧或替换资源。Remove the empty frame or replace the asset. |
| 纹理没有源像素数据Texture has no source pixels | Bake: <name> has no source pixel data |
换用带源图的纹理资源。Use a texture with source image data. |
| 手动格子小于某一帧Manual cell smaller than a frame | Bake: frame <name> (WxH) exceeds the WxH cell — raise the manual cell size or use auto |
调大 Cell W / Cell H,或打开 Auto Cell Size。帧不会被缩放。Raise Cell W / Cell H, or turn on Auto Cell Size. Frames are never scaled. |
| 图集宽或高超过上限Atlas width or height exceeds the cap | Bake: atlas WxH exceeds the N cap — lower cell size, more columns, or raise the cap |
减小格子、增加列数,或上调 Max Atlas Size(≤ 16384)。Shrink the cell, add columns, or raise Max Atlas Size (≤ 16384). |
| 图集名或路径非法Invalid atlas name or path | Bake: invalid atlas name or output path |
填写合法的资产名与内容路径(如 /Game/MyDir/Gen_MySprite)。Enter a valid asset name and content path (e.g. /Game/MyDir/Gen_MySprite). |
| 读取某帧像素失败Reading a frame's pixels fails | Bake: failed to read <name> pixels — abort |
检查该纹理资源能否正常打开并重新导入。Check that the texture opens correctly and re-import it. |
| 纹理资产创建失败Texture asset creation fails | Bake: texture creation failed |
确认输出目录可写后重试。Confirm the output folder is writable and retry. |
| 尚未烘焙就点 ApplyApply before any bake | Apply: nothing baked yet |
先点 Bake Atlas。Press Bake Atlas first. |
| 从未绑定 Creator(从 Window 菜单单独打开)Never bound to a creator (opened standalone from the Window menu) | Apply: creator state is gone (panel closed?) |
先打开 Agent Creator,再从它的 Open Atlas Baker… 重新打开烘焙器。Open the Agent Creator first, then reopen the baker from its Open Atlas Baker…. |
| Creator 已关闭Creator is closed | Apply: creator panel is closed — reopen it and apply again |
重新打开 Agent Creator,再点 Apply。Reopen the Agent Creator and apply again. |
对外接口Public Surface
| 成员Member | 类型Type | 说明Description |
|---|---|---|
Construct | void | 创建烘焙器状态对象、从 Creator 播种输出标识、装配轨道/参数/动作/日志区。Creates the baker state, seeds output identity from the creator, and assembles the tracks, parameters, actions and log areas. |
ExtractDroppedTextures | static bool | 从内容浏览器拖放载荷中提取 UTexture2D 资产;非资产拖放或没有纹理时返回 false。Extracts UTexture2D assets from a Content Browser drag payload; returns false for non-asset drags or drags with no textures. |
OnDrop | virtual FReply | 窗口级放置:把纹理追加到选中轨(无选中则最后一条,无轨道则新建一条)。Window-level drop: appends textures to the selected track (the last one if none is selected, a new track if none exist). |
管线角色Pipeline Role
烘焙器由 Agent Creator 的 Open Atlas Baker… 打开(也可从 Window → Tools 单独打开),是一个可停靠工具标签。它把结果写进 UMassBattleSpritePrepState 的轨道与结果字段,再由 Apply to Creator 转写进 Creator 的 Sprite 槽位;Creator 之后在 Sprite 模式下 Generate,才会把图集与帧区间装配成渲染器、数据资产与材质实例。运行时模拟不读取烘焙器本身,只读取 Creator 产出的资产。
The baker is opened from the Agent Creator via Open Atlas Baker… (or standalone from Window → Tools) as a dockable tool tab. It writes into the tracks and result fields of UMassBattleSpritePrepState, and Apply to Creator then transfers them into the creator's sprite slots; only a later Generate in Sprite mode assembles the atlas and frame ranges into a renderer, data asset and material instance. The runtime simulation reads none of the baker itself — only the assets the creator produces.
补充说明Notes
① 网格契约:图集必须被列 × 行均匀铺满,格间没有额外内边距;帧在格内居中,四周以透明像素填充。② 没有帧的轨道完全跳过,不占格号,也不产生元数据;只有有帧的轨道参与布局与回填。③ 起始格号是烘焙输出,不能在面板里手改;播放顺序只由轨道顺序与资产名的自然序决定。④ 若两条有帧轨道指向同一个(桶, 槽位),回填按轨道顺序写入,后写的覆盖先写的——请为每条轨保留唯一的桶/槽位组合。⑤ 日志最多保留 200 行,界面显示最后 20 行。
① Grid contract: the atlas must be tiled uniformly by columns × rows with no extra padding between cells; frames are centered and padded with transparent pixels. ② Tracks without frames are skipped entirely — they consume no cell index and produce no metadata, so only non-empty tracks participate in layout and apply. ③ The start cell is bake output and cannot be edited in the panel; playback order comes only from track order and the natural order of asset names. ④ If two non-empty tracks target the same (bucket, slot), apply writes them in track order and the later one wins — keep a unique bucket/slot pair per track. ⑤ The log keeps at most 200 lines and the UI shows the last 20.