Mass Battle Frameworkv1.20.0

MassBattleAssemblyCompositeBake.h

C++ Class ×1 Nested Struct ×1

Source/MassBattleEditor/Public/UnitAssembly/MassBattleAssemblyCompositeBake.h

概述Overview

多部件(assembly)单位的复合烘焙:输入是一个 assembly 模板类,输出是「一套能按组合切换部件版本的完整单位」——每个部件的每个版本各自烘一份 VAT 几何与材质,Niagara 侧被重建成「一个部件一个 emitter、一个版本一个只画一个网格的 renderer」,渲染器蓝图携带组合配方,运行时按 agent 推送部件标签即可让每个部件显示出所属版本。它只处理一个模板,不做单网格 quickpath。

The composite bake for multi-part (assembly) units: it takes one assembly template class and produces a complete unit that can switch part versions per combination — every version of every part gets its own VAT geometry and materials, the Niagara side is rebuilt as "one emitter per part, one single-mesh renderer per version", and the renderer Blueprint carries the combination recipe so that pushing a per-part tag at runtime makes each part show its own version. It handles one template only; the single-mesh quickpath is not its job.

消费的内容来自模板:部件(名字、类型、父部件名、挂接 socket、部件变换、烘焙组名)、版本(版本名、源网格、版本变换)、组合(逐部件的版本选择,外加可选的随机参与文本)。产出包括逐版本的 VAT 数据资产与静态网格、挂件的刚体骨骼网格、重建后的 NS、渲染器蓝图,以及一份最终 AgentConfig。整条路线只用骨骼模式:Vertex 子模式是 VAT Standard 的逐 LOD 特性,复合烘焙会把所有版本的所有 LOD 强制成骨骼。

What it consumes comes from the template: parts (name, type, parent part name, attach socket, part transform, bake-group name), versions (version name, source mesh, version transform) and combinations (a version selection per part, plus optional random-membership text). What it produces: per-version VAT data assets and static meshes, rigid skeletal meshes for attachments, a rebuilt NS, a renderer Blueprint and a final AgentConfig. The whole route is bone-only — Vertex is a VAT Standard per-LOD feature; the composite bake forces every LOD of every version to bone.

烘焙组改变槽道划分:同名的部件合成一条槽道(一个 emitter),组内每个在组合里出现过的版本元组各合并成一份网格、占一个 renderer;未打组的部件仍各占一条槽道、每个版本一个 renderer。合并只合几何——合并网格的材质槽是成员槽的串接,不合并,所以每个源 section 仍拿自己的材质与骨骼参数。渲染器 CDO 上的 NumGroupSlots 是槽道数、SlotCombinationMap 是「组合 × 槽道」的推送值表。

Bake groups change the lane split: same-name parts form one lane (one emitter), and every version-tuple that appears in a combination is merged into one mesh occupying one renderer; ungrouped parts keep their own lane with one renderer per version. Only geometry is merged — the merged mesh's material slots are the concatenation of its members' slots and are never merged, so every source section keeps its own material and bone params. On the renderer CDO, NumGroupSlots is the lane count and SlotCombinationMap is the combination × lane push-value table.

FResult struct

一次复合烘焙的结果摘要。失败时除 bOk 为 false 外全部保持默认值,具体原因在 creator 日志里。

Summary of one composite bake. On failure everything except bOk stays at its default and the reason is in the creator log.

成员变量Members

名称Name类型Type默认值说明Description
bOkboolfalse是否整套烘成。为 true 时渲染器蓝图、NS 与最终 AgentConfig 都已装配并写进状态。Whether the whole bake succeeded. When true the renderer Blueprint, the NS and the final AgentConfig are assembled and written into the state.
RendererClassUClass*nullptr新建的渲染器蓝图类(Renderer_<基名>)。The new renderer Blueprint class (Renderer_<base>).
NSUNiagaraSystem*nullptr由模板复制并重建后的 Niagara 系统(NS_<基名>),已是部件/版本结构且自包含。The duplicated and rebuilt Niagara system (NS_<base>), already in part/version structure and self-contained.
NumCombinationsint320烘焙时模板里的组合数,也是渲染器配方表的行数。The template's combination count at bake time — also the row count of the renderer's recipe table.

公开方法Public Methods

ResolveTemplateClass static UClass*

把「拖进模板槽的东西」解析成类:蓝图资产取其生成类(蓝图未编译过则为空),Actor 实例取其类,类本身原样返回,其它类型返回空。它不做类型校验——是不是 assembly 模板由调用方检查,因此槽里放一个普通 Actor 蓝图能解析出类、但会在后续烘焙里被拒。

Resolves "whatever was dropped into the template slot" into a class: a Blueprint asset yields its generated class (null if never compiled), an actor instance yields its class, a class is returned as-is, anything else yields null. It performs no type check — whether the class actually is an assembly template is the caller's job, so a plain Actor Blueprint resolves to a class and is then rejected by the bake itself.

Input
参数Param类型Type说明Description
InTemplateObjectUObject*模板槽里的对象:蓝图资产、Actor 实例或类。可为空。The object in the template slot: Blueprint asset, actor instance or class. May be null.
Output

返回解析出的类;无法解析(空指针、未编译蓝图、其它类型)时返回 nullptr。无副作用。

Returns the resolved class, or nullptr when it cannot be resolved (null pointer, uncompiled Blueprint, other types). No side effects.

ParseMembership static bool

解析一个部件的随机参与文本为允许的版本下标集合。语法:逗号分隔的项,all(或空文本)= 全部版本,none = 空集,N = 单个版本,N-M = 闭区间(写反了自动交换)。越界不报错:区间端点被静默钳到 [0, 版本数),单个越界值被直接丢弃。容忍全角逗号、顿号、空格与制表符。任一项无法解析则整段失败——所以在 assembly 模板里填错会立刻在烘焙时被点名,而不是烘到一半才发现。

Parses one part's random-membership text into the allowed version indices. Grammar: comma-separated items — all (or empty text) = every version, none = empty set, N = one version, N-M = inclusive range (reversed bounds are swapped). Out-of-range values never fail: range endpoints are clamped silently into [0, version count), and a single out-of-range value is dropped. Full-width commas, enumeration commas, spaces and tabs are tolerated. Any unparseable item fails the whole parse — so a typo in the assembly template is named immediately at bake time instead of halfway through a bake.

Input
参数Param类型Type说明Description
Textconst FString&该部件的参与文本(如 0,2,5-7 / all / none)。That part's membership text (e.g. 0,2,5-7 / all / none).
NumVersionsint32该部件的版本数,决定合法下标范围;≤0 时任何参与都是空集。Version count of that part, bounding valid indices; ≤ 0 makes every membership the empty set.
OutAllowedTArray<int32>&输出集合,进入前先清空;重复的版本号只保留一次。Output set, cleared on entry; duplicate version indices appear only once.
Output

返回是否解析成功。失败时 OutAllowed 的内容没有意义(已解析的前几项可能留在里面),调用方必须丢弃它。

Returns whether parsing succeeded. On failure OutAllowed is meaningless (items parsed so far may remain), so the caller must discard it.

Generate static FResult

整套复合烘焙,按以下顺序推进——任一门禁失败即中止并返回未成功的结果:

The whole composite bake, advancing in this order — any failed gate aborts and returns an unsuccessful result:

  1. 门禁:模板类要能取到默认对象;模板至少要有一个捕获的组合(0 个时提示去 Unit Assembly 面板录制);组合数不得超过 255(运行时组合下标是 8 位);Creator Profile 与 NS 模板都要在。Gates: the template class must yield a default object; at least one captured combination is required (zero tells you to capture one in the Unit Assembly panel); combinations must not exceed 255 (the runtime combination index is 8-bit); the Creator Profile and its NS template must both be set.
  2. 随机参与预解析:把每张随机卡的逐部件参与文本在烘焙前全部解析完,一张卡只占配方表的一行,运行时再逐 agent 展开;尾部缺失的部件按 all 处理。Random-membership pre-parse: every random card's per-part text is parsed before any expensive work — one card occupies a single recipe row and expands per agent at runtime; missing tail parts read as all.
  3. 命名与目录:以模板类名去 BP_ 前缀作为基名,GeneratePath 为空时默认为 /Game/Gen_<基名>;之后的资产名都由基名派生。Naming and folders: the base name is the template class name minus the BP_ prefix; an empty GeneratePath defaults to /Game/Gen_<base>, and every later asset name derives from that base.
  4. 挂件刚体预扫:每个挂件版本在父件的骨骼网格上解析 socket 对应的骨(无 socket 则用根骨、单位偏移),把源网格冻结并按「socket 绑定姿势 × 部件/版本合成位姿」摆好,再以 100% 权重刚体绑定到那根骨,得到一张会跟着 socket 走的骨骼网格。父件名解析不到、父件没有骨骼网格、骨不在骨架上都直接中止。Rigid attachment pre-pass: for each attachment version, resolve the socket's bone on the parent's skeletal mesh (no socket → root bone with identity offset), freeze the source mesh at "socket bind pose × combined part/version pose" and rigid-bind it 100% to that bone, yielding a skeletal mesh that follows the socket. An unresolvable parent name, a parent without a skeletal mesh, or a bone missing from the skeleton aborts immediately.
  5. 逐版本烘焙:每个唯一的源网格只烘一次(部件版本与刚体产物共用这条路径):补齐 LOD、查找贴图、强制骨骼模式,然后依次转换静态网格与材质实例、建数据资产、建 VAT 纹理、烘焙动画。逐版本的 AgentConfig 被刻意抑制,只留最终一份。Per-version bake: each unique source mesh is baked once (part versions and rigid products share this path): complete the LODs, find textures, force bone mode, then convert the static mesh and material instances, create the data asset, create VAT textures and bake the animation. Per-version AgentConfigs are deliberately suppressed; only the final one is real.
  6. 骨骼库共享:首个成功的烘焙作供体,其余版本先校验骨架、骨数、帧数与每帧行数完全一致,再改指供体的骨骼纹理与包围盒,从而只在内存里留一份骨骼库。任一项不一致即整体中止——每批只有一张解算骨表,混合不同的骨骼流会解错位。Bone-library sharing: the first successful bake becomes the donor; every other version is validated to share the skeleton, bone count, frame count and rows-per-frame before relinking to the donor's bone textures and bounding box — one bone library in memory instead of one per version. Any mismatch aborts the whole bake: one batch has one solved bone table, so mixing different bone streams would decode wrong.
  7. NS 重建:复制模板为 NS_<基名>,汇总每个 (部件, 版本) 要画的那一个网格与逐 section 材质,并经 槽位桥接 的 BuildPartVersionStructure 重建成「部件 emitter / 版本 renderer / 唯一骨骼参数」结构;结构失败即中止。NS rebuild: duplicate the template into NS_<base>, collect the one mesh each (part, version) draws plus its per-section materials, and rebuild through the slot bridge's BuildPartVersionStructure into "part emitters / version renderers / unique bone params"; a structural failure aborts.
  8. 配方与渲染器 CDO:把组合表压成「组合 × 部件」的推送值数组(值为版本下标 +1,0 表示隐藏),随机卡另存允许下标表;复制渲染器模板为 Renderer_<基名>,先设类默认属性(编译会重建 CDO),再写入组合数、部件槽数、两份配方表、共享骨骼数据资产与逐 (部件, 版本) 的材质集。Recipe and renderer CDO: compress the combinations into a "combination × part" array of pushed values (version index + 1; 0 hides), with the random cards' allowed indices stored alongside; duplicate the renderer template into Renderer_<base>, apply class defaults first (compiling rebuilds the CDO), then write the combination count, part-slot count, both recipe tables, the shared bone data asset and the per-(part, version) material sets.
  9. 最终 AgentConfig:用基名与共享 LOD 设置单独创建一份 AgentConfig,并指向新渲染器类。Final AgentConfig: create one AgentConfig under the base name with the shared LOD settings, pointing at the new renderer class.
Input
参数Param类型Type说明Description
SUMassBattleAgentCreatorState&Creator Profile、搜索/生成路径、动画桶;烘焙结束后写入 NSAsset、RendererInstance、StaticMesh 与 AgentConfigDataAsset。Creator Profile, search/generate paths and animation buckets; after the bake it receives NSAsset, RendererInstance, StaticMesh and AgentConfigDataAsset.
Pconst FMassBattleAgentCreatorParams&烘焙参数;逐版本烘焙时把「创建 AgentConfig」强制关掉,避免每个版本都产出一份。Bake parameters; the per-version passes force "create AgentConfig" off so no version produces its own.
InTemplateClassUClass*assembly 模板类(由 ResolveTemplateClass 得到)。必须是模板 Actor 的子类,否则在门禁处失败。The assembly template class (from ResolveTemplateClass). It must derive from the template actor or the gates reject it.
Output

返回 FResult:是否成功、渲染器类、NS、组合数。副作用:在磁盘上创建逐版本的静态网格、材质实例、VAT 纹理与数据资产、挂件刚体骨骼网格、NS 与渲染器蓝图,并改写状态里的四个产物字段;进度与失败原因写入 creator 日志(Generate 会把它流进进度对话框)。

Returns FResult: success flag, renderer class, NS and combination count. Side effects: creates per-version static meshes, material instances, VAT textures and data assets, the rigid attachment skeletal meshes, the NS and the renderer Blueprint on disk, and writes the four artifact fields in the state; progress and failure reasons go to the creator log (Generate streams them into the progress dialog).

管线角色Pipeline Role

唯一的生产调用点是 FMassBattleAgentCreatorCore::Generate:当工具模式为 VAT Advanced 且模板槽里确实是模板蓝图时,它先用 ResolveTemplateClass 取类、确认是模板 Actor 的子类,再调用这里的 Generate。本烘焙反过来大量复用 MassBattleAgentCreatorCore 的单步原子函数(LOD/贴图查找、网格与材质、数据资产、VAT 纹理、动画烘焙)逐版本派生,因此单部件 agent 与多部件 agent 的资产形态一致。结构与参数由 MassBattleAssemblySlotBridge 落地;运行时的部件切换读渲染器 CDO 上的配方表与逐 (部件, 版本, section) 骨骼材质参数。

The only production call site is FMassBattleAgentCreatorCore::Generate: when the tool mode is VAT Advanced and the template slot really holds a template Blueprint, it resolves the class with ResolveTemplateClass, confirms the class derives from the template actor, then calls Generate here. This bake in turn reuses MassBattleAgentCreatorCore's atomic steps (LOD/texture discovery, mesh and materials, data assets, VAT textures, animation bake) per version, which is why single-part and multi-part agents end up with the same asset shape. Structure and parameters are installed by MassBattleAssemblySlotBridge; runtime part switching reads the recipe table on the renderer CDO plus the per-(part, version, section) bone material parameters.

补充说明Notes

① 上限:组合数上限 255;部件数上限 16(结构构建器按桥接的 16 槽上限拒收,超出时整次烘焙失败)。② 位姿落点:body 部件的「部件变换 × 版本变换」写进该版本 renderer 的网格条目(渲染根空间,整块部件一起动);挂件的同类位姿是 socket 相对的,被烘进刚体几何,条目上只带从父件继承的部件级偏移。③ 随机卡:一张卡只占组合表里的一个条目、也就是配方表的一行,逐 agent 在运行时按允许集掷出版本,所以 255 这个上限管的是组合表条目数,而不是随机卡能展开出的具体版本组合数。④ 失败即中止:任何门禁、刚体绑定或骨骼流校验失败都会中止整套烘焙,而不是留下部分可用的单位——日志里会指明是哪一步、哪个部件。

① Limits: at most 255 combinations; at most 16 parts (the structure builder enforces the bridge's 16-slot ceiling, and exceeding it fails the whole bake). ② Where poses land: a body part's "part transform × version transform" goes into that version's renderer mesh entry (render-root space, so the whole part moves together); an attachment's equivalent pose is socket-relative and is baked into its rigid geometry, leaving only the inherited part-level offset on the entry. ③ Random cards: one card occupies a single entry in the combination list, i.e. one recipe row, and rolls a version per agent from its allowed set at runtime — so the 255 cap counts combination-list entries, not the concrete version combinations a card can expand into. ④ Failures abort: any gate, rigid-bind or bone-stream mismatch stops the whole bake rather than leaving a partly usable unit, and the log names the step and the part.