Files
UnrealEngineUWP/Engine/Source/Runtime/AnimationCore/Public/FABRIK.h
helge mathee ec74f1a9d2 Merging
//Tasks/Fortnite/Dev-UEA-ControlRig/Engine/...

to //Fortnite/Main/Engine/...

Original CL: 6081637

#jira: UEA-490
#rb lina.halper


#ROBOMERGE-SOURCE: CL 6098916 via CL 6100686

[CL 6100754 by helge mathee in Main branch]
2019-04-25 18:03:23 -04:00

95 lines
2.7 KiB
C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "BoneIndices.h"
struct FBoneContainer;
/**
* Controller which implements the FABRIK IK approximation algorithm - see http://andreasaristidou.com/publications/FABRIK.pdf for details
*/
/** Transient structure for FABRIK node evaluation */
/** Transient structure for FABRIK node evaluation */
struct FABRIKChainLink
{
public:
/** Position of bone in component space. */
FVector Position;
/** Distance to its parent link. */
float Length;
/** Bone Index in SkeletalMesh */
int32 BoneIndex;
/** Transform Index that this control will output */
int32 TransformIndex;
/** Default Direction to Parent */
FVector DefaultDirToParent;
/** Child bones which are overlapping this bone.
* They have a zero length distance, so they will inherit this bone's transformation. */
TArray<int32> ChildZeroLengthTransformIndices;
FABRIKChainLink()
: Position(FVector::ZeroVector)
, Length(0.f)
, BoneIndex(INDEX_NONE)
, TransformIndex(INDEX_NONE)
, DefaultDirToParent(FVector(-1.f, 0.f, 0.f))
{
}
FABRIKChainLink(const FVector& InPosition, const float InLength, const FCompactPoseBoneIndex& InBoneIndex, const int32& InTransformIndex)
: Position(InPosition)
, Length(InLength)
, BoneIndex(InBoneIndex.GetInt())
, TransformIndex(InTransformIndex)
, DefaultDirToParent(FVector(-1.f, 0.f, 0.f))
{
}
FABRIKChainLink(const FVector& InPosition, const float InLength, const FCompactPoseBoneIndex& InBoneIndex, const int32& InTransformIndex, const FVector& InDefaultDirToParent)
: Position(InPosition)
, Length(InLength)
, BoneIndex(InBoneIndex.GetInt())
, TransformIndex(InTransformIndex)
, DefaultDirToParent(InDefaultDirToParent)
{
}
FABRIKChainLink(const FVector& InPosition, const float InLength, const int32 InBoneIndex, const int32 InTransformIndex)
: Position(InPosition)
, Length(InLength)
, BoneIndex(InBoneIndex)
, TransformIndex(InTransformIndex)
, DefaultDirToParent(FVector(-1.f, 0.f, 0.f))
{
}
static ANIMATIONCORE_API FVector GetDirectionToParent(const FBoneContainer& BoneContainer, FCompactPoseBoneIndex BoneIndex);
};
namespace AnimationCore
{
/**
* Fabrik solver
*
* This solves FABRIK
*
* @param Chain Array of chain data
* @param TargetPosition Target for the IK
* @param MaximumReach Maximum Reach
* @param Precision Precision
* @param MaxIteration Number of Max Iteration
*
* @return true if modified. False if not.
*/
ANIMATIONCORE_API bool SolveFabrik(TArray<FABRIKChainLink>& InOutChain, const FVector& TargetPosition, float MaximumReach, float Precision, int32 MaxIteration);
};