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

View File

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