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 实现 IP 限流的原理、实践与利弊解析

《SpringBoot实现IP限流的原理、实践与利弊解析》在SpringBoot中实现IP限流是一种简单而有效的方式来保障系统的稳定性和可用性,本文给大家介绍SpringBoot实现IP限... 目录一、引言二、IP 限流原理2.1 令牌桶算法2.2 漏桶算法三、使用场景3.1 防止恶意攻击3.2 控制资源

SQL BETWEEN 语句的基本用法详解

《SQLBETWEEN语句的基本用法详解》SQLBETWEEN语句是一个用于在SQL查询中指定查询条件的重要工具,它允许用户指定一个范围,用于筛选符合特定条件的记录,本文将详细介绍BETWEEN语... 目录概述BETWEEN 语句的基本用法BETWEEN 语句的示例示例 1:查询年龄在 20 到 30 岁

Java Spring ApplicationEvent 代码示例解析

《JavaSpringApplicationEvent代码示例解析》本文解析了Spring事件机制,涵盖核心概念(发布-订阅/观察者模式)、代码实现(事件定义、发布、监听)及高级应用(异步处理、... 目录一、Spring 事件机制核心概念1. 事件驱动架构模型2. 核心组件二、代码示例解析1. 事件定义

CSS place-items: center解析与用法详解

《CSSplace-items:center解析与用法详解》place-items:center;是一个强大的CSS简写属性,用于同时控制网格(Grid)和弹性盒(Flexbox)... place-items: center; 是一个强大的 css 简写属性,用于同时控制 网格(Grid) 和 弹性盒(F

springboot项目中整合高德地图的实践

《springboot项目中整合高德地图的实践》:本文主要介绍springboot项目中整合高德地图的实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一:高德开放平台的使用二:创建数据库(我是用的是mysql)三:Springboot所需的依赖(根据你的需求再

spring中的ImportSelector接口示例详解

《spring中的ImportSelector接口示例详解》Spring的ImportSelector接口用于动态选择配置类,实现条件化和模块化配置,关键方法selectImports根据注解信息返回... 目录一、核心作用二、关键方法三、扩展功能四、使用示例五、工作原理六、应用场景七、自定义实现Impor

一文深入详解Python的secrets模块

《一文深入详解Python的secrets模块》在构建涉及用户身份认证、权限管理、加密通信等系统时,开发者最不能忽视的一个问题就是“安全性”,Python在3.6版本中引入了专门面向安全用途的secr... 目录引言一、背景与动机:为什么需要 secrets 模块?二、secrets 模块的核心功能1. 基

一文详解MySQL如何设置自动备份任务

《一文详解MySQL如何设置自动备份任务》设置自动备份任务可以确保你的数据库定期备份,防止数据丢失,下面我们就来详细介绍一下如何使用Bash脚本和Cron任务在Linux系统上设置MySQL数据库的自... 目录1. 编写备份脚本1.1 创建并编辑备份脚本1.2 给予脚本执行权限2. 设置 Cron 任务2

一文详解如何在idea中快速搭建一个Spring Boot项目

《一文详解如何在idea中快速搭建一个SpringBoot项目》IntelliJIDEA作为Java开发者的‌首选IDE‌,深度集成SpringBoot支持,可一键生成项目骨架、智能配置依赖,这篇文... 目录前言1、创建项目名称2、勾选需要的依赖3、在setting中检查maven4、编写数据源5、开启热

python常见环境管理工具超全解析

《python常见环境管理工具超全解析》在Python开发中,管理多个项目及其依赖项通常是一个挑战,下面:本文主要介绍python常见环境管理工具的相关资料,文中通过代码介绍的非常详细,需要的朋友... 目录1. conda2. pip3. uvuv 工具自动创建和管理环境的特点4. setup.py5.