diff --git a/spine-ue4/Content/Test/raptor-widget.uasset b/spine-ue4/Content/Test/raptor-widget.uasset index bc990b2e0..ff4214a3f 100644 Binary files a/spine-ue4/Content/Test/raptor-widget.uasset and b/spine-ue4/Content/Test/raptor-widget.uasset differ diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp index 3ddd69342..5ab6b4923 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp @@ -51,6 +51,13 @@ void SSpineWidget::Construct(const FArguments& args) { void SSpineWidget::SetData(USpineWidget* Widget) { this->widget = Widget; + if (widget && widget->skeleton && widget->Atlas) { + Skeleton *skeleton = widget->skeleton; + skeleton->setToSetupPose(); + skeleton->updateWorldTransform(); + Vector scratchBuffer; + skeleton->getBounds(this->boundsMin.X, this->boundsMin.Y, this->boundsSize.X, this->boundsSize.Y, scratchBuffer); + } } static void setVertex(FSlateVertex* vertex, float x, float y, float u, float v, const FColor& color, const FVector2D& offset) { @@ -163,6 +170,12 @@ int32 SSpineWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo void SSpineWidget::Flush(int32 LayerId, FSlateWindowElementList& OutDrawElements, const FGeometry& AllottedGeometry, int &Idx, TArray &Vertices, TArray &Indices, TArray &Uvs, TArray &Colors, TArray& Colors2, UMaterialInstanceDynamic* Material) { if (Vertices.Num() == 0) return; SSpineWidget* self = (SSpineWidget*)this; + + const FVector2D widgetSize = AllottedGeometry.GetDrawSize(); + const float setupScale = (widgetSize / FVector2D(boundsSize.X, boundsSize.Y)).GetMin(); + for (int i = 0; i < Vertices.Num(); i++) { + Vertices[i] = (Vertices[i] - FVector(boundsMin.X, -(boundsMin.Y + boundsSize.Y), 0)) * setupScale * widget->Scale; + } self->renderData.IndexData.SetNumUninitialized(Indices.Num()); uint32* indexData = (uint32*)renderData.IndexData.GetData(); @@ -293,18 +306,6 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle } if (lastMaterial != material) { - FBox VerticeBounds = FBox(); - for (int i = 0; i < vertices.Num(); i++) { - VerticeBounds += vertices[i]; - } - const FVector2D DrawSize = AllottedGeometry.GetDrawSize(); - const FVector BoundMin = VerticeBounds.Min; - const FVector BoundSize = VerticeBounds.GetSize(); - const float Scale = (DrawSize / FVector2D(BoundSize.X, BoundSize.Y)).GetMin(); - - for (int i = 0; i < vertices.Num(); i++) { - vertices[i] = (vertices[i] - BoundMin) * Scale; - } Flush(LayerId, OutDrawElements, AllottedGeometry, meshSection, vertices, indices, uvs, colors, darkColors, lastMaterial); lastMaterial = material; idx = 0; @@ -335,22 +336,7 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle clipper.clipEnd(*slot); } - - FBox VerticeBounds = FBox(); - for (int i = 0; i < vertices.Num(); i++) - { - VerticeBounds += vertices[i]; - } - const FVector2D DrawSize = AllottedGeometry.GetDrawSize(); - const FVector BoundMin = VerticeBounds.Min; - const FVector BoundSize = VerticeBounds.GetSize(); - const float Scale = (DrawSize / FVector2D(BoundSize.X, BoundSize.Y)).GetMin(); - - for (int i = 0; i < vertices.Num(); i++) - { - vertices[i] = (vertices[i] - BoundMin)*Scale; - } - + Flush(LayerId, OutDrawElements, AllottedGeometry, meshSection, vertices, indices, uvs, colors, darkColors, lastMaterial); clipper.clipEnd(); } \ No newline at end of file diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SSpineWidget.h b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SSpineWidget.h index 5c04c9be1..13c09e7ab 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SSpineWidget.h +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SSpineWidget.h @@ -55,7 +55,8 @@ protected: void Flush(int32 LayerId, FSlateWindowElementList& OutDrawElements, const FGeometry& AllottedGeometry, int &Idx, TArray &Vertices, TArray &Indices, TArray &Uvs, TArray &Colors, TArray &Colors2, UMaterialInstanceDynamic* Material); - USpineWidget* widget; - + USpineWidget* widget; FRenderData renderData; + FVector boundsMin; + FVector boundsSize; }; diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineWidget.h b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineWidget.h index 96f39c8df..12b4c6c85 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineWidget.h +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineWidget.h @@ -52,6 +52,8 @@ public: #if WITH_EDITOR virtual const FText GetPaletteCategory() override; #endif + UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite) + float Scale = 1; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Spine) USpineAtlasAsset* Atlas;