[UE4][Custom Animation Graph Node]Evaluate Pose by Curve
目的:根据曲线值获得当前动作帧。用于实现各种通过曲线同步的功能。
方法:继承FAnimNode_Base创建自定义动画节点。重写Evaluate部分。创建相应的AnimGraphNode。可参考前一篇http://blog.csdn.net/u010831746/article/details/50733287
Evaluate : 1. 根据曲线Value(Y轴)值获得Time(X轴)值。
曲线KeyArray所在位置。AnimSequenceBase : RawCurveData.
类型AnimCurveTypes.h:FRawCurveTracks
曲线记录是TArray<FRichCurveKey>。每个key中存有Time和Value。根据输入的CurveValue,遍历Array查找Value最接近的Key,返回Time。
2.根据Time值获得动画POS
AnimSequence->GetAnimationPose(…, Time, …)输出Pose。
主要代码:
AnimNode_EvaluatePose.h
/*!
* \file AnimNode_EvaluatePose.h
* \date 2016/03/29 17:45
*
* \author: Jia Zhipeng
* Contact: jiazhipeng@pwrd.com
*
* \brief: 根据曲线获得当前Pose. Get Pose based on curve value.
*
* \note:
*/
#pragma once
#include "Animation/AnimNodeBase.h"
//#include "AnimNode_SkeletalControlBase.h"
#include "AnimNode_EvaluatePose.generated.h" USTRUCT()
struct FAnimNode_EvaluatePose :public FAnimNode_Base
{
GENERATED_USTRUCT_BODY() UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Settings, meta = (PinShownByDefault))
UAnimSequenceBase* Sequence; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Settings, meta = (PinShownByDefault))
FName CurveName; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Settings, meta = (PinShownByDefault))
float CurveValue; UAnimInstance* MyInstance;
public:
// Constructor
FAnimNode_EvaluatePose(); // FAnimNode_Base interface
virtual void Initialize(const FAnimationInitializeContext& Context) override;
virtual void CacheBones(const FAnimationCacheBonesContext& Context) override;
virtual void Evaluate(FPoseContext& Output) override;
virtual void OverrideAsset(UAnimationAsset* NewAsset) override;
virtual void GatherDebugData(FNodeDebugData& DebugData) override;
// End of FAnimNode_Base interface// };
AnimNode_EvaluatePose.cpp
//Iterate Animation's curve's keys to get current time
void FAnimNode_EvaluatePose::Evaluate(FPoseContext& Output)
{
//CurveValue is connected to AnimInstance’s variable in AnimBlueprint, but it is not updated when executing this node. So how to get variable of AnimInstance? 2 ways.
//1. EvaluateGraphExposedInputs.Execute(Output); Cause crash. Explore this method in the future.
//2. Get property from AnimInstance. But in this way, the variable’s name has to be specified. Temporarily use this method.
UFloatProperty* FloatProp = Cast<UFloatProperty>(PW_PropertyTools::FindProperty(MyInstance, TEXT("Horiz Movement Speed")));
if (!FloatProp)
{
UE_LOG(LogTemp, Warning, TEXT("Horiz Movement Speed Not found"));
return;
}
float HorzSpeed = FloatProp->GetPropertyValue_InContainer(MyInstance);
CurveValue = HorzSpeed; USkeleton* Skeleton = Sequence->GetSkeleton();
if (!Skeleton)
{
UE_LOG(LogTemp, Warning, TEXT("FAnimNode_EvaluatePose::Evaluate fail to find skeleton"));
return;
}
FSmartNameMapping* NameMapping = Skeleton->SmartNames.GetContainer(USkeleton::AnimCurveMappingName);
// retrieve curve
USkeleton::AnimCurveUID Uid;
if (!NameMapping->Exists(CurveName))
{
UE_LOG(LogTemp, Warning, TEXT("FAnimNode_EvaluatePose::Evaluate fail to find curve %s"), *CurveName.ToString());
return;
} Uid = *NameMapping->FindUID(CurveName);
FFloatCurve * CurveToCompute = static_cast<FFloatCurve*>(Sequence->RawCurveData.GetCurveData(Uid));
if (!CurveToCompute)
{
UE_LOG(LogTemp, Warning, TEXT("FAnimNode_EvaluatePose::Evaluate fail to find curve %s"), *CurveName.ToString());
return;
} auto FloatCurve = CurveToCompute->FloatCurve;
float OutTime = 0.0f;
BinarySeach(FloatCurve, CurveValue, OutTime);
if ((Sequence != NULL) && (Output.AnimInstance->CurrentSkeleton->IsCompatible(Sequence->GetSkeleton())))
{
Sequence->GetAnimationPose(Output.Pose, Output.Curve, FAnimExtractContext(OutTime, Output.AnimInstance->ShouldExtractRootMotion()));
}
else
{
Output.ResetToRefPose();
}
}
[UE4][Custom Animation Graph Node]Evaluate Pose by Curve的更多相关文章
- UE4 custom depth 自定义深度
用途1: 半透明材质中实现遮挡Mesh自己其他部分的效果. 不遮挡效果如下: 遮挡后效果如下: 实现方法: 深度信息是越远值越大,使用两个Mesh,一个正常渲染,另一个渲染到custom depth ...
- tbb flow graph node types
- 泡泡一分钟: A Linear Least Square Initialization Method for 3D Pose Graph Optimization Problem
张宁 A Linear Least Square Initialization Method for 3D Pose Graph Optimization Problem "链接:https ...
- UE4高级运动系统(Advanced Locomotion System V3)插件分析
Advanced Locomotion System V3是虚幻商城的一款第三方插件.它相比UE4的基础走跑跳表现,实现了更多动作游戏里常用的运动特性,虽然价格定价不菲,依然备受关注.笔者试用了这款插 ...
- Qt5 QtQuick系列----QtQuick的Secne Graph剖析(1)
教是言词, 实不是道,道本无言, 言说是妄.------- 达摩 Qt 5提出了一个新的渲染底层,以替代Qt4时期的Graphics View,这个渲染底层就是Scene Graph.Scene Gr ...
- [LintCode] Find the Weak Connected Component in the Directed Graph
Find the number Weak Connected Component in the directed graph. Each node in the graph contains a ...
- Lintcode: Route Between Two Nodes in Graph
Given a directed graph, design an algorithm to find out whether there is a route between two nodes. ...
- 【LEETCODE OJ】Clone Graph
Problem link: http://oj.leetcode.com/problems/clone-graph/ This problem is very similar to "Cop ...
- lintcode:Find the Connected Component in the Undirected Graph 找出无向图汇总的相连要素
题目: 找出无向图汇总的相连要素 请找出无向图中相连要素的个数. 图中的每个节点包含其邻居的 1 个标签和 1 个列表.(一个无向图的相连节点(或节点)是一个子图,其中任意两个顶点通过路径相连,且不与 ...
随机推荐
- 2016国内最值得期待的响应式前端框架pintuer(拼图)--http://www.pintuer.com
近期,需要将项目从pc端的应用扩展到移动端. 当然移动框架的第一选择必然是bootstrap,但是bootstrap作为移动端明显过于死板,而且作为国外的产品,对于国内的应用明显水土不服.框架里总有那 ...
- [OC笔记]@property之个人理解,大神轻拍
/** * 一个简单的对象 * * @author suzhen * */ public class SimpleObjcet { /** * 声明一个age字段 */ private Object ...
- deep learning on object detection
回归工作一周,忙的头晕,看了两三篇文章,主要在写各种文档和走各种办事流程了-- 这次来写写object detection最近看的三篇文章吧.都不是最近的文章,但是是今年的文章,我也想借此让自己赶快熟 ...
- Android消息的提示,Toast吐司方式
1:选中某个控件进行触发 2:触发事件进行监听,然后绑定Toast对象进行消息提示 1,创建Android项目的时候,自带的一个Activity,我们看看代码 package com.example. ...
- NMAP 基本用法
Nmap 用途: 1.通过对设备或者防火墙的探测来审计它的安全性. 2.探测目标主机所开放的端口. 3.网络存储,网络映射,维护和资产管理.(这个有待深入) 4.通过识别新的服务器审计网络的安全性. ...
- Git之VS2010实践
对于我们经常在VS2010下编程的开发人员来说,强大的SCM工具Git貌似对我们很陌生.对于Git,我在我的另一篇博客<Git学习笔记>中已做过介绍,下面我再简单介绍一下Git在VS201 ...
- NPOI 导入导出excel 支持 03 07
因为微软的office成本太高了,所以开发项目的时候电脑上没安装office,而是安装了wps.但开发语言用的是C#,所以直接调用微软的office组件是很方便的,但一方面慢,一方面成本高,所以从网上 ...
- [转]Snappy压缩库安装和使用之一
Snappy压缩库安装和使用之一 原文地址:http://blog.csdn.net/luo6620378xu/article/details/8521223 近日需要在毕业设计中引入一个压缩库,要求 ...
- python学习-day14-前端之html、css
一.Html 1.本质:一个规则,浏览器能任务的规则 2.开发者: 学习Html规则 开发后台程序: - 写Html文件(充当模板的作用) ***** ...
- 调整static变量初始化顺序的一个办法
// wrap the LaunchDir variable in a function to work around static/global initialization order stati ...