diff --git a/spine-ue4/Plugins/SpinePlugin/Content/UI_SpineUnlitAdditiveMaterial.uasset b/spine-ue4/Plugins/SpinePlugin/Content/UI_SpineUnlitAdditiveMaterial.uasset new file mode 100644 index 000000000..bdd7406f6 Binary files /dev/null and b/spine-ue4/Plugins/SpinePlugin/Content/UI_SpineUnlitAdditiveMaterial.uasset differ diff --git a/spine-ue4/Plugins/SpinePlugin/Content/UI_SpineUnlitMultiplyMaterial.uasset b/spine-ue4/Plugins/SpinePlugin/Content/UI_SpineUnlitMultiplyMaterial.uasset new file mode 100644 index 000000000..4cb8de52a Binary files /dev/null and b/spine-ue4/Plugins/SpinePlugin/Content/UI_SpineUnlitMultiplyMaterial.uasset differ diff --git a/spine-ue4/Plugins/SpinePlugin/Content/UI_SpineUnlitNormalMaterial.uasset b/spine-ue4/Plugins/SpinePlugin/Content/UI_SpineUnlitNormalMaterial.uasset new file mode 100644 index 000000000..c42aa4494 Binary files /dev/null and b/spine-ue4/Plugins/SpinePlugin/Content/UI_SpineUnlitNormalMaterial.uasset differ diff --git a/spine-ue4/Plugins/SpinePlugin/Content/UI_SpineUnlitScreenMaterial.uasset b/spine-ue4/Plugins/SpinePlugin/Content/UI_SpineUnlitScreenMaterial.uasset new file mode 100644 index 000000000..9547cf6ec Binary files /dev/null and b/spine-ue4/Plugins/SpinePlugin/Content/UI_SpineUnlitScreenMaterial.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 2082a078d..a289c29a0 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp @@ -72,6 +72,10 @@ int32 SSpineWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo SSpineWidget* self = (SSpineWidget*)this; + //Begin Change + UMaterialInstanceDynamic* MatNow = nullptr; + // End Change + if (widget && widget->skeleton && widget->Atlas) { widget->skeleton->getColor().set(widget->Color.R, widget->Color.G, widget->Color.B, widget->Color.A); @@ -153,10 +157,10 @@ int32 SSpineWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo widget->pageToScreenBlendMaterial.Add(currPage, widget->atlasScreenBlendMaterials[i]); } } - // self->UpdateMesh(LayerId, OutDrawElements, AllottedGeometry, widget->skeleton); + self->UpdateMesh(LayerId, OutDrawElements, AllottedGeometry, widget->skeleton); } - //return LayerId; - + + /* self->renderData.IndexData.SetNumUninitialized(6); uint32* indexData = (uint32*)renderData.IndexData.GetData(); indexData[0] = 0; @@ -178,12 +182,16 @@ int32 SSpineWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo setVertex(&vertexData[1], width, 0, 1, 0, white, offset); setVertex(&vertexData[2], width, height, 1, 1, white, offset); setVertex(&vertexData[3], 0, height, 0, 1, white, offset); - - if (brush && renderData.VertexData.Num() > 0 && renderData.IndexData.Num() > 0) { + */ + if (renderData.VertexData.Num() > 0 && renderData.IndexData.Num() > 0) { + /* FSlateShaderResourceProxy* shaderResource = FSlateDataPayload::ResourceManager->GetShaderResource(widget->Brush); FSlateResourceHandle resourceHandle = FSlateApplication::Get().GetRenderer()->GetResourceHandle(widget->Brush); - if (shaderResource) - FSlateDrawElement::MakeCustomVerts(OutDrawElements, LayerId, resourceHandle, renderData.VertexData, + */ + //renderData.Brush = MakeShareable(new FSlateMaterialBrush(*MaterialFromMesh, FVector2D(64,64))); + + if (renderData.RenderingResourceHandle.IsValid()) + FSlateDrawElement::MakeCustomVerts(OutDrawElements, LayerId, renderData.RenderingResourceHandle, renderData.VertexData, renderData.IndexData, nullptr, 0, 0); } @@ -209,6 +217,26 @@ void SSpineWidget::Flush(int32 LayerId, FSlateWindowElementList& OutDrawElements for (size_t i = 0; i < (size_t)Vertices.Num(); i++) { setVertex(&vertexData[i], Vertices[i].X, Vertices[i].Y, Uvs[i].X, Uvs[i].Y, Colors[i], offset); } + /* + + */ + brush = &widget->Brush; + //Begin change + if (Material) + { + renderData.Brush = MakeShareable(new FSlateMaterialBrush(*Material, FVector2D(64, 64))); + renderData.RenderingResourceHandle = FSlateApplication::Get().GetRenderer()->GetResourceHandle(*renderData.Brush); + //renderData.Brush = MakeShareable(&widget->Brush); + + //renderData.Brush = MakeShareable(new FSlateMaterialBrush(*Material, widget->Brush)); + //renderData.RenderingResourceHandle = FSlateApplication::Get().GetRenderer()->GetResourceHandle(*brush); + } + // End change + + if (renderData.RenderingResourceHandle.IsValid()) { + FSlateDrawElement::MakeCustomVerts(OutDrawElements, LayerId, renderData.RenderingResourceHandle, renderData.VertexData, renderData.IndexData, nullptr, 0, 0); + } + /*FSlateBrush brush; brush.SetResourceObject(Material); @@ -311,7 +339,7 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle if (!widget->pageToNormalBlendMaterial.Contains(attachmentAtlasRegion->page)) continue; material = widget->pageToNormalBlendMaterial[attachmentAtlasRegion->page]; } - + if (clipper.isClipping()) { clipper.clipTriangles(attachmentVertices.buffer(), attachmentIndices, numIndices, attachmentUvs, 2); attachmentVertices = clipper.getClippedVertices(); @@ -323,7 +351,7 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle } if (lastMaterial != material) { - Flush(LayerId, OutDrawElements, AllottedGeometry, meshSection, vertices, indices, uvs, colors, darkColors, lastMaterial); + lastMaterial = material; idx = 0; } @@ -340,7 +368,8 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle for (int j = 0; j < numVertices << 1; j += 2) { colors.Add(FColor(r, g, b, a)); darkColors.Add(FVector(dr, dg, db)); - vertices.Add(FVector(attachmentVertices[j], depthOffset, attachmentVertices[j + 1])); + //vertices.Add(FVector(attachmentVertices[j], depthOffset, attachmentVertices[j + 1])); + vertices.Add(FVector(attachmentVertices[j], -attachmentVertices[j + 1], depthOffset)); uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1])); } @@ -352,6 +381,23 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle depthOffset += widget->DepthOffset; clipper.clipEnd(*slot); + + //Flush(LayerId, OutDrawElements, AllottedGeometry, meshSection, vertices, indices, uvs, colors, darkColors, lastMaterial); + } + + 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); diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineWidget.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineWidget.cpp index b3bb983b7..7e17b255d 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineWidget.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineWidget.cpp @@ -36,16 +36,16 @@ #define LOCTEXT_NAMESPACE "Spine" USpineWidget::USpineWidget(const FObjectInitializer& ObjectInitializer): Super(ObjectInitializer) { - static ConstructorHelpers::FObjectFinder NormalMaterialRef(TEXT("/SpinePlugin/SpineUnlitNormalMaterial")); + static ConstructorHelpers::FObjectFinder NormalMaterialRef(TEXT("/SpinePlugin/UI_SpineUnlitNormalMaterial")); NormalBlendMaterial = NormalMaterialRef.Object; - static ConstructorHelpers::FObjectFinder AdditiveMaterialRef(TEXT("/SpinePlugin/SpineUnlitAdditiveMaterial")); + static ConstructorHelpers::FObjectFinder AdditiveMaterialRef(TEXT("/SpinePlugin/UI_SpineUnlitAdditiveMaterial")); AdditiveBlendMaterial = AdditiveMaterialRef.Object; - static ConstructorHelpers::FObjectFinder MultiplyMaterialRef(TEXT("/SpinePlugin/SpineUnlitMultiplyMaterial")); + static ConstructorHelpers::FObjectFinder MultiplyMaterialRef(TEXT("/SpinePlugin/UI_SpineUnlitMultiplyMaterial")); MultiplyBlendMaterial = MultiplyMaterialRef.Object; - static ConstructorHelpers::FObjectFinder ScreenMaterialRef(TEXT("/SpinePlugin/SpineUnlitScreenMaterial")); + static ConstructorHelpers::FObjectFinder ScreenMaterialRef(TEXT("/SpinePlugin/UI_SpineUnlitScreenMaterial")); ScreenBlendMaterial = ScreenMaterialRef.Object; TextureParameterName = FName(TEXT("SpriteTexture")); diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SSpineWidget.h b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SSpineWidget.h index 45eca6506..5c04c9be1 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SSpineWidget.h +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SSpineWidget.h @@ -47,7 +47,7 @@ public: void Construct(const FArguments& Args); void SetData(USpineWidget* Widget); - + FSlateBrush* brush; protected: virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override; @@ -56,6 +56,6 @@ 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; - FSlateBrush* brush; + FRenderData renderData; };