ue5 motion matching

ue5.5   gameanimationsample

先看动画蓝图 核心两个node

第一个是根据数据选择当前的pose

 第二个是缓存一段历史记录,为第一个node选择的时候提供数据。

在animinstance的update方法中 每帧都更新这个函数,每帧更新trajectory的数据

看看第一个node的执行顺序

void FAnimNode_MotionMatching::UpdateAssetPlayer(const FAnimationUpdateContext& Context)void UPoseSearchLibrary::UpdateMotionMatchingState(const FAnimationUpdateContext& Context,const TArray<TObjectPtr<const UPoseSearchDatabase>>& Databases,float BlendTime,int32 MaxActiveBlends,const FFloatInterval& PoseJumpThresholdTime,float PoseReselectHistory,float SearchThrottleTime,const FFloatInterval& PlayRate,FMotionMatchingState& InOutMotionMatchingState,EPoseSearchInterruptMode InterruptMode,bool bShouldSearch,bool bShouldUseCachedChannelData,bool bDebugDrawQuery,bool bDebugDrawCurResult){...........//这里每帧都监听第二个节点,把history trajectory传过来const IPoseHistory* PoseHistory = nullptr;if (FPoseHistoryProvider* PoseHistoryProvider = Context.GetMessage<FPoseHistoryProvider>()){PoseHistory = &PoseHistoryProvider->GetPoseHistory();}FMemMark Mark(FMemStack::Get());const UAnimInstance* AnimInstance = Cast<const UAnimInstance>(Context.AnimInstanceProxy->GetAnimInstanceObject());check(AnimInstance);const UPoseSearchDatabase* CurrentResultDatabase = InOutMotionMatchingState.CurrentSearchResult.Database.Get();if (IsInvalidatingContinuingPose(InterruptMode, CurrentResultDatabase, Databases)){InOutMotionMatchingState.CurrentSearchResult.Reset();}FSearchContext SearchContext(0.f, &InOutMotionMatchingState.PoseIndicesHistory, InOutMotionMatchingState.CurrentSearchResult, PoseJumpThresholdTime);//addSearchContext.AddRole(DefaultRole, AnimInstance, PoseHistory);.........const FSearchResult NewSearchResult = Database->Search(SearchContext);.........
}UE::PoseSearch::FSearchResult UPoseSearchDatabase::Search(UE::PoseSearch::FSearchContext& SearchContext) const{.........Result = SearchPCAKDTree(SearchContext);.........
}UE::PoseSearch::FSearchResult UPoseSearchDatabase::SearchPCAKDTree(UE::PoseSearch::FSearchContext& SearchContext) const
{.........//channelTConstArrayView<float> QueryValues = SearchContext.GetOrBuildQuery(Schema);.........
}TConstArrayView<float> FSearchContext::GetOrBuildQuery(const UPoseSearchSchema* Schema)
{QUICK_SCOPE_CYCLE_COUNTER(STAT_PoseSearch_GetOrBuildQuery);check(Schema);if (const FCachedQuery* FoundCachedQuery = CachedQueries.FindByPredicate([Schema](const FCachedQuery& CachedQuery){return CachedQuery.GetSchema() == Schema;})){return FoundCachedQuery->GetValues();}return Schema->BuildQuery(*this);
}TConstArrayView<float> UPoseSearchSchema::BuildQuery(UE::PoseSearch::FSearchContext& SearchContext) const
{QUICK_SCOPE_CYCLE_COUNTER(STAT_PoseSearch_BuildQuery);SearchContext.AddNewFeatureVectorBuilder(this);for (const TObjectPtr<UPoseSearchFeatureChannel>& ChannelPtr : GetChannels()){ChannelPtr->BuildQuery(SearchContext);}return SearchContext.EditFeatureVector();
}void UPoseSearchFeatureChannel_GroupBase::BuildQuery(UE::PoseSearch::FSearchContext& SearchContext) const
{for (const TObjectPtr<UPoseSearchFeatureChannel>& SubChannelPtr : GetSubChannels()){if (const UPoseSearchFeatureChannel* SubChannel = SubChannelPtr.Get()){SubChannel->BuildQuery(SearchContext);}}
}//subchannel就是各种channel 的数组 比如position channel,velocity channelvoid UPoseSearchFeatureChannel_Position::BuildQuery(UE::PoseSearch::FSearchContext& SearchContext) const
{..............const FVector BonePosition = SearchContext.GetSamplePosition(SampleTimeOffset, OriginTimeOffset, SchemaBoneIdx, SchemaOriginBoneIdx, SampleRole, OriginRole, PermutationTimeType, &BonePositionWorld);...........}FVector FSearchContext::GetSamplePosition(float SampleTimeOffset, float OriginTimeOffset, int8 SchemaSampleBoneIdx, int8 SchemaOriginBoneIdx, const FRole& SampleRole, const FRole& OriginRole, EPermutationTimeType PermutationTimeType, const FVector* SampleBonePositionWorldOverride)
{float PermutationSampleTimeOffset = 0.f;float PermutationOriginTimeOffset = 0.f;UPoseSearchFeatureChannel::GetPermutationTimeOffsets(PermutationTimeType, DesiredPermutationTimeOffset, PermutationSampleTimeOffset, PermutationOriginTimeOffset);const float SampleTime = SampleTimeOffset + PermutationSampleTimeOffset;const float OriginTime = OriginTimeOffset + PermutationOriginTimeOffset;return GetSamplePositionInternal(SampleTime, OriginTime, SchemaSampleBoneIdx, SchemaOriginBoneIdx, SampleRole, OriginRole, SampleBonePositionWorldOverride);
}FVector FSearchContext::GetSamplePositionInternal(float SampleTime, float OriginTime, int8 SchemaSampleBoneIdx, int8 SchemaOriginBoneIdx, const FRole& SampleRole, const FRole& OriginRole, const FVector* SampleBonePositionWorldOverride)
{if (SampleBonePositionWorldOverride){const FTransform RootBoneTransform = GetWorldBoneTransformAtTime(OriginTime, OriginRole, RootSchemaBoneIdx);if (SchemaOriginBoneIdx == RootSchemaBoneIdx){return RootBoneTransform.InverseTransformPosition(*SampleBonePositionWorldOverride);}// @todo: validate this still works for when root bone is not Identityconst FTransform OriginBoneTransform = GetWorldBoneTransformAtTime(OriginTime, OriginRole, SchemaOriginBoneIdx);const FVector DeltaBoneTranslation = *SampleBonePositionWorldOverride - OriginBoneTransform.GetTranslation();return RootBoneTransform.InverseTransformVector(DeltaBoneTranslation);}const FTransform RootBoneTransform = GetWorldBoneTransformAtTime(OriginTime, OriginRole, RootSchemaBoneIdx);const FTransform SampleBoneTransform = GetWorldBoneTransformAtTime(SampleTime, SampleRole, SchemaSampleBoneIdx);if (SchemaOriginBoneIdx == RootSchemaBoneIdx){return RootBoneTransform.InverseTransformPosition(SampleBoneTransform.GetTranslation());}const FTransform OriginBoneTransform = GetWorldBoneTransformAtTime(OriginTime, OriginRole, SchemaOriginBoneIdx);const FVector DeltaBoneTranslation = SampleBoneTransform.GetTranslation() - OriginBoneTransform.GetTranslation();return RootBoneTransform.InverseTransformVector(DeltaBoneTranslation);
}//获得过程终于用到了const IPoseHistory* PoseHistory = GetPoseHistory(SampleRole);
FTransform FSearchContext::GetWorldBoneTransformAtTime(float SampleTime, const FRole& SampleRole, int8 SchemaBoneIdx)
{// CachedQueries.Last is the query we're building check(!CachedQueries.IsEmpty());const UPoseSearchSchema* Schema = CachedQueries.Last().GetSchema();check(Schema);TConstArrayView<FBoneReference> BoneReferences = Schema->GetBoneReferences(SampleRole);check(BoneReferences[SchemaBoneIdx].HasValidSetup());const FBoneIndexType BoneIndexType = BoneReferences[SchemaBoneIdx].BoneIndex;const uint32 SampleTimeHash = GetTypeHash(SampleTime);const uint32 SampleRoleHash = GetTypeHash(SampleRole);const uint32 SampleTimeAndRoleHash = HashCombineFast(SampleTimeHash, SampleRoleHash);const uint32 BoneIndexTypeHash = GetTypeHash(BoneIndexType);const uint32 BoneCachedTransformKey = HashCombineFast(SampleTimeAndRoleHash, BoneIndexTypeHash);if (const FTransform* CachedTransform = CachedTransforms.Find(BoneCachedTransformKey)){return *CachedTransform;}FTransform WorldBoneTransform;if (BoneIndexType == RootBoneIndexType){// we already tried querying the CachedTransforms so, let's search in TrajectoryWorldBoneTransform = GetWorldRootBoneTransformAtTime(SampleTime, SampleRole);}else // if (BoneIndexType != RootBoneIndexType){// searching for RootBoneIndexType in CachedTransformsstatic const uint32 RootBoneIndexTypeHash = GetTypeHash(RootBoneIndexType); // Note: static const, since RootBoneIndexType is a constantconst uint32 RootBoneCachedTransformKey = HashCombineFast(SampleTimeAndRoleHash, RootBoneIndexTypeHash);if (const FTransform* CachedTransform = CachedTransforms.Find(RootBoneCachedTransformKey)){WorldBoneTransform = *CachedTransform;}else{WorldBoneTransform = GetWorldRootBoneTransformAtTime(SampleTime, SampleRole);}// collecting the local bone transforms from the IPoseHistoryconst IPoseHistory* PoseHistory = GetPoseHistory(SampleRole);#if WITH_EDITORif (!PoseHistory){UE_LOG(LogPoseSearch, Error, TEXT("FSearchContext::GetWorldBoneTransformAtTime - Couldn't search for bones requested by %s, because no IPoseHistory has been found!"), *Schema->GetName());}else#endif // WITH_EDITOR{check(PoseHistory);const USkeleton* Skeleton = Schema->GetSkeleton(SampleRole);FTransform LocalBoneTransform;if (!PoseHistory->GetTransformAtTime(SampleTime, LocalBoneTransform, Skeleton, BoneIndexType, RootBoneIndexType)){if (Skeleton){if (!PoseHistory->IsEmpty()){UE_LOG(LogPoseSearch, Warning, TEXT("FSearchContext::GetWorldBoneTransformAtTime - Couldn't find BoneIndexType %d (%s) requested by %s"), BoneIndexType, *Skeleton->GetReferenceSkeleton().GetBoneName(BoneIndexType).ToString(), *Schema->GetName());}}else{UE_LOG(LogPoseSearch, Warning, TEXT("FSearchContext::GetWorldBoneTransformAtTime - Schema '%s' Skeleton is not properly set"), *Schema->GetName());}}WorldBoneTransform = LocalBoneTransform * WorldBoneTransform;}}CachedTransforms.Add(BoneCachedTransformKey) = WorldBoneTransform;return WorldBoneTransform;
}//这里就是第二个节点pose history  里面有 trajectory
bool FPoseHistory::GetTransformAtTime(float Time, FTransform& OutBoneTransform, const USkeleton* BoneIndexSkeleton, FBoneIndexType BoneIndexType, FBoneIndexType ReferenceBoneIndexType, bool bExtrapolate) const
{CheckThreadSafetyRead(ReadPoseDataThreadSafeCounter);static_assert(RootBoneIndexType == 0 && ComponentSpaceIndexType == FBoneIndexType(-1) && WorldSpaceIndexType == FBoneIndexType(-2)); // some assumptionscheck(BoneIndexType != ComponentSpaceIndexType && BoneIndexType != WorldSpaceIndexType);bool bSuccess = false;const bool bApplyComponentToWorld = ReferenceBoneIndexType == WorldSpaceIndexType;FTransform ComponentToWorld = FTransform::Identity;if (bApplyComponentToWorld){//就是这个和trajectory 联系上了ComponentToWorld = Trajectory.GetSampleAtTime(Time, bExtrapolate).GetTransform();ReferenceBoneIndexType = ComponentSpaceIndexType;}const FPoseData& ReadPoseData = GetReadPoseData();const int32 NumEntries = ReadPoseData.Entries.Num();if (NumEntries > 0){int32 NextIdx = 0;int32 PrevIdx = 0;if (NumEntries > 1){const int32 LowerBoundIdx = LowerBound(ReadPoseData.Entries.begin(), ReadPoseData.Entries.end(), Time, [](const FPoseHistoryEntry& Entry, float Value) { return Value > Entry.AccumulatedSeconds; });NextIdx = FMath::Clamp(LowerBoundIdx, 1, NumEntries - 1);PrevIdx = NextIdx - 1;}const FPoseHistoryEntry& PrevEntry = ReadPoseData.Entries[PrevIdx];const FPoseHistoryEntry& NextEntry = ReadPoseData.Entries[NextIdx];bSuccess = LerpEntries(Time, bExtrapolate, PrevEntry, NextEntry, BoneIndexSkeleton, ReadPoseData.LastUpdateSkeleton.Get(), ReadPoseData.BoneToTransformMap, BoneIndexType, ReferenceBoneIndexType, OutBoneTransform);if (bApplyComponentToWorld){OutBoneTransform *= ComponentToWorld;}}else{OutBoneTransform = ComponentToWorld;}return bSuccess;
}

关于pose history

FPoseHistory 里面有    FPoseSearchQueryTrajectory Trajectory;

就是

void FAnimNode_PoseSearchHistoryCollector::Evaluate_AnyThread(FPoseContext& Output)
{DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(Evaluate_AnyThread);ANIM_MT_SCOPE_CYCLE_COUNTER_VERBOSE(PoseSearchHistoryCollector, !IsInGameThread());check(Output.AnimInstanceProxy);Super::Evaluate_AnyThread(Output);Source.Evaluate(Output);const bool bNeedsReset = bResetOnBecomingRelevant && UpdateCounter.HasEverBeenUpdated() && !UpdateCounter.WasSynchronizedCounter(Output.AnimInstanceProxy->GetUpdateCounter());FCSPose<FCompactPose> ComponentSpacePose;ComponentSpacePose.InitPose(Output.Pose);TArray<FBoneIndexType> RequiredBones;if (bCacheBones){RequiredBones = GetRequiredBones(Output.AnimInstanceProxy);}PoseHistory.EvaluateComponentSpace_AnyThread(Output.AnimInstanceProxy->GetDeltaSeconds(), ComponentSpacePose, bStoreScales,RootBoneRecoveryTime, RootBoneTranslationRecoveryRatio, RootBoneRotationRecoveryRatio, bNeedsReset, bCacheBones, RequiredBones, Output.Curve, MakeConstArrayView(CollectedCurves));bCacheBones = false;#if ENABLE_DRAW_DEBUG && ENABLE_ANIM_DEBUGFColor Color;
#if WITH_EDITORONLY_DATAColor = DebugColor.ToFColor(true);
#else // WITH_EDITORONLY_DATAColor = FLinearColor::Red.ToFColor(true);
#endif // WITH_EDITORONLY_DATAPoseHistory.DebugDraw(*Output.AnimInstanceProxy, Color);
#endif // ENABLE_DRAW_DEBUG && ENABLE_ANIM_DEBUG
}

FPoseHistory中Trajectory能确定控件的世界空间下的 pos和rotation

再配合CollectedBones确定的骨骼的历史记录

就能确定某个骨骼的历史 的世界坐标

来作为选择某个pose的支撑数据

在FSearchContext中

const IPoseHistory* GetPoseHistory(const FRole& Role) const { return PoseHistories[RoleToIndex[Role]]; }

资产方面 最重要的是要建立 pose search database 

schema最重要的是定义channel,从不同的维度去解析查找符合预期的pose

各种channel的定义

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/63532.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

YOLO系列发展历程:从YOLOv1到YOLO11,目标检测技术的革新与突破

文章目录 前言一、YOLOv1&#xff1a;单阶段目标检测的开端二、YOLOv2&#xff1a;更精准的实时检测三、YOLOv3&#xff1a;阶梯特征融合四、YOLOv4&#xff1a;性能和速度的新平衡五、YOLOv5&#xff1a;易用性和扩展性的加强六、YOLOv6&#xff1a;工业部署的利器七、YOLOv7&…

ConcurrentLinkedQueue<>实现生产者-消费者问题理解和简易demo

1.ConcurrentLinkedQueue<> ConcurrentLinkedQueue 是 Java 中的一个线程安全的无界队列实现。它基于无锁&#xff08;lock-free&#xff09;的算法&#xff0c;采用了一个高效的、非阻塞的、可伸缩并发控制机制。这使得在高并发场景下能够实现较高的吞吐量。 无界性质…

开发 UEFI 驱动

服务型驱动的特点&#xff1a; 1&#xff09;在 Image 的入口函数中执行安装&#xff1b; 2&#xff09;服务型驱动不需要驱动特定硬件&#xff0c;可以安装到任意控制器上&#xff1b; 3&#xff09;没有提供卸载函数。 一个设备 / 总线驱动程序在安装时首先要找到对应的硬件…

java时间处理SimpleDateFormat详解

文章目录 常用构造函数日期格式模式常见用法1. 格式化日期2. 解析日期字符串 注意事项示例扩展&#xff1a;指定区域和时区 SimpleDateFormat 是 Java 中用于日期和时间格式化的类&#xff0c;属于 java.text 包。它允许开发者将日期对象格式化为字符串&#xff0c;或者将字符…

夜莺运维指南之故障自愈

注意: 夜莺v7版本已内置故障自愈, 只需要更给n9e下的config.yaml 文件有关ibex配置即可 所谓的告警自愈&#xff0c;典型手段是在告警触发时自动回调某个 webhook 地址&#xff0c;在这个 webhook 里写告警自愈的逻辑&#xff0c;夜莺默认支持这种方式。另外&#xff0c;夜莺还…

LDR6500:音频双C支持,数字与模拟的完美结合

在当今数字化快速发展的时代&#xff0c;音频设备的兼容性和性能成为了用户关注的重点。LDR6500&#xff0c;作为乐得瑞科技精心研发的USB Power Delivery&#xff08;PD&#xff09;协议芯片&#xff0c;凭借其卓越的性能和广泛的应用兼容性&#xff0c;为音频设备领域带来了新…

python rstrip 的迷惑行为

在项目中&#xff0c;我需要把字符串末尾的一部分去掉&#xff0c;类似截断&#xff0c;我用ide的随笔提示&#xff0c;发现了rstrip这个方法&#xff0c;然后我试了下&#xff0c;满足我的需求&#xff0c;但在测试过程中&#xff0c;我发现了rstrip的一些行为很让我迷惑。 开…

计算机网络编程(Linux):I/O多路转接之 select,poll

I/O多路复用&#xff08;I/O Multiplexing&#xff09;是一种高效的网络编程技术&#xff0c;允许一个线程同时监控多个文件描述符的状态&#xff0c;当某个文件描述符就绪时进行相应处理。这种技术在高并发服务器中广泛使用。本文将介绍I/O多路复用的核心概念及在Linux中的实现…

【原生js案例】webApp实现鼠标移入移出相册放大缩小动画

图片相册这种动画效果也很常见&#xff0c;在我们的网站上。鼠标滑入放大图片&#xff0c;滑出就恢复原来的大小。现在我们使用运动定时器来实现这种滑动效果。 感兴趣的可以关注下我的系列课程【webApp之h5端实战】&#xff0c;里面有大量的css3动画效果制作原生知识分析&…

Spring Boot助力,一键解锁招聘全流程信息精细化管理

2系统相关技术 2.1 Java语言介绍 Java是由SUN公司推出&#xff0c;该公司于2010年被oracle公司收购。Java本是印度尼西亚的一个叫做爪洼岛的英文名称&#xff0c;也因此得来java是一杯正冒着热气咖啡的标识。Java语言在移动互联网的大背景下具备了显著的优势和广阔的前景&#…

Day28两个数组的交集

给定两个数组 nums1 和 nums2 &#xff0c;返回 它们的 交集 。输出结果中的每个元素一定是 唯一 的。我们可以 不考虑输出结果的顺序 。 class Solution{public int[] intersection(int[] nums1, int[] nums2) {Set<Integer> set new HashSet<>();for (int i :…

VRRP的知识点总结及实验

1、VRRP VRRP(Virtual Router Redundancy Protocol&#xff0c;虚拟路由器冗余协议)既能够实现网关的备份&#xff0c;又能解决多个网关之间互相冲突的问题&#xff0c;从而提高网络可靠性。 2、VRRP技术概述&#xff1a; 通过把几台路由设备联合组成一台虚拟的“路由设备”…

DP协议:概括

来了来了&#xff01;&#xff01;&#xff01; 开始之前扯点概念&#xff0c;知道DP好在哪里&#xff0c;以及看到它的发展趋势&#xff0c;才知道我们为什么有学习的必要。 DP的优势 DisplayPort&#xff08;DP&#xff09;协议作为一种专为数字音频和视频传输设计的高速串行…

Ant Design Vue 中 Tree 组件复选框修改样式

一、问题 最近需要实现一个业务需求&#xff0c;要修改勾选框中的颜色&#xff0c;默认勾选框的颜色是蓝色&#xff0c;现在需要变成绿色。 1、官网示例&#xff1a; 2、业务需求&#xff1a; 3、具体实现&#xff1a; HTML 部分代码 <template><div class"s…

【JavaWeb后端学习笔记】登录校验(JWT令牌技术、Interceptor拦截器、Filter过滤器)

登录校验 1、JWT令牌技术1.1 JWT令牌介绍1.2 Java代码生成与校验JWT令牌 2、Filter过滤器2.1 Filter过滤器的简单实现2.2 配置拦截路径2.3 Filter接口中的三个方法&#xff1a;2.4 Filter过滤器登录校验2.5 过滤器链 3、Interceptor拦截器3.1 拦截器(Interceptor)的简单实现3.2…

Linux系统下常用资源查看

一、查看CPU使用率 top 命令 top命令可以看到总体的系统运行状态和cpu的使用率 。 %us&#xff1a;表示用户空间程序的cpu使用率&#xff08;没有通过nice调度&#xff09; %sy&#xff1a;表示系统空间的cpu使用率&#xff0c;主要是内核程序。 %ni&#xff1a;表示用户空间且…

Flutter提示错误:无效的源发行版17

错误描述 Flutter从3.10.1 升级到3.19.4&#xff0c;在3.10.1的时候一切运行正常&#xff0c;但是当我将Flutter版本升级到3.19.4后&#xff0c;出现了下方的错误 FAILURE: Build failed with an exception.* What went wrong: Execution failed for task :device_info_plus:…

java+ssm+mysql学生信息管理系统

项目介绍&#xff1a; 使用javassmmysql开发的学生信息管理系统&#xff0c;系统包含超级管理员&#xff0c;系统管理员、教师、学生角色&#xff0c;功能如下&#xff1a; 超级管理员&#xff1a;管理员管理&#xff08;可以新增管理员&#xff09;&#xff1b;专业管理&…

PCB设计规范

过孔设计 过孔盖油工艺&#xff08;也成为连塞带印&#xff09;&#xff1a;常规工艺、免费工艺&#xff0c;无特殊情况也建议使用此工艺。过孔大小建议直径在0.3mm-0.5mm之间。最省钱&#xff0c;效果最好。 非金属化槽孔 PCB制造商在加工非金属化槽孔时通常采用锣刀加工。最…

【C语言】42道大厂笔试题目(选择题)

本篇博客给大家带来的是一些大厂笔试题目&#xff0c;题目难度&#xff1a;简单&#xff0c;适合小白快速入手C语言部分的大厂笔试难度。 &#x1f41f;&#x1f41f;文章专栏&#xff1a;C语言 &#x1f680;&#x1f680;若有问题评论区下讨论&#xff0c;我会及时回答 ❤❤欢…