Mass Battle Frameworkv1.20.0

MassBattleBoneQuery.h

USTRUCT ×2 C++ API

Source/MassBattle/Public/Ragdoll/MassBattleBoneQuery.h

概述Overview

面向单个 agent 已烘物理资产的骨骼级查询(C++ 接口)。查询入口都在调用那一刻按当前动画状态给该单位的已烘布娃娃刚体摆一次姿态,然后在这些刚体形状上做重叠或射线测试,返回逐刚体的世界空间结果。它只在被调用的瞬间工作:没有任何东西逐 tick 运行、不写进任何 fragment、不进快照、也不进哈希——因此命中判定由你的玩法代码决定,模拟状态不受查询影响。骨骼姿态与刚体形状的唯一来源是烘焙进资产的只读数据(见 MassBattleRagdollTable.h)。

Bone-level queries against one agent's baked physics asset (C++ interface). The query entry points pose the unit's baked ragdoll bodies from the current animation state at the instant of the call, then shape-test those bodies by overlap or ray and return per-body world-space results. It works only for the moment it is called: nothing runs per tick, nothing is written into a fragment, and nothing enters the snapshot or the hash — so hit judgement stays in your gameplay code and the simulation is never affected by a query. The single source of bone poses and body shapes is the read-only bake carried by the asset (see MassBattleRagdollTable.h).

FAgentBodyPose USTRUCT

一个已摆好姿态的刚体:它在世界系里的形状、朝向与尺寸。

One posed body: its shape, orientation and size in world space.

成员变量Members

名称Name类型Type默认值说明Description
BodyIndexint32INDEX_NONE该单位已烘刚体数组中的下标。Index into the unit's baked body array.
BoneIndexint32INDEX_NONE该刚体所属的骨骼索引(按网格参考骨架)。Mesh reference-skeleton bone index this body belongs to.
BoneNameFName—该刚体的骨骼名,运行期无需加载骨架即可读。Bone name of the body; readable at runtime without loading a skeleton.
ShapeKinduint80烘焙出的形状种类:0 球、1 胶囊、2 盒、3 凸包或锥形形状的胶囊近似。Baked shape kind: 0 sphere, 1 capsule, 2 box, 3 capsule approximation of a convex or tapered shape.
CenterFVectorZeroVector查询那一刻形状中心的世界坐标。Shape centre in world space at the instant of the query.
RotationFQuatIdentity形状的世界朝向;胶囊的轴向是它本地坐标系的 Z 轴。Shape rotation in world space; a capsule's axis is this rotation's local Z.
Radiusfloat0.f球/胶囊半径的世界尺寸,已乘上姿态缩放与实体缩放。Sphere/capsule radius in world space, already scaled by the pose and the entity.
HalfLengthfloat0.f胶囊线段半长的世界尺寸;球为零。Capsule segment half length in world space; zero for a sphere.
ExtentsFVectorZeroVector盒的半边尺寸(世界系,已乘缩放)。Box half extents in world space, already scaled.

FAgentBoneHit USTRUCT

一个已摆姿态的刚体对查询给出的答案:命中的刚体与骨骼、形状上的最近点,以及有符号距离。

One posed body's answer to a query: the hit body and bone, the closest point on the shape, and the signed distance.

成员变量Members

名称Name类型Type默认值说明Description
BodyIndexint32INDEX_NONE该单位已烘刚体数组中的下标。Index into the unit's baked body array.
BoneIndexint32INDEX_NONE该刚体所属的骨骼索引(按网格参考骨架)。Mesh reference-skeleton bone index this body belongs to.
BoneNameFName—该刚体的骨骼名。Bone name of the body.
HitLocationFVectorZeroVector刚体形状上的最近点;射线查询时是进入点。Closest point on the body shape; for a ray, the entry point.
Distancefloat0.f有符号的最近距离:负值表示已穿透;射线查询时是到起点的距离。Signed closest distance: negative means penetration; for a ray, the distance from the start point.
DistanceSqfloat0.f距离的平方,便于排序的现成键。Distance squared, the convenience sort key.

公开方法Public Methods

ResolveBoneLibrary static UMassBattleATTDataAsset*

解析该 agent 骨骼烘焙所在的运行时资产:优先取已注册渲染器持有的资产,其次取 FVisualize 渲染器类 CDO 上的资产——专用服不生成渲染器 actor,而 CDO 仍然带着烘焙资产,所以专用服上的查询同样能拿到数据。

Resolves the runtime asset that owns this agent's bone bake: the registered renderer's asset first, then the asset on the FVisualize renderer class's CDO — a dedicated server spawns no renderer actor, and the CDO still carries the baked asset, so queries work there too.

Input
参数Param类型Type说明Description
WorldContextconst UObject*世界上下文。World context.
Entityconst FEntityHandle&被查询的 agent 实体。The agent entity being queried.
Output

返回拥有该单位骨骼烘焙的资产指针。无副作用。

Returns the asset that owns this unit's bone bake. No side effects.

PoseAgentBodies static bool

在调用那一刻按当前动画状态,给该 agent 的全部已烘刚体摆一次姿态,结果写入 OutBodies。适合"我要自己给这些形状做判定"的场景。若渲染器已经把该 agent 交给 GPU 布娃娃池,bOutRagdollSimulating 会报告这一点,此时返回的姿态就是尸体被种入时所用的最后一份动画姿态。

Poses every baked body of the agent once, at the instant of the call, from the current animation state, and writes the result into OutBodies. Use it when you want to judge those shapes yourself. If the renderer already drives this agent through its GPU ragdoll pool, bOutRagdollSimulating reports it, and the returned pose is then the last animation pose the corpse was seeded from.

Input
参数Param类型Type说明Description
WorldContextconst UObject*世界上下文。World context.
Entityconst FEntityHandle&被查询的 agent 实体。The agent entity being queried.
OutBodiesTArray<FAgentBodyPose>&输出数组,逐已烘刚体一项。Output array, one entry per baked body.
bOutRagdollSimulatingbool*可选。非空时写入渲染器是否已在用 GPU 布娃娃池驱动这个 agent。Optional. When non-null, receives whether the renderer already drives this agent through its GPU ragdoll pool.
Output

产出非空姿态时返回 true。副作用:OutBodies 被填充,可能写入 bOutRagdollSimulating。

True when a non-empty pose was produced. Side effects: OutBodies is filled; bOutRagdollSimulating may be written.

QueryAgentBones static bool

先摆一次姿态,再在这些刚体形状上做测试。重叠类形状对有接触的每个刚体产出一行,带有符号最近距离(负值 = 已穿透),没有接触的刚体一律不产出;射线只在进入刚体时产出一行,并报告到起点的距离。返回值即命中标志。KeepCount 与 SortMode 决定保留多少行、按什么顺序排列;Randomize 按由近到远处理——查询绝不消耗随机数。

Poses the bodies once, then tests their shapes. Overlap shapes emit one row per body in contact with the signed closest distance (negative = penetration); non-contacting bodies are omitted. A ray emits a row only when it enters a body and reports the distance from the start point. The return value is the hit flag. KeepCount and SortMode decide how many rows survive and in what order; Randomize is treated as near-to-far — a query never consumes an RNG.

Input
参数Param类型Type说明Description
WorldContextconst UObject*世界上下文。World context.
Entityconst FEntityHandle&被查询的 agent 实体。The agent entity being queried.
ShapeEMassBattleBoneShape测试形状:重叠类,或射线。The test shape: an overlap kind, or a ray.
ShapeParamsconst FDetectShape&形状参数(世界空间)。Shape parameters (world space).
OutHitsTArray<FAgentBoneHit>&输出数组,逐命中刚体一行,已按 SortMode 排序并受 KeepCount 裁剪。Output array, one row per hit body, already sorted by SortMode and trimmed by KeepCount.
KeepCountint32保留行数:负数 = 全部,0 = 一条也不保留。Rows to keep: negative = all, 0 = none.
SortModeESortMode排序方式,按命中自带的有符号距离由近到远或由远到近。Ordering by the hit's own signed distance, near-to-far or far-to-near.
Output

KeepCount 之后仍有结果行时返回 true。副作用:OutHits 被填充。

True when at least one row survives KeepCount. Side effect: OutHits is filled.

EvaluateBodies static bool

纯计算部分:不查 UObject、也不碰世界,只读交进来的姿态表与动画状态来摆这一帧的刚体。适合已经持有资产与动画状态的调用方,或需要在没有世界的环境里复算同一份姿态的场景。

The pure part: no UObject lookup and no world access — it poses this frame's bodies from the pose table and animation state handed to it. For callers that already hold the asset and the animation state, or that need to recompute the same pose where no world is available.

Input
参数Param类型Type说明Description
Attconst UMassBattleATTDataAsset*携带烘焙数据的运行时资产。Runtime asset carrying the bake.
Animatingconst FAnimating&该 agent 的动画运行时状态(决定播到哪一帧)。The agent's animation runtime state (which frame is playing).
AnimSharedconst FAnimShared&该模板的共享动画配置。The template's shared animation config.
EntityMeshTransformconst FTransform&该实体的网格变换,与姿态表、动画状态一起构成本函数的全部输入。The entity's mesh transform; together with the pose table and animation state it forms the function's entire input.
OutBodiesTArray<FAgentBodyPose>&输出数组,逐已烘刚体一项。Output array, one entry per baked body.
Output

产出非空姿态时返回 true。副作用:OutBodies 被填充。

True when a non-empty pose was produced. Side effect: OutBodies is filled.

补充说明Notes

前提:该单位必须已经烘过。烘焙从源网格的物理资产产出刚体与关节表,物理资产至少要提供一个刚体;没有任何物理资产时没有可查询的刚体。每单位最多 32 个刚体——源资产提供的刚体更多时,烘出的列表按质量从大到小排列。结果全部是世界空间,且与查询那一刻的动画画面一致;两次查询之间姿态可能已变,不要把结果跨帧缓存。

Prerequisite: the unit must have been baked. The bake produces the body and joint tables from the source mesh's physics asset, and that asset must supply at least one body — with no physics asset there is nothing to query. A unit carries at most 32 bodies; when the source asset supplies more, the baked list is mass-descending. All results are in world space and match the animation frame at the instant of the call; the pose may have moved on by the next query, so do not cache results across frames.