Mass Battle Frameworkv1.20.0

FBoneBatchPipeline

C++ Struct Shared Bootstrap

Source/MassBattle/Public/Rendering/MassBattleBoneBatchPipeline.h

概述Overview

所有批处理渲染器共用的骨骼管线引导。agent 渲染器与 FX 渲染器走的是同一条 VAT 骨骼通路:烘焙好的骨骼库由骨骼计算着色器解析成逐槽行,网格材质再读这些行。每条流的生命周期(一对被写入姿势的渲染目标 + 该库的布局数字)两边完全相同,而这正是随「武器拥有自己的骨架」不断长大的那一块——把它放在一处,是防止两条渲染管线互相漂移的手段:这里一旦分叉,表现就是「身体动了、武器不动」,排查代价很高。它刻意不接管材质与逐槽上传:这两块按渲染器不同,留在各自的所有者手里。

The bone-pipeline bootstrap shared by every batched renderer. The agent renderer and the FX renderer drive the same VAT bone path: a baked bone library is resolved into per-slot rows by the bone compute shader, and the mesh material reads those rows. The per-stream lifetime (a posed render-target pair plus the library's layout numbers) is identical on both sides, and it is the part that keeps growing as weapons gain their own rigs — keeping it in one place is what stops the two render pipelines from drifting apart: a divergence here shows up as "the body animates but the weapon does not", which is expensive to diagnose. It deliberately does not own materials or per-slot uploads: those differ per renderer and stay with their respective owners.

公开方法Public Methods

MakeBoneRenderTarget static UTextureRenderTarget2D*

分配一条流的姿势目标:一张 UTextureRenderTarget2D,实例槽占行、骨骼占列。分配后挂到 root,避免它在两帧之间被回收——姿势目标必须跨帧存活,否则下一帧读到的是空纹理。

Allocates one stream's posed target: a UTextureRenderTarget2D with instance slots as rows and bones as columns. It is rooted after creation so it survives between frames — the posed target must outlive a frame, otherwise the next frame reads an empty texture.

Input
参数Param类型Type说明Description
OuterUObject*新建渲染目标的外层对象(决定其生命周期归属与命名空间)。Outer for the created render target (decides ownership and namespace).
NumBonesint32骨骼数——纹理的列数,每根骨骼一列。Bone count — the texture's column count, one column per bone.
NumSlotsint32实例槽数——纹理的行数,每个实例槽一行。Instance slot count — the texture's row count, one row per slot.
Output

返回新建的渲染目标。副作用:对象被挂到 root,跨帧存活。

Returns the created render target. Side effects: the object is rooted and survives across frames.

InitStreamRuntime static bool

把一份烘焙库解析成可直接驱动的流:填入布局数字、校验骨骼纹理、分配四张渲染目标(位置 / 旋转,以及它们各自的上一帧)。库不可用时返回 false 且不修改 Out,让调用方记录精确原因,而不是驱动一条半初始化的流。

Resolves a baked library into a ready-to-drive stream: fills the layout numbers, validates the bone textures, and allocates the four render targets (position / rotation plus their previous frames). When the library is unusable it returns false and leaves Out untouched, so the caller can log a precise reason instead of driving a half-initialised stream.

Input
参数Param类型Type说明Description
OutFBoneStreamRuntime&要初始化的流运行时;成功时被填充,失败时保持不变。Stream runtime to initialize; filled on success, left unchanged on failure.
DataAssetUMassBattleATTDataAsset*烘焙库来源(MassBattleATTDataAsset.h)。Source of the baked library (MassBattleATTDataAsset.h).
OuterUObject*四张渲染目标的外层对象。Outer for the four render targets.
NumSlotsint32该流的实例槽数(决定渲染目标行数)。Instance slot count for this stream (decides the render targets' row count).
Output

成功返回 true;库不可用时返回 false 且不改动 Out。成功时的副作用:填充布局数字并分配四张渲染目标。

Returns true on success; returns false and does not touch Out when the library is unusable. On success the side effects are the filled layout numbers and the four allocated render targets.

管线角色Pipeline Role

调用方:agent 渲染器与 FX 渲染器在建立自己的逐流状态时各调用一次InitStreamRuntime,随后按同一份布局数字驱动骨骼计算着色器;MakeBoneRenderTarget 也可由需要单独一张姿势目标的路径直接调用。
数据来源:骨骼库来自 UMassBattleATTDataAsset(烘焙产物:骨骼位置 / 旋转纹理、骨骼数、每帧行数、包围盒)。
分叉的代价:两条渲染器共用这一份引导,任何一侧想改流生命周期都必须改这里——这正是避免「身体动、武器不动」的机制,不要在某一个渲染器里复制一份实现。

Callers: the agent renderer and the FX renderer each call InitStreamRuntime once while building their per-stream state, then drive the bone compute shader from the same layout numbers; MakeBoneRenderTarget is also callable directly by any path that needs one standalone posed target.
Data source: the bone library comes from UMassBattleATTDataAsset (bake output: bone position / rotation textures, bone count, rows per frame, bounding boxes).
Cost of a fork: both renderers share this one bootstrap, so any change to the stream lifetime has to happen here — that is exactly what prevents "body animates, weapon does not". Never copy the implementation into a single renderer.

补充说明Notes

① 四张渲染目标:位置与旋转各一对(当前帧 + 上一帧),共四张;它们的生命周期就是「一条流的生命周期」,因此与布局数字一起集中在本结构体管理。
② 失败要显式:InitStreamRuntime 失败时不写 Out,调用方必须检查返回值——忽略它即等于用一条半初始化的流继续绘制,这正是该返回值存在的理由。
③ 职责边界:材质与逐槽上传不在本结构体内。需要改动材质开关或上传方式时,改对应渲染器,不要改这里——改这里会让两条渲染器同时受影响。

① Four render targets: one pair for position and one for rotation (current frame plus previous frame), four in total; their lifetime is the stream's lifetime, which is why they are managed here together with the layout numbers.
② Failures are explicit: InitStreamRuntime does not write Out on failure, so callers must check the return value — ignoring it means continuing to draw with a half-initialised stream, which is exactly why the return value exists.
③ Responsibility boundary: materials and per-slot uploads are not in this struct. To change a material switch or an upload path, change the matching renderer — editing this struct would affect both renderers at once.