[ue4] Fixed up bone driver, only does position at the moment

This commit is contained in:
badlogic 2016-12-13 17:17:59 +01:00
parent 84766e3a99
commit ba70ec17b4
4 changed files with 9 additions and 4 deletions

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,7 @@ void USpineBoneDriverComponent::BeginPlay () {
void USpineBoneDriverComponent::BeforeUpdateWorldTransform(USpineSkeletonComponent* skeleton) {
AActor* owner = GetOwner();
if (owner) {
if (owner && skeleton == lastBoundComponent) {
skeleton->SetBoneWorldPosition(BoneName, owner->GetActorLocation() );
}
}
@ -25,7 +25,8 @@ void USpineBoneDriverComponent::TickComponent (float DeltaTime, ELevelTick TickT
USpineSkeletonComponent* skeleton = static_cast<USpineSkeletonComponent*>(Target->GetComponentByClass(USpineSkeletonComponent::StaticClass()));
if (skeleton != lastBoundComponent) {
// if (lastBoundComponent) lastBoundComponent->BeforeUpdateWorldTransform.RemoveAll(this);
skeleton->BeforeUpdateWorldTransform.AddDynamic(this, &USpineBoneDriverComponent::BeforeUpdateWorldTransform);
if (!skeleton->BeforeUpdateWorldTransform.GetAllObjects().Contains(this))
skeleton->BeforeUpdateWorldTransform.AddDynamic(this, &USpineBoneDriverComponent::BeforeUpdateWorldTransform);
lastBoundComponent = skeleton;
}
}

View File

@ -73,9 +73,13 @@ void USpineSkeletonComponent::SetBoneWorldPosition (const FString& BoneName, con
}
baseTransform = baseTransform.Inverse();
FVector localPosition = baseTransform.TransformVector(position);
FVector localPosition = baseTransform.TransformPosition(position);
float localX = 0, localY = 0;
spBone_worldToLocal(bone, localPosition.X, localPosition.Z, &localX, &localY);
if (bone->parent) {
spBone_worldToLocal(bone->parent, localPosition.X, localPosition.Z, &localX, &localY);
} else {
spBone_worldToLocal(bone, localPosition.X, localPosition.Z, &localX, &localY);
}
bone->x = localX;
bone->y = localY;
}