Эх сурвалжийг харах

[ue] Add ResetPhysicsConstraints() to SpineSkeletonComponent and SpineWidget, closes #2615

Mario Zechner 1 жил өмнө
parent
commit
c85000b5f8

+ 1 - 0
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
 

BIN
spine-flutter/lib/assets/libspine_flutter.wasm


+ 24 - 0
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<PhysicsConstraint *> &constraints = skeleton->getPhysicsConstraints();
+		for (int i = 0, n = (int) constraints.size(); i < n; i++) {
+			constraints[i]->reset();
+		}
+	}
+}
+
 void USpineSkeletonComponent::BeginPlay() {
 	Super::BeginPlay();
 }

+ 24 - 0
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<PhysicsConstraint *> &constraints = skeleton->getPhysicsConstraints();
+		for (int i = 0, n = (int) constraints.size(); i < n; i++) {
+			constraints[i]->reset();
+		}
+	}
+}

+ 9 - 0
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;
 

+ 9 - 0
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;