UE5《Electric Dreams》项目PCG技术解析 之 PCGCustomNodes详解(一)

2024-03-18 12:10

本文主要是介绍UE5《Electric Dreams》项目PCG技术解析 之 PCGCustomNodes详解(一),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

《Electric Dreams》项目中提供了一些自定义节点和子图(文件位置:“/Content/PCG/Assets/PCGCustomNodes”),这些节点和子图在《Electric Dreams》被广泛使用,对于理解《Electric Dreams》非常重要,而且它们可以直接移植到新的项目中使用。所以写个博客分析一下

文章目录

  • 前导文章
  • Passthrough节点
    • 作用
    • Execute with Context
  • PointNormalToColor节点
    • 作用
    • Point Loop Body
    • Execute with Context
  • PointFromPCGVolume节点
    • 作用
    • Execute with Context

在这里插入图片描述

前导文章

《虚幻引擎程序化资源生成框架PCG 之 UPCGBlueprintElement源码笔记(一)》
《虚幻引擎程序化资源生成框架PCG 之 UPCGBlueprintElement源码笔记(二)数据流》

Passthrough节点

作用

数据流的开关

Execute with Context

在这里插入图片描述

Enabled控制是否将从Input输入进来的从Output输出,当Enabledfalse的时候,输出的PCGDataCollection中的Tagged Data数组将会是一个空数组。

PointNormalToColor节点

作用

将Point法线存入Color属性

Point Loop Body

先看一下它的Point Loop Body
在这里插入图片描述
Point Loop Body的逻辑就是将每一个Point的Up Vector存储在Color属性中,然后把修改过的Point输出。

Execute with Context

在这里插入图片描述

注释见上图,在PointLoopBody后面有一个Initialize from Data节点,代码如下:

void UPCGSpatialData::InitializeFromData(const UPCGSpatialData* InSource, const UPCGMetadata* InMetadataParentOverride, bool bInheritMetadata, bool bInheritAttributes)
{if (InSource && TargetActor.IsExplicitlyNull()){TargetActor = InSource->TargetActor;}if (!Metadata){Metadata = NewObject<UPCGMetadata>(this);}if (!bInheritMetadata || InMetadataParentOverride || InSource){const UPCGMetadata* ParentMetadata = bInheritMetadata ? (InMetadataParentOverride ? InMetadataParentOverride : (InSource ? InSource->Metadata : nullptr)) : nullptr;Metadata->Initialize(ParentMetadata, bInheritAttributes);}else{UE_LOG(LogPCG, Warning, TEXT("InitializeFromData has both no source and no metadata override"));}
}

Initialize from Data做了两件事:

  • 将源Data中的TargetActor赋值给新PCGSpatialDataTargetActor
  • 用源Data的metadata初始化新PCGSpatialData的metadata

PointFromPCGVolume节点

作用

使用ContextSourceComponent或者Component的几何信息(TransformBound)构造1个PCGPoint

Execute with Context

在这里插入图片描述

我们先看一下GetComponentGetOriginalComponent

UPCGComponent* UPCGBlueprintHelpers::GetComponent(FPCGContext& Context)
{return Context.SourceComponent.Get();
}UPCGComponent* UPCGBlueprintHelpers::GetOriginalComponent(FPCGContext& Context)
{if (Context.SourceComponent.IsValid() &&Cast<APCGPartitionActor>(Context.SourceComponent->GetOwner()) &&Cast<APCGPartitionActor>(Context.SourceComponent->GetOwner())->GetOriginalComponent(Context.SourceComponent.Get())){return Cast<APCGPartitionActor>(Context.SourceComponent->GetOwner())->GetOriginalComponent(Context.SourceComponent.Get());}else{return Context.SourceComponent.Get();}
}

再看看它是如何获取GetActorLocalBoundsPCG

UPCGBlueprintHelpers::GetActorLocalBoundsPCG

FBox UPCGBlueprintHelpers::GetActorLocalBoundsPCG(AActor* InActor, bool bIgnorePCGCreatedComponents)
{return PCGHelpers::GetActorLocalBounds(InActor, bIgnorePCGCreatedComponents);
}

PCGHelpers::GetActorLocalBounds

FBox GetActorLocalBounds(const AActor* InActor, bool bIgnorePCGCreatedComponents){// Specialized version of CalculateComponentsBoundingBoxInLocalScape that skips over PCG generated components// This is to ensure stable bounds and no timing issues (cleared ISMs, etc.)FBox Box(EForceInit::ForceInit);const bool bNonColliding = true;const bool bIncludeFromChildActors = true;if (InActor){const FTransform& ActorToWorld = InActor->GetTransform();const FTransform WorldToActor = ActorToWorld.Inverse();InActor->ForEachComponent<UPrimitiveComponent>(bIncludeFromChildActors, [bNonColliding, bIgnorePCGCreatedComponents, &WorldToActor, &Box](const UPrimitiveComponent* InPrimComp){if ((bNonColliding || InPrimComp->IsCollisionEnabled()) &&(!bIgnorePCGCreatedComponents || !InPrimComp->ComponentTags.Contains(DefaultPCGTag))){const FTransform ComponentToActor = InPrimComp->GetComponentTransform() * WorldToActor;Box += InPrimComp->CalcBounds(ComponentToActor).GetBox();}});}else{UE_LOG(LogPCG, Error, TEXT("Actor is invalid in GetActorLocalBounds"));}return Box;}

所谓LocalBounds就是把所属Actor的所有PrimitiveComponent叠加起来获得最大的FBox

在这里插入图片描述

这篇关于UE5《Electric Dreams》项目PCG技术解析 之 PCGCustomNodes详解(一)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/822294

相关文章

Spring Boot中的路径变量示例详解

《SpringBoot中的路径变量示例详解》SpringBoot中PathVariable通过@PathVariable注解实现URL参数与方法参数绑定,支持多参数接收、类型转换、可选参数、默认值及... 目录一. 基本用法与参数映射1.路径定义2.参数绑定&nhttp://www.chinasem.cnbs

MySql基本查询之表的增删查改+聚合函数案例详解

《MySql基本查询之表的增删查改+聚合函数案例详解》本文详解SQL的CURD操作INSERT用于数据插入(单行/多行及冲突处理),SELECT实现数据检索(列选择、条件过滤、排序分页),UPDATE... 目录一、Create1.1 单行数据 + 全列插入1.2 多行数据 + 指定列插入1.3 插入否则更

Redis中Stream详解及应用小结

《Redis中Stream详解及应用小结》RedisStreams是Redis5.0引入的新功能,提供了一种类似于传统消息队列的机制,但具有更高的灵活性和可扩展性,本文给大家介绍Redis中Strea... 目录1. Redis Stream 概述2. Redis Stream 的基本操作2.1. XADD

Spring StateMachine实现状态机使用示例详解

《SpringStateMachine实现状态机使用示例详解》本文介绍SpringStateMachine实现状态机的步骤,包括依赖导入、枚举定义、状态转移规则配置、上下文管理及服务调用示例,重点解... 目录什么是状态机使用示例什么是状态机状态机是计算机科学中的​​核心建模工具​​,用于描述对象在其生命

IntelliJ IDEA2025创建SpringBoot项目的实现步骤

《IntelliJIDEA2025创建SpringBoot项目的实现步骤》本文主要介绍了IntelliJIDEA2025创建SpringBoot项目的实现步骤,文中通过示例代码介绍的非常详细,对大家... 目录一、创建 Spring Boot 项目1. 新建项目2. 基础配置3. 选择依赖4. 生成项目5.

Java JDK1.8 安装和环境配置教程详解

《JavaJDK1.8安装和环境配置教程详解》文章简要介绍了JDK1.8的安装流程,包括官网下载对应系统版本、安装时选择非系统盘路径、配置JAVA_HOME、CLASSPATH和Path环境变量,... 目录1.下载JDK2.安装JDK3.配置环境变量4.检验JDK官网下载地址:Java Downloads

nginx -t、nginx -s stop 和 nginx -s reload 命令的详细解析(结合应用场景)

《nginx-t、nginx-sstop和nginx-sreload命令的详细解析(结合应用场景)》本文解析Nginx的-t、-sstop、-sreload命令,分别用于配置语法检... 以下是关于 nginx -t、nginx -s stop 和 nginx -s reload 命令的详细解析,结合实际应

MyBatis中$与#的区别解析

《MyBatis中$与#的区别解析》文章浏览阅读314次,点赞4次,收藏6次。MyBatis使用#{}作为参数占位符时,会创建预处理语句(PreparedStatement),并将参数值作为预处理语句... 目录一、介绍二、sql注入风险实例一、介绍#(井号):MyBATis使用#{}作为参数占位符时,会

使用Python删除Excel中的行列和单元格示例详解

《使用Python删除Excel中的行列和单元格示例详解》在处理Excel数据时,删除不需要的行、列或单元格是一项常见且必要的操作,本文将使用Python脚本实现对Excel表格的高效自动化处理,感兴... 目录开发环境准备使用 python 删除 Excphpel 表格中的行删除特定行删除空白行删除含指定

MySQL中的LENGTH()函数用法详解与实例分析

《MySQL中的LENGTH()函数用法详解与实例分析》MySQLLENGTH()函数用于计算字符串的字节长度,区别于CHAR_LENGTH()的字符长度,适用于多字节字符集(如UTF-8)的数据验证... 目录1. LENGTH()函数的基本语法2. LENGTH()函数的返回值2.1 示例1:计算字符串