mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
[ue4] Fixed SpineSkeletonComponent::GetBoneWorldTransform :D
This commit is contained in:
parent
724fdf13c0
commit
c66088a3f2
Binary file not shown.
Binary file not shown.
@ -54,7 +54,7 @@ void USpineSkeletonAnimationComponent::BeginPlay() {
|
|||||||
trackEntries.Empty();
|
trackEntries.Empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void USpineSkeletonAnimationComponent::TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
|
void USpineSkeletonAnimationComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
|
||||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||||
|
|
||||||
CheckState();
|
CheckState();
|
||||||
@ -68,6 +68,18 @@ void USpineSkeletonAnimationComponent::TickComponent (float DeltaTime, ELevelTic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void USpineSkeletonAnimationComponent::InternalTick(float DeltaTime) {
|
||||||
|
CheckState();
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
spAnimationState_update(state, DeltaTime);
|
||||||
|
spAnimationState_apply(state, skeleton);
|
||||||
|
BeforeUpdateWorldTransform.Broadcast(this);
|
||||||
|
spSkeleton_updateWorldTransform(skeleton);
|
||||||
|
AfterUpdateWorldTransform.Broadcast(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void USpineSkeletonAnimationComponent::CheckState () {
|
void USpineSkeletonAnimationComponent::CheckState () {
|
||||||
if (lastAtlas != Atlas || lastData != SkeletonData) {
|
if (lastAtlas != Atlas || lastData != SkeletonData) {
|
||||||
DisposeState();
|
DisposeState();
|
||||||
@ -106,6 +118,17 @@ void USpineSkeletonAnimationComponent::FinishDestroy () {
|
|||||||
Super::FinishDestroy();
|
Super::FinishDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void USpineSkeletonAnimationComponent::SetTimeScale(float timeScale) {
|
||||||
|
CheckState();
|
||||||
|
if (state) state->timeScale = timeScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
float USpineSkeletonAnimationComponent::GetTimeScale() {
|
||||||
|
CheckState();
|
||||||
|
if (state) return state->timeScale;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
UTrackEntry* USpineSkeletonAnimationComponent::SetAnimation (int trackIndex, FString animationName, bool loop) {
|
UTrackEntry* USpineSkeletonAnimationComponent::SetAnimation (int trackIndex, FString animationName, bool loop) {
|
||||||
CheckState();
|
CheckState();
|
||||||
if (state && spSkeletonData_findAnimation(skeleton->data, TCHAR_TO_UTF8(*animationName))) {
|
if (state && spSkeletonData_findAnimation(skeleton->data, TCHAR_TO_UTF8(*animationName))) {
|
||||||
|
|||||||
@ -17,11 +17,39 @@ bool USpineSkeletonComponent::SetSkin(const FString& skinName) {
|
|||||||
|
|
||||||
bool USpineSkeletonComponent::setAttachment (const FString& slotName, const FString& attachmentName) {
|
bool USpineSkeletonComponent::setAttachment (const FString& slotName, const FString& attachmentName) {
|
||||||
CheckState();
|
CheckState();
|
||||||
if (skeleton) return spSkeleton_setAttachment(skeleton, TCHAR_TO_UTF8(*slotName), TCHAR_TO_UTF8(*attachmentName));
|
if (skeleton) return spSkeleton_setAttachment(skeleton, TCHAR_TO_UTF8(*slotName), TCHAR_TO_UTF8(*attachmentName)) != 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FTransform USpineSkeletonComponent::GetBoneWorldTransform (const FString& BoneName) {
|
FTransform USpineSkeletonComponent::GetBoneWorldTransform (const FString& BoneName) {
|
||||||
|
CheckState();
|
||||||
|
if (skeleton) {
|
||||||
|
spBone* bone = spSkeleton_findBone(skeleton, TCHAR_TO_UTF8(*BoneName));
|
||||||
|
if (!bone->appliedValid) this->InternalTick(0);
|
||||||
|
if (!bone) return FTransform();
|
||||||
|
|
||||||
|
// Need to fetch the renderer component to get world transform of actor plus
|
||||||
|
// offset by renderer component and its parent component(s).
|
||||||
|
// FIXME add overloaded method that takes a base world transform?
|
||||||
|
FTransform baseTransform;
|
||||||
|
AActor* owner = GetOwner();
|
||||||
|
if (owner) {
|
||||||
|
USpineSkeletonRendererComponent* rendererComponent = static_cast<USpineSkeletonRendererComponent*>(owner->GetComponentByClass(USpineSkeletonRendererComponent::StaticClass()));
|
||||||
|
if (rendererComponent) baseTransform = rendererComponent->GetComponentTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
FVector position(bone->worldX, 0, bone->worldY);
|
||||||
|
FMatrix localTransform;
|
||||||
|
localTransform.SetIdentity();
|
||||||
|
localTransform.SetAxis(2, FVector(bone->a, 0, bone->c));
|
||||||
|
localTransform.SetAxis(0, FVector(bone->b, 0, bone->d));
|
||||||
|
localTransform.SetOrigin(FVector(bone->worldX, 0, bone->worldY));
|
||||||
|
localTransform = localTransform * baseTransform.ToMatrixWithScale();
|
||||||
|
|
||||||
|
FTransform result;
|
||||||
|
result.SetFromMatrix(localTransform);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
return FTransform();
|
return FTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +78,10 @@ void USpineSkeletonComponent::BeginPlay() {
|
|||||||
|
|
||||||
void USpineSkeletonComponent::TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
|
void USpineSkeletonComponent::TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
|
||||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||||
|
InternalTick(DeltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void USpineSkeletonComponent::InternalTick(float DeltaTime) {
|
||||||
CheckState();
|
CheckState();
|
||||||
|
|
||||||
if (skeleton) {
|
if (skeleton) {
|
||||||
|
|||||||
@ -188,6 +188,12 @@ public:
|
|||||||
virtual void FinishDestroy () override;
|
virtual void FinishDestroy () override;
|
||||||
|
|
||||||
// Blueprint functions
|
// Blueprint functions
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Components|Spine")
|
||||||
|
void SetTimeScale(float timeScale);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Components|Spine")
|
||||||
|
float GetTimeScale();
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category="Components|Spine")
|
UFUNCTION(BlueprintCallable, Category="Components|Spine")
|
||||||
UTrackEntry* SetAnimation (int trackIndex, FString animationName, bool loop);
|
UTrackEntry* SetAnimation (int trackIndex, FString animationName, bool loop);
|
||||||
|
|
||||||
@ -232,6 +238,7 @@ public:
|
|||||||
void GCTrackEntry(UTrackEntry* entry) { trackEntries.Remove(entry); }
|
void GCTrackEntry(UTrackEntry* entry) { trackEntries.Remove(entry); }
|
||||||
protected:
|
protected:
|
||||||
virtual void CheckState () override;
|
virtual void CheckState () override;
|
||||||
|
virtual void InternalTick(float DeltaTime) override;
|
||||||
virtual void DisposeState () override;
|
virtual void DisposeState () override;
|
||||||
|
|
||||||
spAnimationState* state;
|
spAnimationState* state;
|
||||||
|
|||||||
@ -62,6 +62,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void CheckState ();
|
virtual void CheckState ();
|
||||||
|
virtual void InternalTick(float DeltaTime);
|
||||||
virtual void DisposeState ();
|
virtual void DisposeState ();
|
||||||
|
|
||||||
spSkeleton* skeleton;
|
spSkeleton* skeleton;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user