From c85000b5f81bd93bcdd9cd2ae6e3789ac2907492 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Fri, 30 Aug 2024 13:39:15 +0200 Subject: [PATCH] [ue] Add ResetPhysicsConstraints() to SpineSkeletonComponent and SpineWidget, closes #2615 --- CHANGELOG.md | 1 + .../lib/assets/libspine_flutter.wasm | Bin 417918 -> 417940 bytes .../Private/SpineSkeletonComponent.cpp | 24 ++++++++++++++++++ .../SpinePlugin/Private/SpineWidget.cpp | 24 ++++++++++++++++++ .../Public/SpineSkeletonComponent.h | 9 +++++++ .../Source/SpinePlugin/Public/SpineWidget.h | 9 +++++++ 6 files changed, 67 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index daa028312..acac4b6ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,7 @@ - **Breaking**: Starting with Unreal Engine 5.3 imported `.skel`/`.json` and `.atlas` files in the same folder must NOT have a common prefix. E.g. `skeleton.json` and `skeleton.atlas` will not work. Make sure to rename at least one of the two files so there is no prefix collision, e.g. `skeleton-data.json` and `skeleton.atlas`. - Added compatibility with UE 5.3 - Added more example maps +- Added blueprint-callable methods `PhysicsTranslate()`, `PhysicsRotate()` and `ResetPhysicsConstraints()` (which will reset all physics constraints in the skeleton) to `SpineSkeletonComponent` and `SpineWidget`. ### Godot diff --git a/spine-flutter/lib/assets/libspine_flutter.wasm b/spine-flutter/lib/assets/libspine_flutter.wasm index cffc6246ba57442b30e518fb9d07e8fb31129ee1..89b0c594a93b46510e52913b59a0f7ad75e26754 100755 GIT binary patch delta 78 zcmex&Kyu1K$qgALOufgNvr5{tN*IBdX?s=)^CKn3&(nRUGh2%>GSw@vJ2JYlI4H33 gGAS@>FtKPb*-THI%c9V}VmdPrvus~6o%PxY0BS`V_y7O^ delta 61 zcmbPoQ1aga$qgALOy7?-XO*;Pl`sM^)ApuC*}if*>+2H$Fz*>c diff --git a/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonComponent.cpp b/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonComponent.cpp index 58aabe0d9..a48e786d3 100644 --- a/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonComponent.cpp +++ b/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonComponent.cpp @@ -287,6 +287,30 @@ float USpineSkeletonComponent::GetAnimationDuration(FString AnimationName) { return 0; } +void USpineSkeletonComponent::PhysicsTranslate(float x, float y) { + CheckState(); + if (skeleton) { + skeleton->physicsTranslate(x, y); + } +} + +void USpineSkeletonComponent::PhysicsRotate(float x, float y, float degrees) { + CheckState(); + if (skeleton) { + skeleton->physicsRotate(x, y, degrees); + } +} + +void USpineSkeletonComponent::ResetPhysicsConstraints() { + CheckState(); + if (skeleton) { + Vector &constraints = skeleton->getPhysicsConstraints(); + for (int i = 0, n = (int) constraints.size(); i < n; i++) { + constraints[i]->reset(); + } + } +} + void USpineSkeletonComponent::BeginPlay() { Super::BeginPlay(); } diff --git a/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineWidget.cpp b/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineWidget.cpp index dcdaac900..a6034adf4 100644 --- a/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineWidget.cpp +++ b/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineWidget.cpp @@ -524,3 +524,27 @@ void USpineWidget::ClearTrack(int trackIndex) { state->clearTrack(trackIndex); } } + +void USpineWidget::PhysicsTranslate(float x, float y) { + CheckState(); + if (skeleton) { + skeleton->physicsTranslate(x, y); + } +} + +void USpineWidget::PhysicsRotate(float x, float y, float degrees) { + CheckState(); + if (skeleton) { + skeleton->physicsRotate(x, y, degrees); + } +} + +void USpineWidget::ResetPhysicsConstraints() { + CheckState(); + if (skeleton) { + Vector &constraints = skeleton->getPhysicsConstraints(); + for (int i = 0, n = (int) constraints.size(); i < n; i++) { + constraints[i]->reset(); + } + } +} \ No newline at end of file diff --git a/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonComponent.h b/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonComponent.h index c040110ce..94dcf9eef 100644 --- a/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonComponent.h +++ b/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonComponent.h @@ -127,6 +127,15 @@ public: UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton") float GetAnimationDuration(FString AnimationName); + UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton") + void PhysicsTranslate(float x, float y); + + UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton") + void PhysicsRotate(float x, float y, float degrees); + + UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton") + void ResetPhysicsConstraints(); + UPROPERTY(BlueprintAssignable, Category = "Components|Spine|Skeleton") FSpineBeforeUpdateWorldTransformDelegate BeforeUpdateWorldTransform; diff --git a/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineWidget.h b/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineWidget.h index c02339638..0019a6eea 100644 --- a/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineWidget.h +++ b/spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineWidget.h @@ -153,6 +153,15 @@ public: UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton") float GetAnimationDuration(FString AnimationName); + UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton") + void PhysicsTranslate(float x, float y); + + UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton") + void PhysicsRotate(float x, float y, float degrees); + + UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton") + void ResetPhysicsConstraints(); + UPROPERTY(BlueprintAssignable, Category = "Components|Spine|Skeleton") FSpineWidgetBeforeUpdateWorldTransformDelegate BeforeUpdateWorldTransform;