[ue4] Query methods for SpineSkeletonComponent and UTrackEntry. Closes #1289.

This commit is contained in:
badlogic 2019-03-06 15:11:24 +01:00
parent e7e64ebf2f
commit 75f21f846c
3 changed files with 112 additions and 10 deletions

View File

@ -42,7 +42,7 @@ USpineSkeletonComponent::USpineSkeletonComponent () {
bAutoActivate = true; bAutoActivate = true;
} }
bool USpineSkeletonComponent::SetSkin(const FString& skinName) { bool USpineSkeletonComponent::SetSkin (const FString skinName) {
CheckState(); CheckState();
if (skeleton) { if (skeleton) {
Skin* skin = skeleton->getData()->findSkin(TCHAR_TO_UTF8(*skinName)); Skin* skin = skeleton->getData()->findSkin(TCHAR_TO_UTF8(*skinName));
@ -53,7 +53,24 @@ bool USpineSkeletonComponent::SetSkin(const FString& skinName) {
else return false; else return false;
} }
bool USpineSkeletonComponent::SetAttachment (const FString& slotName, const FString& attachmentName) { void USpineSkeletonComponent::GetSkins (TArray<FString> &Skins) {
CheckState();
if (skeleton) {
for (size_t i = 0, n = skeleton->getData()->getSkins().size(); i < n; i++) {
Skins.Add(skeleton->getData()->getSkins()[i]->getName().buffer());
}
}
}
bool USpineSkeletonComponent::HasSkin (const FString skinName) {
CheckState();
if (skeleton) {
return skeleton->getData()->findAnimation(TCHAR_TO_UTF8(*skinName)) != nullptr;
}
return false;
}
bool USpineSkeletonComponent::SetAttachment (const FString slotName, const FString attachmentName) {
CheckState(); CheckState();
if (skeleton) { if (skeleton) {
if (!skeleton->getAttachment(TCHAR_TO_UTF8(*slotName), TCHAR_TO_UTF8(*attachmentName))) return false; if (!skeleton->getAttachment(TCHAR_TO_UTF8(*slotName), TCHAR_TO_UTF8(*attachmentName))) return false;
@ -180,6 +197,58 @@ void USpineSkeletonComponent::GetBones(TArray<FString> &Bones) {
} }
} }
bool USpineSkeletonComponent::HasBone (const FString BoneName) {
CheckState();
if (skeleton) {
return skeleton->getData()->findBone(TCHAR_TO_UTF8(*BoneName)) != nullptr;
}
return false;
}
void USpineSkeletonComponent::GetSlots (TArray<FString> &Slots) {
CheckState();
if (skeleton) {
for (size_t i = 0, n = skeleton->getSlots().size(); i < n; i++) {
Slots.Add(skeleton->getSlots()[i]->getData().getName().buffer());
}
}
}
bool USpineSkeletonComponent::HasSlot (const FString SlotName) {
CheckState();
if (skeleton) {
return skeleton->getData()->findSlot(TCHAR_TO_UTF8(*SlotName)) != nullptr;
}
return false;
}
void USpineSkeletonComponent::GetAnimations(TArray<FString> &Animations) {
CheckState();
if (skeleton) {
for (size_t i = 0, n = skeleton->getData()->getAnimations().size(); i < n; i++) {
Animations.Add(skeleton->getData()->getAnimations()[i]->getName().buffer());
}
}
}
bool USpineSkeletonComponent::HasAnimation(FString AnimationName) {
CheckState();
if (skeleton) {
return skeleton->getData()->findAnimation(TCHAR_TO_UTF8(*AnimationName)) != nullptr;
}
return false;
}
float USpineSkeletonComponent::GetAnimationDuration(FString AnimationName) {
CheckState();
if (skeleton) {
Animation *animation = skeleton->getData()->findAnimation(TCHAR_TO_UTF8(*AnimationName));
if (animation == nullptr) return 0;
else return animation->getDuration();
}
return 0;
}
void USpineSkeletonComponent::BeginPlay() { void USpineSkeletonComponent::BeginPlay() {
Super::BeginPlay(); Super::BeginPlay();
} }

View File

@ -157,6 +157,15 @@ public:
UFUNCTION(BlueprintCallable, Category="Components|Spine|TrackEntry") UFUNCTION(BlueprintCallable, Category="Components|Spine|TrackEntry")
void SetMixDuration(float mixDuration) { if (entry) entry->setMixDuration(mixDuration); } void SetMixDuration(float mixDuration) { if (entry) entry->setMixDuration(mixDuration); }
UFUNCTION(BlueprintCallable, Category = "Components|Spine|TrackEntry")
FString getAnimationName() { return entry ? entry->getAnimation()->getName().buffer() : ""; }
UFUNCTION(BlueprintCallable, Category = "Components|Spine|TrackEntry")
float getAnimationDuration() { return entry ? entry->getAnimation()->getDuration(): 0; }
UFUNCTION(BlueprintCallable, Category = "Components|Spine|TrackEntry")
float isValidAnimation() { return entry != nullptr; }
UPROPERTY(BlueprintAssignable, Category = "Components|Spine|TrackEntry") UPROPERTY(BlueprintAssignable, Category = "Components|Spine|TrackEntry")
FSpineAnimationStartDelegate AnimationStart; FSpineAnimationStartDelegate AnimationStart;

View File

@ -54,11 +54,17 @@ public:
spine::Skeleton* GetSkeleton () { return skeleton; }; spine::Skeleton* GetSkeleton () { return skeleton; };
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton") UFUNCTION(BlueprintPure, Category = "Components|Spine|Skeleton")
bool SetSkin (const FString& SkinName); void GetSkins(TArray<FString> &Skins);
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton") UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
bool SetAttachment (const FString& slotName, const FString& attachmentName); bool SetSkin (const FString SkinName);
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
bool HasSkin(const FString SkinName);
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
bool SetAttachment (const FString slotName, const FString attachmentName);
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton") UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
FTransform GetBoneWorldTransform (const FString& BoneName); FTransform GetBoneWorldTransform (const FString& BoneName);
@ -93,6 +99,24 @@ public:
UFUNCTION(BlueprintPure, Category = "Components|Spine|Skeleton") UFUNCTION(BlueprintPure, Category = "Components|Spine|Skeleton")
void GetBones(TArray<FString> &Bones); void GetBones(TArray<FString> &Bones);
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
bool HasBone(const FString BoneName);
UFUNCTION(BlueprintPure, Category = "Components|Spine|Skeleton")
void GetSlots(TArray<FString> &Slots);
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
bool HasSlot(const FString SlotName);
UFUNCTION(BlueprintPure, Category = "Components|Spine|Skeleton")
void GetAnimations(TArray<FString> &Animations);
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
bool HasAnimation(FString AnimationName);
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
float GetAnimationDuration(FString AnimationName);
UPROPERTY(BlueprintAssignable, Category = "Components|Spine|Skeleton") UPROPERTY(BlueprintAssignable, Category = "Components|Spine|Skeleton")
FSpineBeforeUpdateWorldTransformDelegate BeforeUpdateWorldTransform; FSpineBeforeUpdateWorldTransformDelegate BeforeUpdateWorldTransform;