[UE4] UBoneDriverComponent and UBoneFollowerComponent as USceneComponent (#1175)

* bone driver component as scene component

* bone follower component as scene component
This commit is contained in:
przemyslawlis 2018-10-03 13:23:02 +02:00 committed by Mario Zechner
parent e7058b225c
commit 566afe6c57
4 changed files with 33 additions and 11 deletions

View File

@ -41,9 +41,14 @@ void USpineBoneDriverComponent::BeginPlay () {
}
void USpineBoneDriverComponent::BeforeUpdateWorldTransform(USpineSkeletonComponent* skeleton) {
AActor* owner = GetOwner();
if (owner && skeleton == lastBoundComponent) {
skeleton->SetBoneWorldPosition(BoneName, owner->GetActorLocation() );
if (skeleton == lastBoundComponent) {
if (UseComponentTransform) {
skeleton->SetBoneWorldPosition(BoneName, GetComponentLocation());
}
else {
AActor* owner = GetOwner();
if (owner) skeleton->SetBoneWorldPosition(BoneName, owner->GetActorLocation());
}
}
}

View File

@ -43,14 +43,23 @@ void USpineBoneFollowerComponent::BeginPlay () {
void USpineBoneFollowerComponent::TickComponent ( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) {
Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
AActor* owner = GetOwner();
if (Target && owner) {
if (Target) {
USpineSkeletonComponent* skeleton = static_cast<USpineSkeletonComponent*>(Target->GetComponentByClass(USpineSkeletonComponent::StaticClass()));
if (skeleton) {
FTransform transform = skeleton->GetBoneWorldTransform(BoneName);
if (UsePosition) owner->SetActorLocation(transform.GetLocation());
if (UseRotation) owner->SetActorRotation(transform.GetRotation());
if (UseScale) owner->SetActorScale3D(transform.GetScale3D());
if (UseComponentTransform) {
if (UsePosition) SetWorldLocation(transform.GetLocation());
if (UseRotation) SetWorldRotation(transform.GetRotation());
if (UseScale) SetWorldScale3D(transform.GetScale3D());
}
else {
AActor* owner = GetOwner();
if (owner) {
if (UsePosition) owner->SetActorLocation(transform.GetLocation());
if (UseRotation) owner->SetActorRotation(transform.GetRotation());
if (UseScale) owner->SetActorScale3D(transform.GetScale3D());
}
}
}
}
}

View File

@ -30,13 +30,13 @@
#pragma once
#include "Components/ActorComponent.h"
#include "Components/SceneComponent.h"
#include "SpineBoneDriverComponent.generated.h"
class USpineSkeletonComponent;
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class SPINEPLUGIN_API USpineBoneDriverComponent : public UActorComponent {
class SPINEPLUGIN_API USpineBoneDriverComponent : public USceneComponent {
GENERATED_BODY()
public:
@ -46,6 +46,10 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString BoneName;
//Uses just this component when set to true. Updates owning actor otherwise.
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool UseComponentTransform = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool UsePosition = true;

View File

@ -35,7 +35,7 @@
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class SPINEPLUGIN_API USpineBoneFollowerComponent : public UActorComponent {
class SPINEPLUGIN_API USpineBoneFollowerComponent : public USceneComponent {
GENERATED_BODY()
public:
@ -45,6 +45,10 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString BoneName;
//Updates just this component when set to true. Updates owning actor otherwise.
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool UseComponentTransform = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool UsePosition = true;