Hi guys,
I want to re-create a simple blueprint-based VR IK setup, but written in C++. I’ve been mirroring the Blueprint process in C++, and so far so good. It turns out that I can’t easily type everything out in C++ and have it all run. Instead, it looks like I’ll do most of the heavy lifting in C++ and pass over all of that heavy lifting in the form of a custom Anim Graph Node. However, I don’t understand the structure of the custom Anim Node, which means that I don’t know where to type the IK logic code.
The idea I’m going after is pretty simple. The blueprint-based Simple VR IK works like this:
1) It stores the motion controller transforms in the EventGraph portion of the Anim Instance.
1.a) I mirrored this process by creating my own custom Anim Instance in C
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyVRAnimInstance.h"
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "GameFramework/Actor.h"
#include "VRPawn.h"
#include "Engine/Classes/Animation/AnimInstance.h"
#include "Runtime/HeadMountedDisplay/Public/MotionControllerComponent.h"
UMyVRAnimInstance::UMyVRAnimInstance()
{
Speed = 0.0;
}
void UMyVRAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
Super::NativeUpdateAnimation(DeltaSeconds);
AActor* OwningActor = GetOwningActor();
APawn* PawnOwner = TryGetPawnOwner();
AVRPawn* myVRpawn;
myVRpawn = Cast<AVRPawn>(PawnOwner);
if(OwningActor != nullptr)
{
Speed = OwningActor->GetVelocity().Size();
}
if (PawnOwner != nullptr && myVRpawn != nullptr)
{
LMotionControllerTransform = myVRpawn->LeftMotionController->GetComponentTransform();
RMotionControllerTransform = myVRpawn->RightMotionController->GetComponentTransform();
}
}
2) The simple blueprint VR IK example then pulls the Motion Controller transforms within the AnimGraph section of the Anim Instance, and applies FABRIK IK logic to it.
2.a) In an attempt to mirror the process above, I created an empty shell of a custom AnimNode. However, I don’t know where to place the FABRIK logic. Where do I place the FABRIK logic? In which section of my Custom Anim Node? Below i include an image of the Theoretical AnimGraphNode (right now it’s just a shell, but this is how I envision it working). Further below that, I am including my custom Anim Node cpp file.
CUSTOM ANIM GRAPH NODE CPP FILE BELOW
Where do I place the FABRIK functions and how do I return them back out from the node, as in the image above?
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyAnimNode.h"
#include "CoreMinimal.h"
#include "MyVRGame.h"
#include "Animation/AnimInstanceProxy.h"
FMyAnimNode::FMyAnimNode()
{
}
void FMyAnimNode::Initialize_AnyThread(const FAnimationInitializeContext& Context)
{
Super::Initialize_AnyThread(Context);
BasePose.Initialize(Context);
}
void FMyAnimNode::CacheBones_AnyThread(const FAnimationCacheBonesContext& Context)
{
BasePose.CacheBones(Context);
}
void FMyAnimNode::Update_AnyThread(const FAnimationUpdateContext& Context)
{
GetEvaluateGraphExposedInputs().Execute(Context);
BasePose.Update(Context);
}
void FMyAnimNode::Evaluate_AnyThread(FPoseContext& Output)
{
// Evaluate the input
BasePose.Evaluate(Output);
//Output.Pose.GetBoneContainer().
}
void FMyAnimNode::GatherDebugData(FNodeDebugData& DebugData) {
FString DebugLine = DebugData.GetNodeName(this);
DebugData.AddDebugItem(DebugLine);
BasePose.GatherDebugData(DebugData);
}