Skip to content

Commit

Permalink
[UE4] UBoneDriverComponent and UBoneFollowerComponent as USceneCompon…
Browse files Browse the repository at this point in the history
…ent (#1175)

* bone driver component as scene component

* bone follower component as scene component
  • Loading branch information
przemyslawlis authored and badlogic committed Oct 3, 2018
1 parent e7058b2 commit 566afe6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -46,6 +46,10 @@ class SPINEPLUGIN_API USpineBoneDriverComponent : public UActorComponent {
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class SPINEPLUGIN_API USpineBoneFollowerComponent : public UActorComponent {
class SPINEPLUGIN_API USpineBoneFollowerComponent : public USceneComponent {
GENERATED_BODY()

public:
Expand All @@ -45,6 +45,10 @@ class SPINEPLUGIN_API USpineBoneFollowerComponent : public UActorComponent {
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;

Expand Down

0 comments on commit 566afe6

Please sign in to comment.