继续解析《Electric Dreams》项目中的自定义节点和子图:SG_CopyPointsWithHierarchy
和PostCopyPoints-OffsetIndices
![在这里插入图片描述](https://img-blog.csdnimg.cn/8f7b0cc8281748a1b5a693322fe48b9e.png)
前导文章
《UE5《Electric Dreams》项目PCG技术解析 之 理解Assembly(以SplineExample为例)》
《虚幻引擎程序化资源生成框架PCG 之 UPCGBlueprintElement源码笔记(一)》
《虚幻引擎程序化资源生成框架PCG 之 UPCGBlueprintElement源码笔记(二)数据流》
《UE5《Electric Dreams》项目PCG技术解析 之 PCGCustomNodes详解(一)》
《UE5《Electric Dreams》项目PCG技术解析 之 PCGCustomNodes详解(二)Look At》
标准组合拳
《Electric Dreams》以及官方文档中给出了SG_CopyPointsWithHierarchy
和ApplyHierarchy
标准使用套路
![在这里插入图片描述](https://img-blog.csdnimg.cn/3025401deed943798ffbd0c26beb5b2a.png)
以下摘自官方文档:
- 由 Level to PCG资产工具 将关卡转换为包含PCG点的PCG设置资产,其相关联的场景层级信息将存储为
metadata
特性。
-
SG_CopyPointsWithHierarchy
子图表使用目标点变换在多个位置复制PCG设置资产,这与Copy Points
节点的作用类似,但它还通过维护和偏移层级特性值,使父级信息对于原始资产点的每个副本来说都是唯一的。
-
Point Filter
节点,根据特性选择点。
-
Transform Points
节点与ApplyToAttributes
选项,对被选中点的相对变换特性执行变换操作。
-
Merge
节点,重新组合同一数据流中同一层级的所有点。
-
ApplyHierarchy
节点,将相对变换特性与父级变换相结合,应用到点上。
SG_CopyPointsWithHierarchy
![在这里插入图片描述](https://img-blog.csdnimg.cn/b760e2420c4249baa979a107b1081b74.png)
在SG_CopyPointsWithHierarchy
中首先进行了Copy Points
,而它的关键部分在于PostCopyPoints-OffsetIndices
PostCopyPoints-OffsetIndices
顾名思义:PostCopyPoints-OffsetIndices
就是在CopyPoints
之后,对Point
的"Index"进行Offset
。但是理解到这个层次还是让人摸不着头脑。在研究源代码之前我们先看一下它的使用情景。
使用情景
SG_CopyPointsWithHierarchy
(以及PostCopyPoints-OffsetIndices
)都是结合着Assembly来使用的,所以这个例子要从Assembly开始。
老王在《UE5《Electric Dreams》项目PCG技术解析 之 理解Assembly(以SplineExample为例)》一文中简要介绍过Assembly。
构造一个简单的简单的关卡“Assembly_01”,并使用"PCG-Level to PCGSettings"工具生成对应的“Assembly_01_PCG”
![在这里插入图片描述](https://img-blog.csdnimg.cn/27a21566e14c4cbc91bd12c58b0bf746.png)
构造一个简单的PCGGraph看一下
![在这里插入图片描述](https://img-blog.csdnimg.cn/f43967259a864fa0b41c26e323f1ef17.png)
![在这里插入图片描述](https://img-blog.csdnimg.cn/9cf32fb248dd4f8da2d64ed696eecdd9.png)
"Assembly_01"中Points通道的原始信息
![在这里插入图片描述](https://img-blog.csdnimg.cn/a5f8272df27a4999ab14e94ec8b981d0.png)
-
Mesh: 模型
-
Material: 材质
-
Actor Index: Actor的Index
-
Parent Index: 这个Actor父级Actor的Index,当
Parent Index
为-1时没有父级
-
Hierarchy Depth: 所处层级
-
其它: 相对父级的Transform
"SG_CopyPointsWithHierarchy"的信息
![在这里插入图片描述](https://img-blog.csdnimg.cn/05e4504e9d8b4636acb736e2716f09dd.png)
**对比以后我们可以看到PostCopyPoints-OffsetIndices
,实际上就是对为每个Point重新分配了Actor Index
保证它们在1:N变成M:N*M以后依然有互不相同的Actor Index
,并且Parent Index
依然对应着它的父级Actor Index
。接下来,我们看一下它是如何实现的。
![在这里插入图片描述](https://img-blog.csdnimg.cn/41c26a6ebe8e4d18851957ffde32197e.png#pic_center)
Execute with Context
![在这里插入图片描述](https://img-blog.csdnimg.cn/dcef64f54e6f430a918ef0891a384c9a.png)
1-2. 首先获取CopyPointsTarget
输入通道中第1个PCGTaggedData
(→PCGSpatialData
)计算出其中Point
个数存入Total Point Count
3. 获取Context
的TaskId
计算出Random Offset
,这里TaskId
就是一个uint64
类型的整数,相当于一个随机种子
4-5. 获取CopyPointsOut
输入通道中第1个PCGTaggedData
(→PCGPointData
),其中PCGPoint
的数量会作为IterationLoop
的迭代次数。
Iteration Loop Body
![在这里插入图片描述](https://img-blog.csdnimg.cn/e2d4b1cbae654f1d820415de99b55fda.png)
Iteration Loop Body
的目的就是为Point
的两个Int64类型的特性:ActorIndex
和ParentIndex
重新赋值,保证每个Point的子Point有足够的编号空间。
小结
-
SG_CopyPointsWithHierarchy
其实就是携带source中层级信息和相对Transform的高级版CopyPoints。
- 它需要和"PCGSettings"以及"PCG-Level to PCGSettings"一起工作(需要"PCGSettings"中原始
ActorIndex
和ParentIndex
信息)。
![在这里插入图片描述](https://img-blog.csdnimg.cn/14e717ce1ec840bfaa7da7cb461798fd.png)