[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 个列表.(一个无向图的相连节点(或节点)是一个子图,其中任意两个顶点通过路径相连,且不与 ...
随机推荐
- [转载] Android随笔之——PackageManager详解
本文转载自: http://www.cnblogs.com/travellife/p/3932823.html 参考:http://www.cnblogs.com/xingfuzzhd/p/33745 ...
- Java线程基础实例
概述 Java线程是一个在实战开发中经常使用的基础功能,而在Java中线程相关的类在java.lang和java.util.concurrent里 Thread package thread.base ...
- js Function.call
提到上述的概念之前,首先想说说javascript中函数的隐含参数:arguments Arguments 该对象代表正在执行的函数和调用它的函数的参数. [function.]arguments ...
- 最近遇到的jsfl开发问题总结
最近在用jsfl开发一套把MUGEN角色动画和数据导入flash的脚本.遇到不少问题,这里备忘一下: 1.绘制笔刷和填充的问题 更换填充和笔刷需要用如下的代码 而不是随便设置一下doc的属性 var ...
- DataGridView控件内建立日期选择编辑列
两个文件: CalendarColumn 类: public class CalendarColumn : DataGridViewColumn { public CalendarColumn() : ...
- ASP.NET MVC4中@model使用多个类型实例的方法
转http://blog.csdn.net/hulihui/article/details/48199897
- XAF进修二:在XAF中打开自定义的WinForm
在建造WinForm时须要加上一机关函数和Show办法 using System; using System.Collections.Generic; using System.ComponentMo ...
- NGUI BUG /各种坑
以下为:NGUI3.6具体使用过程中碰到的 各种BUG /各种坑 备忘 1.UIToggle 使用UIToggle组件实现多个tab标签互斥,如果是在代码中动态的设置显示某个tab标签对应的内容,则需 ...
- JS产生随机一注彩票
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- 查看oracle表中列的数据类型
一. SQLPLUS中,直接用 DESC[ribe] tablename 即可. 二.在外部应用程序调用查看ORACLE中的表结构时,只能用下面的语句代替: 1.看字段名与数据类型 select * ...