mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
[ue4] Tried to fix memory corruption, still not working. Added default material support, needs instancing. Added mesh attachment support
This commit is contained in:
parent
96af30c8b9
commit
aff9558f8d
Binary file not shown.
BIN
spine-ue4/Content/Raptor/Textures/raptor.uasset
Normal file
BIN
spine-ue4/Content/Raptor/Textures/raptor.uasset
Normal file
Binary file not shown.
279
spine-ue4/Content/Raptor/raptor.atlas
Normal file
279
spine-ue4/Content/Raptor/raptor.atlas
Normal file
@ -0,0 +1,279 @@
|
||||
|
||||
raptor.png
|
||||
size: 1024,1024
|
||||
format: RGBA8888
|
||||
filter: Linear,Linear
|
||||
repeat: none
|
||||
back_arm
|
||||
rotate: true
|
||||
xy: 140, 191
|
||||
size: 46, 29
|
||||
orig: 46, 29
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
back_bracer
|
||||
rotate: true
|
||||
xy: 167, 317
|
||||
size: 39, 28
|
||||
orig: 39, 28
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
back_hand
|
||||
rotate: false
|
||||
xy: 167, 358
|
||||
size: 36, 34
|
||||
orig: 36, 34
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
back_knee
|
||||
rotate: false
|
||||
xy: 299, 478
|
||||
size: 49, 67
|
||||
orig: 49, 67
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
back_thigh
|
||||
rotate: true
|
||||
xy: 167, 437
|
||||
size: 39, 24
|
||||
orig: 39, 24
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
eyes_closed
|
||||
rotate: true
|
||||
xy: 2, 2
|
||||
size: 47, 45
|
||||
orig: 47, 45
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
eyes_open
|
||||
rotate: true
|
||||
xy: 49, 2
|
||||
size: 47, 45
|
||||
orig: 47, 45
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
eyes_surprised
|
||||
rotate: true
|
||||
xy: 96, 2
|
||||
size: 47, 45
|
||||
orig: 47, 45
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
front_arm
|
||||
rotate: false
|
||||
xy: 419, 544
|
||||
size: 48, 30
|
||||
orig: 48, 30
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
front_bracer
|
||||
rotate: false
|
||||
xy: 880, 695
|
||||
size: 41, 29
|
||||
orig: 41, 29
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
front_hand
|
||||
rotate: true
|
||||
xy: 167, 394
|
||||
size: 41, 38
|
||||
orig: 41, 38
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
front_open_hand
|
||||
rotate: false
|
||||
xy: 880, 726
|
||||
size: 43, 44
|
||||
orig: 43, 44
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
front_thigh
|
||||
rotate: false
|
||||
xy: 360, 545
|
||||
size: 57, 29
|
||||
orig: 57, 29
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
gun
|
||||
rotate: false
|
||||
xy: 785, 774
|
||||
size: 107, 103
|
||||
orig: 107, 103
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
gun_nohand
|
||||
rotate: false
|
||||
xy: 614, 703
|
||||
size: 105, 102
|
||||
orig: 105, 102
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
head
|
||||
rotate: false
|
||||
xy: 2, 137
|
||||
size: 136, 149
|
||||
orig: 136, 149
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
lower_leg
|
||||
rotate: true
|
||||
xy: 780, 699
|
||||
size: 73, 98
|
||||
orig: 73, 98
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
mouth_grind
|
||||
rotate: false
|
||||
xy: 469, 544
|
||||
size: 47, 30
|
||||
orig: 47, 30
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
mouth_oooo
|
||||
rotate: true
|
||||
xy: 894, 772
|
||||
size: 105, 30
|
||||
orig: 105, 30
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
mouth_smile
|
||||
rotate: true
|
||||
xy: 140, 239
|
||||
size: 47, 30
|
||||
orig: 47, 30
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
neck
|
||||
rotate: true
|
||||
xy: 538, 577
|
||||
size: 18, 21
|
||||
orig: 18, 21
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_arm_back
|
||||
rotate: false
|
||||
xy: 940, 936
|
||||
size: 82, 86
|
||||
orig: 82, 86
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_body
|
||||
rotate: false
|
||||
xy: 2, 737
|
||||
size: 610, 285
|
||||
orig: 610, 285
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_front_arm
|
||||
rotate: true
|
||||
xy: 195, 464
|
||||
size: 81, 102
|
||||
orig: 81, 102
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_front_leg
|
||||
rotate: false
|
||||
xy: 2, 478
|
||||
size: 191, 257
|
||||
orig: 191, 257
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_hindleg_back
|
||||
rotate: false
|
||||
xy: 614, 807
|
||||
size: 169, 215
|
||||
orig: 169, 215
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_horn
|
||||
rotate: false
|
||||
xy: 360, 655
|
||||
size: 182, 80
|
||||
orig: 182, 80
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_horn_back
|
||||
rotate: false
|
||||
xy: 360, 576
|
||||
size: 176, 77
|
||||
orig: 176, 77
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_jaw
|
||||
rotate: false
|
||||
xy: 785, 879
|
||||
size: 153, 143
|
||||
orig: 153, 143
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_saddle_noshadow
|
||||
rotate: false
|
||||
xy: 2, 288
|
||||
size: 163, 188
|
||||
orig: 163, 188
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_saddle_strap_front
|
||||
rotate: false
|
||||
xy: 721, 710
|
||||
size: 57, 95
|
||||
orig: 57, 95
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_saddle_strap_rear
|
||||
rotate: true
|
||||
xy: 940, 880
|
||||
size: 54, 74
|
||||
orig: 54, 74
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_saddle_w_shadow
|
||||
rotate: false
|
||||
xy: 195, 547
|
||||
size: 163, 188
|
||||
orig: 163, 188
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_tongue
|
||||
rotate: true
|
||||
xy: 544, 649
|
||||
size: 86, 64
|
||||
orig: 86, 64
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
stirrup_back
|
||||
rotate: true
|
||||
xy: 140, 145
|
||||
size: 44, 35
|
||||
orig: 44, 35
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
stirrup_front
|
||||
rotate: false
|
||||
xy: 538, 597
|
||||
size: 45, 50
|
||||
orig: 45, 50
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
stirrup_strap
|
||||
rotate: false
|
||||
xy: 350, 497
|
||||
size: 49, 46
|
||||
orig: 49, 46
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
torso
|
||||
rotate: true
|
||||
xy: 610, 647
|
||||
size: 54, 91
|
||||
orig: 54, 91
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
visor
|
||||
rotate: false
|
||||
xy: 2, 51
|
||||
size: 131, 84
|
||||
orig: 131, 84
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
2637
spine-ue4/Content/Raptor/raptor.json
Normal file
2637
spine-ue4/Content/Raptor/raptor.json
Normal file
File diff suppressed because one or more lines are too long
BIN
spine-ue4/Content/Raptor/raptor.png
Normal file
BIN
spine-ue4/Content/Raptor/raptor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 495 KiB |
BIN
spine-ue4/Content/Raptor/raptor.skel
Normal file
BIN
spine-ue4/Content/Raptor/raptor.skel
Normal file
Binary file not shown.
BIN
spine-ue4/Content/Raptor/raptor.uasset
Normal file
BIN
spine-ue4/Content/Raptor/raptor.uasset
Normal file
Binary file not shown.
@ -59,7 +59,7 @@ void USpineSkeletonComponent::DisposeState() {
|
||||
}
|
||||
}
|
||||
|
||||
void USpineSkeletonComponent::BeginDestroy() {
|
||||
void USpineSkeletonComponent::FinishDestroy() {
|
||||
DisposeState();
|
||||
Super::BeginDestroy();
|
||||
Super::FinishDestroy();
|
||||
}
|
||||
@ -10,7 +10,10 @@ USpineSkeletonRendererComponent::USpineSkeletonRendererComponent(const FObjectIn
|
||||
bWantsBeginPlay = true;
|
||||
PrimaryComponentTick.bCanEverTick = true;
|
||||
bTickInEditor = true;
|
||||
bAutoActivate = true;
|
||||
bAutoActivate = true;
|
||||
|
||||
static ConstructorHelpers::FObjectFinder<UMaterialInterface> MaskedMaterialRef(TEXT("/Paper2D/MaskedUnlitSpriteMaterial"));
|
||||
DefaultMaterial = MaskedMaterialRef.Object;
|
||||
}
|
||||
|
||||
// Called when the game starts
|
||||
@ -41,13 +44,15 @@ void USpineSkeletonRendererComponent::UpdateMesh(spSkeleton* skeleton) {
|
||||
TArray<FVector2D> uvs;
|
||||
TArray<FColor> colors;
|
||||
|
||||
int worldVerticesLength = 1000;
|
||||
float* worldVertices = (float*)malloc((2 + 2 + 5) * worldVerticesLength);
|
||||
TArray<float> worldVertices;
|
||||
worldVertices.SetNumUninitialized(2 * 1024);
|
||||
int idx = 0;
|
||||
int meshSection = 0;
|
||||
|
||||
ClearAllMeshSections();
|
||||
|
||||
float depthOffset = 0;
|
||||
|
||||
for (int i = 0; i < skeleton->slotsCount; ++i) {
|
||||
spSlot* slot = skeleton->drawOrder[i];
|
||||
spAttachment* attachment = slot->attachment;
|
||||
@ -55,7 +60,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(spSkeleton* skeleton) {
|
||||
|
||||
if (attachment->type == SP_ATTACHMENT_REGION) {
|
||||
spRegionAttachment* regionAttachment = (spRegionAttachment*)attachment;
|
||||
spRegionAttachment_computeWorldVertices(regionAttachment, slot->bone, worldVertices);
|
||||
spRegionAttachment_computeWorldVertices(regionAttachment, slot->bone, worldVertices.GetData());
|
||||
|
||||
uint8 r = static_cast<uint8>(skeleton->r * slot->r * 255);
|
||||
uint8 g = static_cast<uint8>(skeleton->g * slot->g * 255);
|
||||
@ -63,19 +68,19 @@ void USpineSkeletonRendererComponent::UpdateMesh(spSkeleton* skeleton) {
|
||||
uint8 a = static_cast<uint8>(skeleton->a * slot->a * 255);
|
||||
|
||||
colors.Add(FColor(r, g, b, a));
|
||||
vertices.Add(FVector(worldVertices[0], 0, worldVertices[1]));
|
||||
vertices.Add(FVector(worldVertices[0], depthOffset, worldVertices[1]));
|
||||
uvs.Add(FVector2D(regionAttachment->uvs[0], regionAttachment->uvs[1]));
|
||||
|
||||
colors.Add(FColor(r, g, b, a));
|
||||
vertices.Add(FVector(worldVertices[2], 0, worldVertices[3]));
|
||||
vertices.Add(FVector(worldVertices[2], depthOffset, worldVertices[3]));
|
||||
uvs.Add(FVector2D(regionAttachment->uvs[2], regionAttachment->uvs[3]));
|
||||
|
||||
colors.Add(FColor(r, g, b, a));
|
||||
vertices.Add(FVector(worldVertices[4], 0, worldVertices[5]));
|
||||
vertices.Add(FVector(worldVertices[4], depthOffset, worldVertices[5]));
|
||||
uvs.Add(FVector2D(regionAttachment->uvs[4], regionAttachment->uvs[5]));
|
||||
|
||||
colors.Add(FColor(r, g, b, a));
|
||||
vertices.Add(FVector(worldVertices[6], 0, worldVertices[7]));
|
||||
vertices.Add(FVector(worldVertices[6], depthOffset, worldVertices[7]));
|
||||
uvs.Add(FVector2D(regionAttachment->uvs[6], regionAttachment->uvs[7]));
|
||||
|
||||
indices.Add(idx + 0);
|
||||
@ -84,35 +89,41 @@ void USpineSkeletonRendererComponent::UpdateMesh(spSkeleton* skeleton) {
|
||||
indices.Add(idx + 0);
|
||||
indices.Add(idx + 2);
|
||||
indices.Add(idx + 3);
|
||||
idx += 4;
|
||||
}
|
||||
/*else if (attachment->type == ATTACHMENT_MESH) {
|
||||
MeshAttachment* mesh = (MeshAttachment*)attachment;
|
||||
if (mesh->super.worldVerticesLength > SPINE_MESH_VERTEX_COUNT_MAX) continue;
|
||||
texture = (Texture*)((AtlasRegion*)mesh->rendererObject)->page->rendererObject;
|
||||
MeshAttachment_computeWorldVertices(mesh, slot, worldVertices);
|
||||
|
||||
Uint8 r = static_cast<Uint8>(skeleton->r * slot->r * 255);
|
||||
Uint8 g = static_cast<Uint8>(skeleton->g * slot->g * 255);
|
||||
Uint8 b = static_cast<Uint8>(skeleton->b * slot->b * 255);
|
||||
Uint8 a = static_cast<Uint8>(skeleton->a * slot->a * 255);
|
||||
vertex.color.r = r;
|
||||
vertex.color.g = g;
|
||||
vertex.color.b = b;
|
||||
vertex.color.a = a;
|
||||
|
||||
Vector2u size = texture->getSize();
|
||||
for (int i = 0; i < mesh->trianglesCount; ++i) {
|
||||
int index = mesh->triangles[i] << 1;
|
||||
vertex.position.x = worldVertices[index];
|
||||
vertex.position.y = worldVertices[index + 1];
|
||||
vertex.texCoords.x = mesh->uvs[index] * size.x;
|
||||
vertex.texCoords.y = mesh->uvs[index + 1] * size.y;
|
||||
vertexArray->append(vertex);
|
||||
idx += 4;
|
||||
depthOffset -= this->depthOffset;
|
||||
} else if (attachment->type == SP_ATTACHMENT_MESH) {
|
||||
spMeshAttachment* mesh = (spMeshAttachment*)attachment;
|
||||
if (mesh->super.worldVerticesLength> worldVertices.Num()) {
|
||||
worldVertices.SetNum(mesh->super.worldVerticesLength);
|
||||
}
|
||||
}*/
|
||||
spMeshAttachment_computeWorldVertices(mesh, slot, worldVertices.GetData());
|
||||
|
||||
uint8 r = static_cast<uint8>(skeleton->r * slot->r * 255);
|
||||
uint8 g = static_cast<uint8>(skeleton->g * slot->g * 255);
|
||||
uint8 b = static_cast<uint8>(skeleton->b * slot->b * 255);
|
||||
uint8 a = static_cast<uint8>(skeleton->a * slot->a * 255);
|
||||
|
||||
for (int i = 0; i < mesh->super.worldVerticesLength; i += 2) {
|
||||
colors.Add(FColor(r, g, b, a));
|
||||
vertices.Add(FVector(worldVertices[i], depthOffset, worldVertices[i + 1]));
|
||||
uvs.Add(FVector2D(mesh->uvs[i], mesh->uvs[i + 1]));
|
||||
}
|
||||
|
||||
for (int i = 0; i < mesh->trianglesCount; i++) {
|
||||
indices.Add(idx + mesh->triangles[i]);
|
||||
}
|
||||
idx += mesh->super.worldVerticesLength >> 1;
|
||||
depthOffset -= this->depthOffset;
|
||||
}
|
||||
}
|
||||
|
||||
CreateMeshSection(0, vertices, indices, TArray<FVector>(), uvs, colors, TArray<FProcMeshTangent>(), false);
|
||||
free(worldVertices);
|
||||
CreateMeshSection(0, vertices, indices, TArray<FVector>(), uvs, colors, TArray<FProcMeshTangent>(), false);
|
||||
}
|
||||
|
||||
UMaterialInterface* USpineSkeletonRendererComponent::GetMaterial(int32 MaterialIndex) const {
|
||||
return MaterialIndex == 0 ? GetDefaultMaterial() : nullptr;
|
||||
}
|
||||
|
||||
int32 USpineSkeletonRendererComponent::GetNumMaterials() const {
|
||||
return 1;
|
||||
}
|
||||
@ -28,11 +28,11 @@ public:
|
||||
|
||||
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;
|
||||
|
||||
virtual void BeginDestroy () override;
|
||||
virtual void FinishDestroy () override;
|
||||
|
||||
protected:
|
||||
void DisposeState();
|
||||
|
||||
USpineAtlasAsset* lastAtlas = nullptr;
|
||||
USpineSkeletonDataAsset* lastData = nullptr;
|
||||
USpineSkeletonDataAsset* lastData = nullptr;
|
||||
};
|
||||
|
||||
@ -18,10 +18,24 @@ public:
|
||||
|
||||
virtual void BeginPlay () override;
|
||||
|
||||
virtual void TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
virtual void TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadOnly)
|
||||
UMaterialInterface* DefaultMaterial;
|
||||
|
||||
UMaterialInterface* GetDefaultMaterial() const { return DefaultMaterial; }
|
||||
|
||||
UMaterialInterface* GetAlternateMaterial() const { return nullptr; }
|
||||
|
||||
UMaterialInterface* GetMaterial(int32 MaterialIndex) const;
|
||||
|
||||
int32 GetNumMaterials() const;
|
||||
|
||||
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite)
|
||||
float depthOffset = 0.1f;
|
||||
protected:
|
||||
void UpdateMesh (spSkeleton* skeleton);
|
||||
|
||||
bool updated;
|
||||
UPROPERTY()
|
||||
TArray<UMaterialInstanceDynamic*> atlasMaterials;
|
||||
};
|
||||
|
||||
@ -8,8 +8,8 @@ namespace UnrealBuildTool.Rules
|
||||
{
|
||||
PublicIncludePaths.AddRange(new string[] { "SpinePlugin/Public", "SpinePlugin/Public/spine-c/include" });
|
||||
PrivateIncludePaths.AddRange(new string[] { "SpinePlugin/Private", "SpinePlugin/Public/spine-c/include" });
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "ProceduralMeshComponent" });
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { "RHI", "RenderCore", "ShaderCore" });
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "ProceduralMeshComponent", "Paper2D" });
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { "RHI", "RenderCore", "ShaderCore", "Paper2D" });
|
||||
OptimizeCode = CodeOptimization.Never;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user