Hey,
So my binding looks like that, I’m still searching the final class to move a bone in unreal (don’t laught please)
#pragma once
#include "DxyzFacialController.generated.h"
USTRUCT()
struct FDxyzFacialController
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
int32 Type;//0 bone / 1 Morph / -1 uninitialized
UPROPERTY()
USkeletalMeshComponent* Parent;
UPROPERTY()
int32 BoneIndex;
UPROPERTY()
FBodyInstance Body;
UPROPERTY()
FName MorphName;
//Constructor
FDxyzFacialController():
Type(-1), Parent(nullptr), BoneIndex(-1), MorphName(""), Body()
{
}
};
my binding method , I would like to create a shortcut access :
void HandleSocketXMLReceived()
{
UE_LOG(DxyzLog, Log, TEXT("HandleSocketXMLReceived: XML Received"));
if (Client.IsValid())
{
for (int i = 0; i < Client->ChannelList.Num(); ++i)
{
FDxyzFacialController ctrl;
bool found = false;
if (Client->ChannelList[i].ClassName.ToLower() == "component")//mean bone
{
ctrl.Type = 0;//Bone
UE_LOG(DxyzLog, Log, TEXT("searching : %s"), *(Client->ChannelList[i].Name));
for (TObjectIterator<USkeletalMeshComponent> Itr; Itr && !found; ++Itr)
{
UE_LOG(DxyzLog, Log, TEXT("Scan USkeletalMeshComponent: %s %s"), *(Itr->GetName()), *(Itr->GetFullName()));
int32 BoneIndex = Itr->GetBoneIndex(FName(*(Client->ChannelList[i].Name)));// Will return INDEX_NONE if bone not found.
FBodyInstance * Body = Itr->GetBodyInstance
(
FName(*(Client->ChannelList[i].Name))
);
if (INDEX_NONE != BoneIndex)
{
UE_LOG(DxyzLog, Log, TEXT("Found USkeletalMeshComponent: Bone Index %d"), BoneIndex);
ctrl.Parent = (*Itr);
ctrl.BoneIndex = BoneIndex;
ctrl.Body = (*Body);
found = true;
}
}
}
else if (Client->ChannelList[i].ClassName.ToLower() == "blendshapetarget")//mean morph
{
ctrl.Type = 1;//Morph
int LastOpenBracketIndex = 0;
if (!Client->ChannelList[i].Name.FindLastChar('[', LastOpenBracketIndex))
{
UE_LOG(DxyzLog, Log, TEXT("Blendshape name parsing failed, can't find [ char in %s"), *( Client->ChannelList[i].Name));
}
int LastCloseBracketIndex;
if (!Client->ChannelList[i].Name.FindLastChar(']', LastCloseBracketIndex))
{
UE_LOG(DxyzLog, Log, TEXT("Blendshape name parsing failed, can't find ] char in %s"), *(Client->ChannelList[i].Name));
}
FString ParentMeshName = Client->ChannelList[i].Name.LeftChop(LastOpenBracketIndex);
FString TargetName = Client->ChannelList[i].Name.RightChop(LastOpenBracketIndex).LeftChop(LastCloseBracketIndex);
UE_LOG(DxyzLog, Log, TEXT("Scan searching : %s %s"), *(ParentMeshName), *(TargetName));
for (TObjectIterator<USkeletalMeshComponent> Itr; Itr && !found; ++Itr)
{
UE_LOG(DxyzLog, Log, TEXT("Scan USkeletalMeshComponent: %s"), *(Itr->GetName()));
if (Itr->GetName().ToLower() == ParentMeshName.ToLower())
{
UE_LOG(DxyzLog, Log, TEXT("Found USkeletalMeshComponent: %s"), *(Itr->GetName()));
UMorphTarget* Morph = Itr->FindMorphTarget(FName(*TargetName));
if (Morph != NULL)
{
UE_LOG(DxyzLog, Log, TEXT("Found UMorphTarget: %s"), *(TargetName));
ctrl.Parent = (*Itr);
ctrl.MorphName = FName(*TargetName);
found = true;
}
}
}
}
if (ctrl.Type != -1)
fControllers.Add(ctrl);
else
{
UE_LOG(DxyzLog, Log, TEXT("Error Channel not found %s"), *(Client->ChannelList[i].Name));
}
}
}
}
and my frame received delegate :
void HandleSocketFrameReceived()
{
UE_LOG(DxyzLog, Log, TEXT("HandleSocketFrameReceived: Frame Received"));
if (fControllers.Num() == 0)return;
if (Client->ChannelList.Num() != fControllers.Num())return;
if (Client->CoeffCount == 0)return;
if (Client->CoeffBuffer == NULL)return;
for (int i = 0; i < fControllers.Num(); i++)
{
if (fControllers[i].Type == 0)//bone
{
FVector RelativeLocation(Client->CoeffBuffer[Client->ChannelList[i].CoeffBufferIndex],
Client->CoeffBuffer[Client->ChannelList[i].CoeffBufferIndex + 1],
Client->CoeffBuffer[Client->ChannelList[i].CoeffBufferIndex + 2]);
FRotator RelativeRotation(const FQuat(Client->CoeffBuffer[Client->ChannelList[i].CoeffBufferIndex + 3]//InX
, Client->CoeffBuffer[Client->ChannelList[i].CoeffBufferIndex + 4]//InY
, Client->CoeffBuffer[Client->ChannelList[i].CoeffBufferIndex + 5]//InZ
, Client->CoeffBuffer[Client->ChannelList[i].CoeffBufferIndex + 6]//InA
));
FVector RelativeScale3D(Client->CoeffBuffer[Client->ChannelList[i].CoeffBufferIndex + 7],
Client->CoeffBuffer[Client->ChannelList[i].CoeffBufferIndex + 8],
Client->CoeffBuffer[Client->ChannelList[i].CoeffBufferIndex + 9]);
FTransform RelativeTransform(RelativeRotation, RelativeLocation, RelativeScale3D);
const FBoneTransform BoneTransform(fControllers[i].BoneIndex, RelativeTransform);
fControllers[i].Body.SetBodyTransform(RelativeTransform, true);
}
else if (fControllers[i].Type == 1)//morph
{
fControllers[i].Parent->SetMorphTarget(fControllers[i].MorphName, Client->CoeffBuffer[Client->ChannelList[i].CoeffBufferIndex]);
}
}
}
No movement at all