This commit is contained in:
badlogic 2019-04-16 13:53:02 +02:00
commit 9531cb0b7d
19 changed files with 120 additions and 61 deletions

View File

@ -270,7 +270,7 @@ namespace Spine {
return clipped;
}
static void MakeClockwise (ExposedList<float> polygon) {
public static void MakeClockwise (ExposedList<float> polygon) {
float[] vertices = polygon.Items;
int verticeslength = polygon.Count;

View File

@ -31,7 +31,7 @@
using System;
namespace Spine {
internal class Triangulator {
public class Triangulator {
private readonly ExposedList<ExposedList<float>> convexPolygons = new ExposedList<ExposedList<float>>();
private readonly ExposedList<ExposedList<int>> convexPolygonsIndices = new ExposedList<ExposedList<int>>();

View File

@ -175,6 +175,8 @@ public class SkeletonBinary {
if (skeletonData.hash.isEmpty()) skeletonData.hash = null;
skeletonData.version = input.readString();
if (skeletonData.version.isEmpty()) skeletonData.version = null;
skeletonData.x = input.readFloat();
skeletonData.y = input.readFloat();
skeletonData.width = input.readFloat();
skeletonData.height = input.readFloat();

View File

@ -47,7 +47,7 @@ public class SkeletonData {
final Array<IkConstraintData> ikConstraints = new Array();
final Array<TransformConstraintData> transformConstraints = new Array();
final Array<PathConstraintData> pathConstraints = new Array();
float width, height;
float x, y, width, height;
String version, hash;
// Nonessential.
@ -234,6 +234,24 @@ public class SkeletonData {
this.name = name;
}
/** The X coordinate of the skeleton's axis aligned bounding box in the setup pose. */
public float getX () {
return x;
}
public void setX (float x) {
this.x = x;
}
/** The Y coordinate of the skeleton's axis aligned bounding box in the setup pose. */
public float getY () {
return y;
}
public void setY (float y) {
this.y = y;
}
/** The width of the skeleton's axis aligned bounding box in the setup pose. */
public float getWidth () {
return width;

View File

@ -122,6 +122,8 @@ public class SkeletonJson {
if (skeletonMap != null) {
skeletonData.hash = skeletonMap.getString("hash", null);
skeletonData.version = skeletonMap.getString("spine", null);
skeletonData.x = skeletonMap.getFloat("x", 0);
skeletonData.y = skeletonMap.getFloat("y", 0);
skeletonData.width = skeletonMap.getFloat("width", 0);
skeletonData.height = skeletonMap.getFloat("height", 0);
skeletonData.fps = skeletonMap.getFloat("fps", 30);

View File

@ -65,9 +65,9 @@ namespace Spine {
// String name = "spineboy-ess";
// String name = "goblins-pro";
// String name = "raptor-pro";
String name = "raptor-pro";
// String name = "tank-pro";
String name = "coin-pro";
// String name = "coin-pro";
String atlasName = name.Replace("-pro", "").Replace("-ess", "");
bool binaryData = false;
@ -109,17 +109,17 @@ namespace Spine {
state.Complete += Complete;
state.Event += Event;
state.SetAnimation(0, "test", false);
state.SetAnimation(0, "run", false);
TrackEntry entry = state.AddAnimation(0, "jump", false, 0);
entry.End += End; // Event handling for queued animations.
state.AddAnimation(0, "run", true, 0);
}
else if (name == "raptor-pro") {
state.SetAnimation(0, "walk", true);
state.AddAnimation(1, "gungrab", false, 2);
state.AddAnimation(1, "gun-grab", false, 2);
}
else if (name == "coin-pro") {
state.SetAnimation(0, "rotate", true);
state.SetAnimation(0, "animation", true);
}
else if (name == "tank-pro") {
state.SetAnimation(0, "drive", true);
@ -127,9 +127,10 @@ namespace Spine {
else {
state.SetAnimation(0, "walk", true);
}
skeleton.X = 400 + (name == "tank-pro" ? 300 : 0);
skeleton.Y = GraphicsDevice.Viewport.Height;
skeleton.ScaleY = -1;
skeleton.UpdateWorldTransform();
headSlot = skeleton.FindSlot("head");

View File

@ -42,6 +42,15 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\spine-xna\src\ShapeRenderer.cs">
<Link>spine-xna\ShapeRenderer.cs</Link>
</Compile>
<Compile Include="..\..\spine-xna\src\SkeletonDebugRenderer.cs">
<Link>spine-xna\SkeletonDebugRenderer.cs</Link>
</Compile>
<Compile Include="..\..\spine-xna\src\VertexEffect.cs">
<Link>spine-xna\VertexEffect.cs</Link>
</Compile>
<Compile Include="..\..\spine-xna\src\MeshBatcher.cs">
<Link>spine-xna\MeshBatcher.cs</Link>
</Compile>

View File

@ -7,9 +7,15 @@ DefaultGraphicsPerformance=Maximum
AppliedDefaultGraphicsPerformance=Maximum
[/Script/EngineSettings.GameMapsSettings]
GameDefaultMap=/Game/Test/Test.Test
GameDefaultMap=/Game/Test/NewWorld.NewWorld
GlobalDefaultGameMode=/Game/Test/Blueprints/TouchClick.TouchClick_C
[/Script/IOSRuntimeSettings.IOSRuntimeSettings]
bSupportsPortraitOrientation=False
bSupportsUpsideDownOrientation=False
bSupportsLandscapeLeftOrientation=True
PreferredLandscapeOrientation=LandscapeLeft
[/Script/Engine.PhysicsSettings]
DefaultGravityZ=-980.000000
DefaultTerminalVelocity=4000.000000
@ -17,12 +23,12 @@ DefaultFluidFriction=0.300000
SimulateScratchMemorySize=262144
RagdollAggregateThreshold=4
TriangleMeshTriangleMinAreaThreshold=5.000000
bEnableAsyncScene=False
bEnableShapeSharing=False
bEnablePCM=True
bEnableStabilization=False
bWarnMissingLocks=True
bEnable2DPhysics=False
PhysicErrorCorrection=(PingExtrapolation=0.100000,PingLimit=100.000000,ErrorPerLinearDifference=1.000000,ErrorPerAngularDifference=1.000000,MaxRestoredStateError=1.000000,MaxLinearHardSnapDistance=400.000000,PositionLerp=0.000000,AngleLerp=0.400000,LinearVelocityCoefficient=100.000000,AngularVelocityCoefficient=10.000000,ErrorAccumulationSeconds=0.500000,ErrorAccumulationDistanceSq=15.000000,ErrorAccumulationSimilarity=100.000000)
LockedAxis=Invalid
DefaultDegreesOfFreedom=Full3D
BounceThresholdVelocity=200.000000
@ -39,6 +45,8 @@ bDefaultHasComplexCollision=True
bSuppressFaceRemapTable=False
bSupportUVFromHitResults=False
bDisableActiveActors=False
bDisableKinematicStaticPairs=False
bDisableKinematicKinematicPairs=False
bDisableCCD=False
bEnableEnhancedDeterminism=False
MaxPhysicsDeltaTime=0.033333
@ -47,16 +55,7 @@ bSubsteppingAsync=False
MaxSubstepDeltaTime=0.016667
MaxSubsteps=6
SyncSceneSmoothingFactor=0.000000
AsyncSceneSmoothingFactor=0.990000
InitialAverageFrameRate=0.016667
PhysXTreeRebuildRate=10
[/Script/IOSRuntimeSettings.IOSRuntimeSettings]
bSupportsPortraitOrientation=False
bSupportsUpsideDownOrientation=False
bSupportsLandscapeLeftOrientation=True
PreferredLandscapeOrientation=LandscapeLeft
DefaultBroadphaseSettings=(bUseMBPOnClient=False,bUseMBPOnServer=False,MBPBounds=(Min=(X=0.000000,Y=0.000000,Z=0.000000),Max=(X=0.000000,Y=0.000000,Z=0.000000),IsValid=0),MBPNumSubdivs=2)

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -37,7 +37,7 @@ class FSpineEditorPlugin: public ISpineEditorPlugin {
virtual void ShutdownModule() override;
};
IMPLEMENT_MODULE(FSpineEditorPlugin, ISpineEditorPlugin)
IMPLEMENT_MODULE(FSpineEditorPlugin, SpineEditorPlugin)
void FSpineEditorPlugin::StartupModule () {
}

View File

@ -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<float> 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<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, TArray<FVector>& 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();
}

View File

@ -38,7 +38,41 @@
using namespace spine;
void callback(AnimationState* state, spine::EventType type, TrackEntry* entry, Event* event);
void callbackWidget(AnimationState* state, spine::EventType type, TrackEntry* entry, Event* event) {
USpineWidget* component = (USpineWidget*)state->getRendererObject();
if (entry->getRendererObject()) {
UTrackEntry* uEntry = (UTrackEntry*)entry->getRendererObject();
if (type == EventType_Start) {
component->AnimationStart.Broadcast(uEntry);
uEntry->AnimationStart.Broadcast(uEntry);
}
else if (type == EventType_Interrupt) {
component->AnimationInterrupt.Broadcast(uEntry);
uEntry->AnimationInterrupt.Broadcast(uEntry);
}
else if (type == EventType_Event) {
FSpineEvent evt;
evt.SetEvent(event);
component->AnimationEvent.Broadcast(uEntry, evt);
uEntry->AnimationEvent.Broadcast(uEntry, evt);
}
else if (type == EventType_Complete) {
component->AnimationComplete.Broadcast(uEntry);
uEntry->AnimationComplete.Broadcast(uEntry);
}
else if (type == EventType_End) {
component->AnimationEnd.Broadcast(uEntry);
uEntry->AnimationEnd.Broadcast(uEntry);
}
else if (type == EventType_Dispose) {
component->AnimationDispose.Broadcast(uEntry);
uEntry->AnimationDispose.Broadcast(uEntry);
uEntry->SetTrackEntry(nullptr);
component->GCTrackEntry(uEntry);
}
}
}
USpineWidget::USpineWidget(const FObjectInitializer& ObjectInitializer): Super(ObjectInitializer) {
static ConstructorHelpers::FObjectFinder<UMaterialInterface> NormalMaterialRef(TEXT("/SpinePlugin/UI_SpineUnlitNormalMaterial"));
@ -130,7 +164,7 @@ void USpineWidget::CheckState() {
AnimationStateData* stateData = SkeletonData->GetAnimationStateData(Atlas->GetAtlas());
state = new (__FILE__, __LINE__) AnimationState(stateData);
state->setRendererObject((void*)this);
state->setListener(callback);
state->setListener(callbackWidget);
trackEntries.Empty();
}
}
@ -355,7 +389,8 @@ UTrackEntry* USpineWidget::SetAnimation(int trackIndex, FString animationName, b
trackEntries.Add(uEntry);
return uEntry;
}
else return NewObject<UTrackEntry>();
else
return NewObject<UTrackEntry>();
}
@ -370,7 +405,8 @@ UTrackEntry* USpineWidget::AddAnimation(int trackIndex, FString animationName, b
trackEntries.Add(uEntry);
return uEntry;
}
else return NewObject<UTrackEntry>();
else
return NewObject<UTrackEntry>();
}
UTrackEntry* USpineWidget::SetEmptyAnimation(int trackIndex, float mixDuration) {
@ -382,7 +418,8 @@ UTrackEntry* USpineWidget::SetEmptyAnimation(int trackIndex, float mixDuration)
trackEntries.Add(uEntry);
return uEntry;
}
else return NewObject<UTrackEntry>();
else
return NewObject<UTrackEntry>();
}
UTrackEntry* USpineWidget::AddEmptyAnimation(int trackIndex, float mixDuration, float delay) {
@ -394,7 +431,8 @@ UTrackEntry* USpineWidget::AddEmptyAnimation(int trackIndex, float mixDuration,
trackEntries.Add(uEntry);
return uEntry;
}
else return NewObject<UTrackEntry>();
else
return NewObject<UTrackEntry>();
}
UTrackEntry* USpineWidget::GetCurrent(int trackIndex) {
@ -411,7 +449,8 @@ UTrackEntry* USpineWidget::GetCurrent(int trackIndex) {
return uEntry;
}
}
else return NewObject<UTrackEntry>();
else
return NewObject<UTrackEntry>();
}
void USpineWidget::ClearTracks() {

View File

@ -55,7 +55,8 @@ protected:
void Flush(int32 LayerId, FSlateWindowElementList& OutDrawElements, const FGeometry& AllottedGeometry, int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, TArray<FVector> &Colors2, UMaterialInstanceDynamic* Material);
USpineWidget* widget;
USpineWidget* widget;
FRenderData renderData;
FVector boundsMin;
FVector boundsSize;
};

View File

@ -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;

View File

@ -15,7 +15,7 @@ namespace UnrealBuildTool.Rules
PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private"));
PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Public/spine-cpp/include"));
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "RHI", "RenderCore", "ShaderCore", "ProceduralMeshComponent", "UMG", "Slate", "SlateCore" });
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "ProceduralMeshComponent", "UMG", "Slate", "SlateCore" });
PublicDefinitions.Add("SPINE_UE4");
}
}

View File

@ -1,6 +1,6 @@
{
"FileVersion": 3,
"EngineAssociation": "4.21",
"EngineAssociation": "4.22",
"Category": "",
"Description": "",
"Modules": [