浏览代码

[ue4] Closes #2234, add SpineWidget::GetBonePosition in the skeleton coordinate system.

badlogic 2 年之前
父节点
当前提交
39d544ce86

二进制
spine-ue4/Content/GettingStarted/Blueprints/UmgRaptor.uasset


+ 19 - 0
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineWidget.cpp

@@ -331,6 +331,25 @@ bool USpineWidget::HasBone(const FString BoneName) {
 	return false;
 	return false;
 }
 }
 
 
+FTransform USpineWidget::GetBoneTransform(const FString& BoneName) {
+	CheckState();
+	if (skeleton) {
+		Bone *bone = skeleton->findBone(TCHAR_TO_UTF8(*BoneName));
+		if (!bone) return FTransform();
+		
+		FMatrix localTransform;
+		localTransform.SetIdentity();
+		localTransform.SetAxis(2, FVector(bone->getA(), 0, bone->getC()));
+		localTransform.SetAxis(0, FVector(bone->getB(), 0, bone->getD()));
+		localTransform.SetOrigin(FVector(bone->getWorldX(), 0, bone->getWorldY()));
+
+		FTransform result;
+		result.SetFromMatrix(localTransform);
+		return result;
+	}
+	return FTransform();
+}
+
 void USpineWidget::GetSlots(TArray<FString> &Slots) {
 void USpineWidget::GetSlots(TArray<FString> &Slots) {
 	CheckState();
 	CheckState();
 	if (skeleton) {
 	if (skeleton) {

+ 3 - 0
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineWidget.h

@@ -132,6 +132,9 @@ public:
 	UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
 	UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
 	bool HasBone(const FString BoneName);
 	bool HasBone(const FString BoneName);
 
 
+	UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
+	FTransform GetBoneTransform(const FString &BoneName);
+
 	UFUNCTION(BlueprintPure, Category = "Components|Spine|Skeleton")
 	UFUNCTION(BlueprintPure, Category = "Components|Spine|Skeleton")
 	void GetSlots(TArray<FString> &Slots);
 	void GetSlots(TArray<FString> &Slots);