[ue4] Fix formatting.

This commit is contained in:
badlogic 2022-07-04 14:00:50 +02:00
parent a85765d4d9
commit de5f8cd469

View File

@ -36,7 +36,7 @@
using namespace spine; using namespace spine;
USpineSkeletonRendererComponent::USpineSkeletonRendererComponent(const FObjectInitializer& ObjectInitializer) USpineSkeletonRendererComponent::USpineSkeletonRendererComponent(const FObjectInitializer &ObjectInitializer)
: UProceduralMeshComponent(ObjectInitializer) { : UProceduralMeshComponent(ObjectInitializer) {
PrimaryComponentTick.bCanEverTick = true; PrimaryComponentTick.bCanEverTick = true;
bTickInEditor = true; bTickInEditor = true;
@ -67,19 +67,19 @@ void USpineSkeletonRendererComponent::BeginPlay() {
Super::BeginPlay(); Super::BeginPlay();
} }
void USpineSkeletonRendererComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { void USpineSkeletonRendererComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) {
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
AActor* owner = GetOwner(); AActor *owner = GetOwner();
if (owner) { if (owner) {
UClass* skeletonClass = USpineSkeletonComponent::StaticClass(); UClass *skeletonClass = USpineSkeletonComponent::StaticClass();
USpineSkeletonComponent* skeleton = Cast<USpineSkeletonComponent>(owner->GetComponentByClass(skeletonClass)); USpineSkeletonComponent *skeleton = Cast<USpineSkeletonComponent>(owner->GetComponentByClass(skeletonClass));
UpdateRenderer(skeleton); UpdateRenderer(skeleton);
} }
} }
void USpineSkeletonRendererComponent::UpdateRenderer(USpineSkeletonComponent* skeleton) { void USpineSkeletonRendererComponent::UpdateRenderer(USpineSkeletonComponent *skeleton) {
if (skeleton && !skeleton->IsBeingDestroyed() && skeleton->GetSkeleton() && skeleton->Atlas) { if (skeleton && !skeleton->IsBeingDestroyed() && skeleton->GetSkeleton() && skeleton->Atlas) {
skeleton->GetSkeleton()->getColor().set(Color.R, Color.G, Color.B, Color.A); skeleton->GetSkeleton()->getColor().set(Color.R, Color.G, Color.B, Color.A);
@ -94,9 +94,9 @@ void USpineSkeletonRendererComponent::UpdateRenderer(USpineSkeletonComponent* sk
pageToScreenBlendMaterial.Empty(); pageToScreenBlendMaterial.Empty();
for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) { for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) {
AtlasPage* currPage = skeleton->Atlas->GetAtlas()->getPages()[i]; AtlasPage *currPage = skeleton->Atlas->GetAtlas()->getPages()[i];
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NormalBlendMaterial, this); UMaterialInstanceDynamic *material = UMaterialInstanceDynamic::Create(NormalBlendMaterial, this);
material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]); material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
atlasNormalBlendMaterials.Add(material); atlasNormalBlendMaterials.Add(material);
pageToNormalBlendMaterial.Add(currPage, material); pageToNormalBlendMaterial.Add(currPage, material);
@ -116,16 +116,15 @@ void USpineSkeletonRendererComponent::UpdateRenderer(USpineSkeletonComponent* sk
atlasScreenBlendMaterials.Add(material); atlasScreenBlendMaterials.Add(material);
pageToScreenBlendMaterial.Add(currPage, material); pageToScreenBlendMaterial.Add(currPage, material);
} }
} } else {
else {
pageToNormalBlendMaterial.Empty(); pageToNormalBlendMaterial.Empty();
pageToAdditiveBlendMaterial.Empty(); pageToAdditiveBlendMaterial.Empty();
pageToMultiplyBlendMaterial.Empty(); pageToMultiplyBlendMaterial.Empty();
pageToScreenBlendMaterial.Empty(); pageToScreenBlendMaterial.Empty();
for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) { for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) {
AtlasPage* currPage = skeleton->Atlas->GetAtlas()->getPages()[i]; AtlasPage *currPage = skeleton->Atlas->GetAtlas()->getPages()[i];
UTexture2D* texture = skeleton->Atlas->atlasPages[i]; UTexture2D *texture = skeleton->Atlas->atlasPages[i];
UpdateRendererMaterial(currPage, texture, atlasNormalBlendMaterials[i], NormalBlendMaterial, pageToNormalBlendMaterial); UpdateRendererMaterial(currPage, texture, atlasNormalBlendMaterials[i], NormalBlendMaterial, pageToNormalBlendMaterial);
UpdateRendererMaterial(currPage, texture, atlasAdditiveBlendMaterials[i], AdditiveBlendMaterial, pageToAdditiveBlendMaterial); UpdateRendererMaterial(currPage, texture, atlasAdditiveBlendMaterials[i], AdditiveBlendMaterial, pageToAdditiveBlendMaterial);
@ -134,34 +133,33 @@ void USpineSkeletonRendererComponent::UpdateRenderer(USpineSkeletonComponent* sk
} }
} }
UpdateMesh(skeleton->GetSkeleton()); UpdateMesh(skeleton->GetSkeleton());
} } else {
else {
ClearAllMeshSections(); ClearAllMeshSections();
} }
} }
void USpineSkeletonRendererComponent::UpdateRendererMaterial(spine::AtlasPage* CurrentPage, UTexture2D* Texture, void USpineSkeletonRendererComponent::UpdateRendererMaterial(spine::AtlasPage *CurrentPage, UTexture2D *Texture,
UMaterialInstanceDynamic*& CurrentInstance, UMaterialInterface* ParentMaterial, UMaterialInstanceDynamic *&CurrentInstance, UMaterialInterface *ParentMaterial,
TMap<spine::AtlasPage*, UMaterialInstanceDynamic*>& PageToBlendMaterial) { TMap<spine::AtlasPage *, UMaterialInstanceDynamic *> &PageToBlendMaterial) {
UTexture* oldTexture = nullptr; UTexture *oldTexture = nullptr;
if (!CurrentInstance || !CurrentInstance->GetTextureParameterValue(TextureParameterName, oldTexture) || if (!CurrentInstance || !CurrentInstance->GetTextureParameterValue(TextureParameterName, oldTexture) ||
oldTexture != Texture || CurrentInstance->Parent != ParentMaterial) { oldTexture != Texture || CurrentInstance->Parent != ParentMaterial) {
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(ParentMaterial, this); UMaterialInstanceDynamic *material = UMaterialInstanceDynamic::Create(ParentMaterial, this);
material->SetTextureParameterValue(TextureParameterName, Texture); material->SetTextureParameterValue(TextureParameterName, Texture);
CurrentInstance = material; CurrentInstance = material;
} }
PageToBlendMaterial.Add(CurrentPage, CurrentInstance); PageToBlendMaterial.Add(CurrentPage, CurrentInstance);
} }
void USpineSkeletonRendererComponent::Flush(int& Idx, TArray<FVector>& Vertices, TArray<int32>& Indices, TArray<FVector>& Normals, TArray<FVector2D>& Uvs, TArray<FColor>& Colors, TArray<FVector>& Colors2, UMaterialInstanceDynamic* Material) { void USpineSkeletonRendererComponent::Flush(int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector> &Normals, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, TArray<FVector> &Colors2, UMaterialInstanceDynamic *Material) {
if (Vertices.Num() == 0) return; if (Vertices.Num() == 0) return;
SetMaterial(Idx, Material); SetMaterial(Idx, Material);
bool bShouldCreateCollision = false; bool bShouldCreateCollision = false;
if (bCreateCollision) { if (bCreateCollision) {
UWorld* world = GetWorld(); UWorld *world = GetWorld();
if (world && world->IsGameWorld()) { if (world && world->IsGameWorld()) {
bShouldCreateCollision = true; bShouldCreateCollision = true;
} }
@ -179,7 +177,7 @@ void USpineSkeletonRendererComponent::Flush(int& Idx, TArray<FVector>& Vertices,
Idx++; Idx++;
} }
void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) { void USpineSkeletonRendererComponent::UpdateMesh(Skeleton *Skeleton) {
TArray<FVector> vertices; TArray<FVector> vertices;
TArray<int32> indices; TArray<int32> indices;
TArray<FVector> normals; TArray<FVector> normals;
@ -189,7 +187,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
int idx = 0; int idx = 0;
int meshSection = 0; int meshSection = 0;
UMaterialInstanceDynamic* lastMaterial = nullptr; UMaterialInstanceDynamic *lastMaterial = nullptr;
ClearAllMeshSections(); ClearAllMeshSections();
@ -197,20 +195,20 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
if (Skeleton->getColor().a == 0) return; if (Skeleton->getColor().a == 0) return;
float depthOffset = 0; float depthOffset = 0;
unsigned short quadIndices[] = { 0, 1, 2, 0, 2, 3 }; unsigned short quadIndices[] = {0, 1, 2, 0, 2, 3};
for (size_t i = 0; i < Skeleton->getSlots().size(); ++i) { for (size_t i = 0; i < Skeleton->getSlots().size(); ++i) {
Vector<float>* attachmentVertices = &worldVertices; Vector<float> *attachmentVertices = &worldVertices;
unsigned short* attachmentIndices = nullptr; unsigned short *attachmentIndices = nullptr;
int numVertices; int numVertices;
int numIndices; int numIndices;
AtlasRegion* attachmentAtlasRegion = nullptr; AtlasRegion *attachmentAtlasRegion = nullptr;
spine::Color attachmentColor; spine::Color attachmentColor;
attachmentColor.set(1, 1, 1, 1); attachmentColor.set(1, 1, 1, 1);
float* attachmentUvs = nullptr; float *attachmentUvs = nullptr;
Slot* slot = Skeleton->getDrawOrder()[i]; Slot *slot = Skeleton->getDrawOrder()[i];
Attachment* attachment = slot->getAttachment(); Attachment *attachment = slot->getAttachment();
if (slot->getColor().a == 0 || !slot->getBone().isActive()) { if (slot->getColor().a == 0 || !slot->getBone().isActive()) {
clipper.clipEnd(*slot); clipper.clipEnd(*slot);
@ -227,7 +225,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
} }
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
RegionAttachment* regionAttachment = (RegionAttachment*)attachment; RegionAttachment *regionAttachment = (RegionAttachment *) attachment;
// Early out if region is invisible // Early out if region is invisible
if (regionAttachment->getColor().a == 0) { if (regionAttachment->getColor().a == 0) {
@ -236,15 +234,14 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
} }
attachmentColor.set(regionAttachment->getColor()); attachmentColor.set(regionAttachment->getColor());
attachmentAtlasRegion = (AtlasRegion*)regionAttachment->getRendererObject(); attachmentAtlasRegion = (AtlasRegion *) regionAttachment->getRendererObject();
regionAttachment->computeWorldVertices(slot->getBone(), *attachmentVertices, 0, 2); regionAttachment->computeWorldVertices(slot->getBone(), *attachmentVertices, 0, 2);
attachmentIndices = quadIndices; attachmentIndices = quadIndices;
attachmentUvs = regionAttachment->getUVs().buffer(); attachmentUvs = regionAttachment->getUVs().buffer();
numVertices = 4; numVertices = 4;
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) {
@ -253,15 +250,14 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
} }
attachmentColor.set(mesh->getColor()); attachmentColor.set(mesh->getColor());
attachmentAtlasRegion = (AtlasRegion*)mesh->getRendererObject(); attachmentAtlasRegion = (AtlasRegion *) mesh->getRendererObject();
mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), *attachmentVertices, 0, 2); mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), *attachmentVertices, 0, 2);
attachmentIndices = mesh->getTriangles().buffer(); attachmentIndices = mesh->getTriangles().buffer();
attachmentUvs = mesh->getUVs().buffer(); attachmentUvs = mesh->getUVs().buffer();
numVertices = mesh->getWorldVerticesLength() >> 1; numVertices = mesh->getWorldVerticesLength() >> 1;
numIndices = mesh->getTriangles().size(); numIndices = mesh->getTriangles().size();
} } else /* clipping */ {
else /* clipping */ { ClippingAttachment *clip = (ClippingAttachment *) attachment;
ClippingAttachment* clip = (ClippingAttachment*)attachment;
clipper.clipStart(*slot, clip); clipper.clipStart(*slot, clip);
continue; continue;
} }
@ -269,42 +265,42 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
// 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;
switch (slot->getData().getBlendMode()) { switch (slot->getData().getBlendMode()) {
case BlendMode_Normal: case BlendMode_Normal:
if (!pageToNormalBlendMaterial.Contains(attachmentAtlasRegion->page)) { if (!pageToNormalBlendMaterial.Contains(attachmentAtlasRegion->page)) {
clipper.clipEnd(*slot); clipper.clipEnd(*slot);
continue; continue;
} }
material = pageToNormalBlendMaterial[attachmentAtlasRegion->page]; material = pageToNormalBlendMaterial[attachmentAtlasRegion->page];
break; break;
case BlendMode_Additive: case BlendMode_Additive:
if (!pageToAdditiveBlendMaterial.Contains(attachmentAtlasRegion->page)) { if (!pageToAdditiveBlendMaterial.Contains(attachmentAtlasRegion->page)) {
clipper.clipEnd(*slot); clipper.clipEnd(*slot);
continue; continue;
} }
material = pageToAdditiveBlendMaterial[attachmentAtlasRegion->page]; material = pageToAdditiveBlendMaterial[attachmentAtlasRegion->page];
break; break;
case BlendMode_Multiply: case BlendMode_Multiply:
if (!pageToMultiplyBlendMaterial.Contains(attachmentAtlasRegion->page)) { if (!pageToMultiplyBlendMaterial.Contains(attachmentAtlasRegion->page)) {
clipper.clipEnd(*slot); clipper.clipEnd(*slot);
continue; continue;
} }
material = pageToMultiplyBlendMaterial[attachmentAtlasRegion->page]; material = pageToMultiplyBlendMaterial[attachmentAtlasRegion->page];
break; break;
case BlendMode_Screen: case BlendMode_Screen:
if (!pageToScreenBlendMaterial.Contains(attachmentAtlasRegion->page)) { if (!pageToScreenBlendMaterial.Contains(attachmentAtlasRegion->page)) {
clipper.clipEnd(*slot); clipper.clipEnd(*slot);
continue; continue;
} }
material = pageToScreenBlendMaterial[attachmentAtlasRegion->page]; material = pageToScreenBlendMaterial[attachmentAtlasRegion->page];
break; break;
default: default:
if (!pageToNormalBlendMaterial.Contains(attachmentAtlasRegion->page)) { if (!pageToNormalBlendMaterial.Contains(attachmentAtlasRegion->page)) {
clipper.clipEnd(*slot); clipper.clipEnd(*slot);
continue; continue;
} }
material = pageToNormalBlendMaterial[attachmentAtlasRegion->page]; material = pageToNormalBlendMaterial[attachmentAtlasRegion->page];
} }
if (clipper.isClipping()) { if (clipper.isClipping()) {
@ -337,7 +333,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
float dg = slot->hasDarkColor() ? slot->getDarkColor().g : 0.0f; float dg = slot->hasDarkColor() ? slot->getDarkColor().g : 0.0f;
float db = slot->hasDarkColor() ? slot->getDarkColor().b : 0.0f; float db = slot->hasDarkColor() ? slot->getDarkColor().b : 0.0f;
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));
darkColors.Add(FVector(dr, dg, db)); darkColors.Add(FVector(dr, dg, db));
@ -351,7 +347,6 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
} }
//Calculate total triangle to add on this loof. //Calculate total triangle to add on this loof.
int TriangleInitialCount = firstIndex / 3; int TriangleInitialCount = firstIndex / 3;
@ -367,19 +362,17 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
const int TargetTringleIndex = firstIndex + j * 3; const int TargetTringleIndex = firstIndex + j * 3;
if (FVector::CrossProduct( if (FVector::CrossProduct(
vertices[indices[TargetTringleIndex + 2]] - vertices[indices[TargetTringleIndex]], vertices[indices[TargetTringleIndex + 2]] - vertices[indices[TargetTringleIndex]],
vertices[indices[TargetTringleIndex + 1]] - vertices[indices[TargetTringleIndex]]).Y < 0.f) vertices[indices[TargetTringleIndex + 1]] - vertices[indices[TargetTringleIndex]])
{ .Y < 0.f) {
const int32 targetVertex = indices[TargetTringleIndex]; const int32 targetVertex = indices[TargetTringleIndex];
indices[TargetTringleIndex] = indices[TargetTringleIndex + 2]; indices[TargetTringleIndex] = indices[TargetTringleIndex + 2];
indices[TargetTringleIndex + 2] = targetVertex; indices[TargetTringleIndex + 2] = targetVertex;
} }
} }
FVector normal = FVector(0, 1, 0); FVector normal = FVector(0, 1, 0);
//Add normals for vertices. //Add normals for vertices.
@ -387,7 +380,6 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
for (int j = 0; j < numVertices; j++) { for (int j = 0; j < numVertices; j++) {
normals.Add(normal); normals.Add(normal);
} }
idx += numVertices; idx += numVertices;