虚幻引擎程序化资源生成框架PCG 之 UPCGBlueprintElement源码笔记(一)

news/2025/2/13 5:13:39/

UPCGBlueprintElement是PCGGraph中自定义节点的基类,但官方目前还没有给出详细的文档,所以从源代码里找点答案。

文章目录

  • 可覆盖函数(Override Functions)
    • Excute 和 Excute with Context
    • Loop Body函数和Loop函数
      • Point Loop Body和PointLoop
      • Variable Loop Body和VariableLoop
      • Nested Loop Body和NestedLoop
      • Iteration Loop Body和IterationLoop

在这里插入图片描述

可覆盖函数(Override Functions)

在这里插入图片描述

UPCGBlueprintElement是PCGGraph中所有自定义节点的基类,有如下几个可供蓝图覆盖的函数:

  • Excute
  • Excute with Context
  • Iteration Loop Body
  • Point Loop Body
  • Variable Loop Body
  • Nested Loop Body
  • Node Color Override
  • Node Title Override
  • Node Type Override

其中 ExcuteExcute with ContextNodeTitleOverrideNodeColorOverrideNodeTypeOverride是覆盖后被自动触发的;而剩余的几个“Loop Body函数”则需要在蓝图中显示调用对应的“Loop函数”才可以执行循环,比如:要调用PointLoop才可以执行Point Loop Body

Excute 和 Excute with Context

这两个函数可以理解为自定义节点的“主函数”,区别就是一个有PCGContext输入另一个没有,ExecuteWithContext会调用Execute

Excute

	UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "PCG|Execution")void Execute(const FPCGDataCollection& Input, FPCGDataCollection& Output);

Excute with Context

	UFUNCTION(BlueprintNativeEvent, Category = "PCG|Execution")void ExecuteWithContext(UPARAM(ref)FPCGContext& InContext, const FPCGDataCollection& Input, FPCGDataCollection& Output);
void UPCGBlueprintElement::ExecuteWithContext_Implementation(FPCGContext& InContext, const FPCGDataCollection& Input, FPCGDataCollection& Output)
{Execute(Input, Output);
}

其实还有个C++ 函数ExecuteInternalExcute with Context是由它调用的。

virtual bool ExecuteInternal(FPCGContext* Context) const override;
	/** Finally, execute the actual blueprint */Context->BlueprintElementInstance->ExecuteWithContext(*Context, Context->InputData, Context->OutputData);

Loop Body函数和Loop函数

在这里插入图片描述

Loop Body函数都是在Loop函数中定义的lambda表达式调用的。

  • Point Loop BodyNested Loop BodyIteration Loop Body通过FPCGAsync::AsyncPointProcessing调用;
  • Variable Loop Body通过FPCGAsync::AsyncMultiPointProcessing调用
  • 上述节点中的各种Data参数都是PCGPointData类型,需要的话可以在调用Loop函数的时候传入,它们会直接传入Loop Body函数

Point Loop Body和PointLoop

Point Loop Body需要通过PointLoop执行循环

Point Loop Body
在这里插入图片描述

PointLoop

	FPCGAsync::AsyncPointProcessing(&InContext, InPoints.Num(), OutPoints, [this, &InContext, InData, OutData, &InPoints](int32 Index, FPCGPoint& OutPoint){return PointLoopBody(InContext, InData, InPoints[Index], OutPoint, OutData->Metadata);});

Variable Loop Body和VariableLoop

Variable Loop Body需要通过VariableLoop执行循环

在这里插入图片描述

VariableLoop

	FPCGAsync::AsyncMultiPointProcessing(&InContext, InPoints.Num(), OutPoints, [this, &InContext, InData, OutData, &InPoints](int32 Index){return VariableLoopBody(InContext, InData, InPoints[Index], OutData->Metadata);});
}

FPCGAsync::AsyncPointProcessingFPCGAsync::AsyncMultiPointProcessing都是异步的,它们的区别就在于处理输入:输出为1:1还是1:N的循环。Point Loop BodyVariableLoopBody,前者输入一个point返回一个point;后者输入一个point可以返回一个point的数组。比如:如果你想把一个point看作一块地基,想在它的垂直上方再生成一串点作为楼层,然后把这些点返回,那么你就需要用到VariableLoopBody

Nested Loop Body和NestedLoop

Nested Loop Body需要通过NestedLoop执行循环

在这里插入图片描述
关键代码如下,但使用情景没想明白。

NestedLoop

	const TArray<FPCGPoint>& InOuterPoints = InOuterData->GetPoints();const TArray<FPCGPoint>& InInnerPoints = InInnerData->GetPoints();TArray<FPCGPoint>& OutPoints = OutData->GetMutablePoints();FPCGAsync::AsyncPointProcessing(&InContext, InOuterPoints.Num() * InInnerPoints.Num(), OutPoints, [this, &InContext, InOuterData, InInnerData, OutData, &InOuterPoints, &InInnerPoints](int32 Index, FPCGPoint& OutPoint){return NestedLoopBody(InContext, InOuterData, InInnerData, InOuterPoints[Index / InInnerPoints.Num()], InInnerPoints[Index % InInnerPoints.Num()], OutPoint, OutData->Metadata);});

Iteration Loop Body和IterationLoop

Iteration Loop Body需要通过IterationLoop执行循环

在这里插入图片描述

Point Loop Body一样,但它会提供一个NumIterations用于指定迭代次数

IterationLoop

	FPCGAsync::AsyncPointProcessing(&InContext, NumIterations, OutPoints, [this, &InContext, InA, InB, OutData](int32 Index, FPCGPoint& OutPoint){return IterationLoopBody(InContext, Index, InA, InB, OutPoint, OutData->Metadata);});

http://www.ppmy.cn/news/837883.html

相关文章

Unity 事件函数的执行顺序

脚本生命周期流程图 Awake&#xff1a;在所有 Start 函数之前&#xff0c;以及 prefab 实例化之后调用。&#xff08;如果一个 GameObject 在启动期间处于非活动状态&#xff0c;则在激活之前不会调用它。&#xff09;OnEnable&#xff08;仅在对象处于活动状态时调用&#xff…

python 今日头条增加流量_今日头条怎么提高推荐量?

很多人都会在闲暇的时间来做一些自媒体&#xff0c;写一些文章来发表挣得收益。但是有一些自媒体写手会发现一个事情&#xff0c;写着写着&#xff0c;文章是自己的原创文章&#xff0c;但是这个官方给的推荐量却在不断减少。为什么会出现这样的问题呢?即使是标题和内容都搭配…

今日头条极速版自动脚本_今日头条极速版多开软件,这个工具造福广大自媒体人!...

因为个人发声的需求越来越强烈&#xff0c;最近几年&#xff0c;自媒体视频行业实在被大家青睐&#xff0c;其内容覆盖面积广、优越的转化效果的数不胜数的优越性&#xff0c;强烈吸引着无数有想法的人&#xff0c;出于各种原因&#xff0c;都想获取巨大的展现流量&#xff0c;…

今日头条怎么刷文章阅读量_今日头条能刷阅读量吗?

今日头条目前已成为主流自媒体平台&#xff0c;每日流量可谓非常之大。很多做自媒体的朋友一直发愁如何提高今日头条等自媒体平台的阅读量。自头条号推出新规则后&#xff0c;让很多新手很高兴&#xff0c;因为不用苦苦转正过新手期直接都开通了广告权限&#xff0c;只要发的文…

今日头条各种套路玩法

【各种打赏&#xff0c;点赞&#xff0c;评论都没法拿到 stormzhang 签名书&#xff0c;只能坚持在知识星球分享&#xff0c;进入精华区&#xff0c;获取签名书&#xff08;一&#xff09;】 第一篇分享&#xff0c;就围绕头条号来说了。 一次闲聊&#xff0c;偶然在 stormzh…

今日头条阅读量怎么刷_今日头条提升头条号阅读量的几大方法

“为什么我在今日头条发布的文章阅读量低&#xff1f;” “我的头条号文章发布了&#xff0c;但是推荐量一直很少&#xff0c;能不能多给我一点推荐量&#xff1f;” 因为大家都知道&#xff0c;只有我们在今日头条上发布的文章阅读量越大&#xff0c;我们的收益才能越高&#…

今日头条粉丝如何引流微信?免费教你今日头条引流微信加粉方法

随着自媒体的火爆,今日头条、一点资讯、天天快报这样的自媒体平台越来越多,用户量也越来越大,很多微商朋友仅仅知道利用今日头条来看看新闻资讯,用来休闲娱乐,并不知道怎么用用这些自媒体平台来加粉引流。 聪少这边研究自媒体赚钱、营销引流的时间比较早,从今日头条出来开…

今日头条的排名算法_今日头条旗下悟空问答的排名算法规则

原标题&#xff1a;今日头条旗下悟空问答的排名算法规则 悟空问答里&#xff0c;答案的排序按照什么标准?提到百度知道平台&#xff0c;大家都知道&#xff0c;但是知乎、悟空问答这些后起之秀你知道吗?今天收集网络上关注今日头条旗下产品悟空问答的排名算法规则。 由用户 开…