Fix formatting.

This commit is contained in:
Mario Zechner 2023-02-17 07:13:51 +01:00
parent d5cd7f67b1
commit 13803ce644
3 changed files with 57 additions and 58 deletions

View File

@ -135,7 +135,6 @@ void USpineSkeletonRendererComponent::UpdateMaterial(UTexture2D *Texture, UMater
material->SetTextureParameterValue(TextureParameterName, Texture); material->SetTextureParameterValue(TextureParameterName, Texture);
CurrentInstance = material; CurrentInstance = material;
} }
} }
void USpineSkeletonRendererComponent::Flush(int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector> &Normals, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, UMaterialInstanceDynamic *Material) { void USpineSkeletonRendererComponent::Flush(int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector> &Normals, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, UMaterialInstanceDynamic *Material) {
@ -167,13 +166,13 @@ void USpineSkeletonRendererComponent::UpdateMesh(USpineSkeletonComponent *compon
normals.Empty(); normals.Empty();
uvs.Empty(); uvs.Empty();
colors.Empty(); colors.Empty();
int idx = 0; int idx = 0;
int meshSection = 0; int meshSection = 0;
UMaterialInstanceDynamic *lastMaterial = nullptr; UMaterialInstanceDynamic *lastMaterial = nullptr;
ClearAllMeshSections(); ClearAllMeshSections();
// Early out if skeleton is invisible // Early out if skeleton is invisible
if (Skeleton->getColor().a == 0) return; if (Skeleton->getColor().a == 0) return;
@ -226,13 +225,13 @@ void USpineSkeletonRendererComponent::UpdateMesh(USpineSkeletonComponent *compon
numIndices = 6; numIndices = 6;
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
MeshAttachment *mesh = (MeshAttachment *) attachment; MeshAttachment *mesh = (MeshAttachment *) attachment;
// Early out if region is invisible // Early out if region is invisible
if (mesh->getColor().a == 0) { if (mesh->getColor().a == 0) {
clipper.clipEnd(*slot); clipper.clipEnd(*slot);
continue; continue;
} }
attachmentColor.set(mesh->getColor()); attachmentColor.set(mesh->getColor());
attachmentVertices->setSize(mesh->getWorldVerticesLength(), 0); attachmentVertices->setSize(mesh->getWorldVerticesLength(), 0);
mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), attachmentVertices->buffer(), 0, 2); mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), attachmentVertices->buffer(), 0, 2);
@ -259,14 +258,14 @@ void USpineSkeletonRendererComponent::UpdateMesh(USpineSkeletonComponent *compon
continue; continue;
} }
} }
// if the user switches the atlas data while not having switched // if the user switches the atlas data while not having switched
// to the correct skeleton data yet, we won't find any regions. // to the correct skeleton data yet, we won't find any regions.
// ignore regions for which we can't find a material // ignore regions for which we can't find a material
UMaterialInstanceDynamic* material = nullptr; UMaterialInstanceDynamic *material = nullptr;
int foundPageIndex = -1; int foundPageIndex = -1;
for (int pageIndex = 0; i < component->Atlas->atlasPages.Num(); pageIndex++) { for (int pageIndex = 0; i < component->Atlas->atlasPages.Num(); pageIndex++) {
AtlasPage* page = component->Atlas->GetAtlas()->getPages()[pageIndex]; AtlasPage *page = component->Atlas->GetAtlas()->getPages()[pageIndex];
if (attachmentAtlasRegion->page == page) { if (attachmentAtlasRegion->page == page) {
foundPageIndex = pageIndex; foundPageIndex = pageIndex;
break; break;
@ -277,74 +276,74 @@ void USpineSkeletonRendererComponent::UpdateMesh(USpineSkeletonComponent *compon
continue; continue;
} }
switch (slot->getData().getBlendMode()) { switch (slot->getData().getBlendMode()) {
case BlendMode_Additive: case BlendMode_Additive:
if (i >= atlasAdditiveBlendMaterials.Num()) { if (i >= atlasAdditiveBlendMaterials.Num()) {
clipper.clipEnd(*slot); clipper.clipEnd(*slot);
continue; continue;
} }
material = atlasAdditiveBlendMaterials[i]; material = atlasAdditiveBlendMaterials[i];
break; break;
case BlendMode_Multiply: case BlendMode_Multiply:
if (i >= atlasMultiplyBlendMaterials.Num()) { if (i >= atlasMultiplyBlendMaterials.Num()) {
clipper.clipEnd(*slot); clipper.clipEnd(*slot);
continue; continue;
} }
material = atlasMultiplyBlendMaterials[i]; material = atlasMultiplyBlendMaterials[i];
break; break;
case BlendMode_Screen: case BlendMode_Screen:
if (i >= atlasScreenBlendMaterials.Num()) { if (i >= atlasScreenBlendMaterials.Num()) {
clipper.clipEnd(*slot); clipper.clipEnd(*slot);
continue; continue;
} }
material = atlasScreenBlendMaterials[i]; material = atlasScreenBlendMaterials[i];
break; break;
case BlendMode_Normal: case BlendMode_Normal:
default: default:
if (i >= atlasNormalBlendMaterials.Num()) { if (i >= atlasNormalBlendMaterials.Num()) {
clipper.clipEnd(*slot); clipper.clipEnd(*slot);
continue; continue;
} }
material = atlasNormalBlendMaterials[i]; material = atlasNormalBlendMaterials[i];
break; break;
} }
if (lastMaterial != material) { if (lastMaterial != material) {
Flush(meshSection, vertices, indices, normals, uvs, colors, lastMaterial); Flush(meshSection, vertices, indices, normals, uvs, colors, lastMaterial);
lastMaterial = material; lastMaterial = material;
idx = 0; idx = 0;
} }
SetMaterial(meshSection, material); SetMaterial(meshSection, material);
uint8 r = static_cast<uint8>(Skeleton->getColor().r * slot->getColor().r * attachmentColor.r * 255); uint8 r = static_cast<uint8>(Skeleton->getColor().r * slot->getColor().r * attachmentColor.r * 255);
uint8 g = static_cast<uint8>(Skeleton->getColor().g * slot->getColor().g * attachmentColor.g * 255); uint8 g = static_cast<uint8>(Skeleton->getColor().g * slot->getColor().g * attachmentColor.g * 255);
uint8 b = static_cast<uint8>(Skeleton->getColor().b * slot->getColor().b * attachmentColor.b * 255); uint8 b = static_cast<uint8>(Skeleton->getColor().b * slot->getColor().b * attachmentColor.b * 255);
uint8 a = static_cast<uint8>(Skeleton->getColor().a * slot->getColor().a * attachmentColor.a * 255); uint8 a = static_cast<uint8>(Skeleton->getColor().a * slot->getColor().a * attachmentColor.a * 255);
float* verticesPtr = attachmentVertices->buffer(); float *verticesPtr = attachmentVertices->buffer();
for (int j = 0; j < numVertices << 1; j += 2) { for (int j = 0; j < numVertices << 1; j += 2) {
colors.Add(FColor(r, g, b, a)); colors.Add(FColor(r, g, b, a));
vertices.Add(FVector(verticesPtr[j], depthOffset, verticesPtr[j + 1])); vertices.Add(FVector(verticesPtr[j], depthOffset, verticesPtr[j + 1]));
uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1])); uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1]));
} }
for (int j = 0; j < numIndices; j++) { for (int j = 0; j < numIndices; j++) {
indices.Add(idx + attachmentIndices[j]); indices.Add(idx + attachmentIndices[j]);
} }
int numTriangles = indices.Num() / 3; int numTriangles = indices.Num() / 3;
for (int j = 0; j < numTriangles; j++) { for (int j = 0; j < numTriangles; j++) {
const int triangleIndex = j * 3; const int triangleIndex = j * 3;
if (FVector::CrossProduct( if (FVector::CrossProduct(
vertices[indices[triangleIndex + 2]] - vertices[indices[triangleIndex]], vertices[indices[triangleIndex + 2]] - vertices[indices[triangleIndex]],
vertices[indices[triangleIndex + 1]] - vertices[indices[triangleIndex]]) vertices[indices[triangleIndex + 1]] - vertices[indices[triangleIndex]])
.Y < 0.f) { .Y < 0.f) {
const int32 targetVertex = indices[triangleIndex]; const int32 targetVertex = indices[triangleIndex];
indices[triangleIndex] = indices[triangleIndex + 2]; indices[triangleIndex] = indices[triangleIndex + 2];
indices[triangleIndex + 2] = targetVertex; indices[triangleIndex + 2] = targetVertex;
} }
} }
FVector normal = FVector(0, 1, 0); FVector normal = FVector(0, 1, 0);
for (int j = 0; j < numVertices; j++) { for (int j = 0; j < numVertices; j++) {
normals.Add(normal); normals.Add(normal);

View File

@ -331,12 +331,12 @@ bool USpineWidget::HasBone(const FString BoneName) {
return false; return false;
} }
FTransform USpineWidget::GetBoneTransform(const FString& BoneName) { FTransform USpineWidget::GetBoneTransform(const FString &BoneName) {
CheckState(); CheckState();
if (skeleton) { if (skeleton) {
Bone *bone = skeleton->findBone(TCHAR_TO_UTF8(*BoneName)); Bone *bone = skeleton->findBone(TCHAR_TO_UTF8(*BoneName));
if (!bone) return FTransform(); if (!bone) return FTransform();
FMatrix localTransform; FMatrix localTransform;
localTransform.SetIdentity(); localTransform.SetIdentity();
localTransform.SetAxis(2, FVector(bone->getA(), 0, bone->getC())); localTransform.SetAxis(2, FVector(bone->getA(), 0, bone->getC()));

View File

@ -99,15 +99,15 @@ protected:
spine::Vector<float> worldVertices; spine::Vector<float> worldVertices;
spine::SkeletonClipping clipper; spine::SkeletonClipping clipper;
UPROPERTY(); UPROPERTY();
TArray<FVector> vertices; TArray<FVector> vertices;
UPROPERTY(); UPROPERTY();
TArray<int32> indices; TArray<int32> indices;
UPROPERTY(); UPROPERTY();
TArray<FVector> normals; TArray<FVector> normals;
UPROPERTY(); UPROPERTY();
TArray<FVector2D> uvs; TArray<FVector2D> uvs;
UPROPERTY(); UPROPERTY();
TArray<FColor> colors; TArray<FColor> colors;
}; };