mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[ue4] Fix formatting.
This commit is contained in:
parent
a85765d4d9
commit
de5f8cd469
@ -1,403 +1,395 @@
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Spine Runtimes License Agreement
|
* Spine Runtimes License Agreement
|
||||||
* Last updated January 1, 2020. Replaces all prior versions.
|
* Last updated January 1, 2020. Replaces all prior versions.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013-2020, Esoteric Software LLC
|
* Copyright (c) 2013-2020, Esoteric Software LLC
|
||||||
*
|
*
|
||||||
* Integration of the Spine Runtimes into software or otherwise creating
|
* Integration of the Spine Runtimes into software or otherwise creating
|
||||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||||
* http://esotericsoftware.com/spine-editor-license
|
* http://esotericsoftware.com/spine-editor-license
|
||||||
*
|
*
|
||||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||||
* "Products"), provided that each user of the Products must obtain their own
|
* "Products"), provided that each user of the Products must obtain their own
|
||||||
* Spine Editor license and redistribution of the Products in any form must
|
* Spine Editor license and redistribution of the Products in any form must
|
||||||
* include this license and copyright notice.
|
* include this license and copyright notice.
|
||||||
*
|
*
|
||||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "Engine.h"
|
#include "Engine.h"
|
||||||
#include "SpinePluginPrivatePCH.h"
|
#include "SpinePluginPrivatePCH.h"
|
||||||
#include "spine/spine.h"
|
#include "spine/spine.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define LOCTEXT_NAMESPACE "Spine"
|
#define LOCTEXT_NAMESPACE "Spine"
|
||||||
|
|
||||||
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;
|
||||||
bAutoActivate = true;
|
bAutoActivate = true;
|
||||||
|
|
||||||
static ConstructorHelpers::FObjectFinder<UMaterialInterface> NormalMaterialRef(TEXT("/SpinePlugin/SpineUnlitNormalMaterial"));
|
static ConstructorHelpers::FObjectFinder<UMaterialInterface> NormalMaterialRef(TEXT("/SpinePlugin/SpineUnlitNormalMaterial"));
|
||||||
NormalBlendMaterial = NormalMaterialRef.Object;
|
NormalBlendMaterial = NormalMaterialRef.Object;
|
||||||
|
|
||||||
static ConstructorHelpers::FObjectFinder<UMaterialInterface> AdditiveMaterialRef(TEXT("/SpinePlugin/SpineUnlitAdditiveMaterial"));
|
static ConstructorHelpers::FObjectFinder<UMaterialInterface> AdditiveMaterialRef(TEXT("/SpinePlugin/SpineUnlitAdditiveMaterial"));
|
||||||
AdditiveBlendMaterial = AdditiveMaterialRef.Object;
|
AdditiveBlendMaterial = AdditiveMaterialRef.Object;
|
||||||
|
|
||||||
static ConstructorHelpers::FObjectFinder<UMaterialInterface> MultiplyMaterialRef(TEXT("/SpinePlugin/SpineUnlitMultiplyMaterial"));
|
static ConstructorHelpers::FObjectFinder<UMaterialInterface> MultiplyMaterialRef(TEXT("/SpinePlugin/SpineUnlitMultiplyMaterial"));
|
||||||
MultiplyBlendMaterial = MultiplyMaterialRef.Object;
|
MultiplyBlendMaterial = MultiplyMaterialRef.Object;
|
||||||
|
|
||||||
static ConstructorHelpers::FObjectFinder<UMaterialInterface> ScreenMaterialRef(TEXT("/SpinePlugin/SpineUnlitScreenMaterial"));
|
static ConstructorHelpers::FObjectFinder<UMaterialInterface> ScreenMaterialRef(TEXT("/SpinePlugin/SpineUnlitScreenMaterial"));
|
||||||
ScreenBlendMaterial = ScreenMaterialRef.Object;
|
ScreenBlendMaterial = ScreenMaterialRef.Object;
|
||||||
|
|
||||||
TextureParameterName = FName(TEXT("SpriteTexture"));
|
TextureParameterName = FName(TEXT("SpriteTexture"));
|
||||||
|
|
||||||
worldVertices.ensureCapacity(1024 * 2);
|
worldVertices.ensureCapacity(1024 * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void USpineSkeletonRendererComponent::FinishDestroy() {
|
void USpineSkeletonRendererComponent::FinishDestroy() {
|
||||||
Super::FinishDestroy();
|
Super::FinishDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void USpineSkeletonRendererComponent::BeginPlay() {
|
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);
|
||||||
|
|
||||||
if (atlasNormalBlendMaterials.Num() != skeleton->Atlas->atlasPages.Num()) {
|
if (atlasNormalBlendMaterials.Num() != skeleton->Atlas->atlasPages.Num()) {
|
||||||
atlasNormalBlendMaterials.SetNum(0);
|
atlasNormalBlendMaterials.SetNum(0);
|
||||||
pageToNormalBlendMaterial.Empty();
|
pageToNormalBlendMaterial.Empty();
|
||||||
atlasAdditiveBlendMaterials.SetNum(0);
|
atlasAdditiveBlendMaterials.SetNum(0);
|
||||||
pageToAdditiveBlendMaterial.Empty();
|
pageToAdditiveBlendMaterial.Empty();
|
||||||
atlasMultiplyBlendMaterials.SetNum(0);
|
atlasMultiplyBlendMaterials.SetNum(0);
|
||||||
pageToMultiplyBlendMaterial.Empty();
|
pageToMultiplyBlendMaterial.Empty();
|
||||||
atlasScreenBlendMaterials.SetNum(0);
|
atlasScreenBlendMaterials.SetNum(0);
|
||||||
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);
|
||||||
|
|
||||||
material = UMaterialInstanceDynamic::Create(AdditiveBlendMaterial, this);
|
material = UMaterialInstanceDynamic::Create(AdditiveBlendMaterial, this);
|
||||||
material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
|
material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
|
||||||
atlasAdditiveBlendMaterials.Add(material);
|
atlasAdditiveBlendMaterials.Add(material);
|
||||||
pageToAdditiveBlendMaterial.Add(currPage, material);
|
pageToAdditiveBlendMaterial.Add(currPage, material);
|
||||||
|
|
||||||
material = UMaterialInstanceDynamic::Create(MultiplyBlendMaterial, this);
|
material = UMaterialInstanceDynamic::Create(MultiplyBlendMaterial, this);
|
||||||
material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
|
material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
|
||||||
atlasMultiplyBlendMaterials.Add(material);
|
atlasMultiplyBlendMaterials.Add(material);
|
||||||
pageToMultiplyBlendMaterial.Add(currPage, material);
|
pageToMultiplyBlendMaterial.Add(currPage, material);
|
||||||
|
|
||||||
material = UMaterialInstanceDynamic::Create(ScreenBlendMaterial, this);
|
material = UMaterialInstanceDynamic::Create(ScreenBlendMaterial, this);
|
||||||
material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
|
material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
|
||||||
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);
|
UpdateRendererMaterial(currPage, texture, atlasMultiplyBlendMaterials[i], MultiplyBlendMaterial, pageToMultiplyBlendMaterial);
|
||||||
UpdateRendererMaterial(currPage, texture, atlasMultiplyBlendMaterials[i], MultiplyBlendMaterial, pageToMultiplyBlendMaterial);
|
UpdateRendererMaterial(currPage, texture, atlasScreenBlendMaterials[i], ScreenBlendMaterial, pageToScreenBlendMaterial);
|
||||||
UpdateRendererMaterial(currPage, texture, atlasScreenBlendMaterials[i], ScreenBlendMaterial, pageToScreenBlendMaterial);
|
}
|
||||||
}
|
}
|
||||||
}
|
UpdateMesh(skeleton->GetSkeleton());
|
||||||
UpdateMesh(skeleton->GetSkeleton());
|
} else {
|
||||||
}
|
ClearAllMeshSections();
|
||||||
else {
|
}
|
||||||
ClearAllMeshSections();
|
}
|
||||||
}
|
|
||||||
}
|
void USpineSkeletonRendererComponent::UpdateRendererMaterial(spine::AtlasPage *CurrentPage, UTexture2D *Texture,
|
||||||
|
UMaterialInstanceDynamic *&CurrentInstance, UMaterialInterface *ParentMaterial,
|
||||||
void USpineSkeletonRendererComponent::UpdateRendererMaterial(spine::AtlasPage* CurrentPage, UTexture2D* Texture,
|
TMap<spine::AtlasPage *, UMaterialInstanceDynamic *> &PageToBlendMaterial) {
|
||||||
UMaterialInstanceDynamic*& CurrentInstance, UMaterialInterface* ParentMaterial,
|
|
||||||
TMap<spine::AtlasPage*, UMaterialInstanceDynamic*>& PageToBlendMaterial) {
|
UTexture *oldTexture = nullptr;
|
||||||
|
if (!CurrentInstance || !CurrentInstance->GetTextureParameterValue(TextureParameterName, oldTexture) ||
|
||||||
UTexture* oldTexture = nullptr;
|
oldTexture != Texture || CurrentInstance->Parent != ParentMaterial) {
|
||||||
if (!CurrentInstance || !CurrentInstance->GetTextureParameterValue(TextureParameterName, oldTexture) ||
|
|
||||||
oldTexture != Texture || CurrentInstance->Parent != ParentMaterial) {
|
UMaterialInstanceDynamic *material = UMaterialInstanceDynamic::Create(ParentMaterial, this);
|
||||||
|
material->SetTextureParameterValue(TextureParameterName, Texture);
|
||||||
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(ParentMaterial, this);
|
CurrentInstance = material;
|
||||||
material->SetTextureParameterValue(TextureParameterName, Texture);
|
}
|
||||||
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) {
|
||||||
|
if (Vertices.Num() == 0) return;
|
||||||
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) {
|
SetMaterial(Idx, Material);
|
||||||
if (Vertices.Num() == 0) return;
|
|
||||||
SetMaterial(Idx, Material);
|
bool bShouldCreateCollision = false;
|
||||||
|
if (bCreateCollision) {
|
||||||
bool bShouldCreateCollision = false;
|
UWorld *world = GetWorld();
|
||||||
if (bCreateCollision) {
|
if (world && world->IsGameWorld()) {
|
||||||
UWorld* world = GetWorld();
|
bShouldCreateCollision = true;
|
||||||
if (world && world->IsGameWorld()) {
|
}
|
||||||
bShouldCreateCollision = true;
|
}
|
||||||
}
|
|
||||||
}
|
GetBodySetup()->bGenerateMirroredCollision = GetComponentScale().X < 0 || GetComponentScale().Y < 0 || GetComponentScale().Z < 0;
|
||||||
|
CreateMeshSection(Idx, Vertices, Indices, Normals, Uvs, Colors, TArray<FProcMeshTangent>(), bShouldCreateCollision);
|
||||||
GetBodySetup()->bGenerateMirroredCollision = GetComponentScale().X < 0 || GetComponentScale().Y < 0 || GetComponentScale().Z < 0;
|
|
||||||
CreateMeshSection(Idx, Vertices, Indices, Normals, Uvs, Colors, TArray<FProcMeshTangent>(), bShouldCreateCollision);
|
Vertices.SetNum(0);
|
||||||
|
Indices.SetNum(0);
|
||||||
Vertices.SetNum(0);
|
Normals.SetNum(0);
|
||||||
Indices.SetNum(0);
|
Uvs.SetNum(0);
|
||||||
Normals.SetNum(0);
|
Colors.SetNum(0);
|
||||||
Uvs.SetNum(0);
|
Colors2.SetNum(0);
|
||||||
Colors.SetNum(0);
|
Idx++;
|
||||||
Colors2.SetNum(0);
|
}
|
||||||
Idx++;
|
|
||||||
}
|
void USpineSkeletonRendererComponent::UpdateMesh(Skeleton *Skeleton) {
|
||||||
|
TArray<FVector> vertices;
|
||||||
void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
|
TArray<int32> indices;
|
||||||
TArray<FVector> vertices;
|
TArray<FVector> normals;
|
||||||
TArray<int32> indices;
|
TArray<FVector2D> uvs;
|
||||||
TArray<FVector> normals;
|
TArray<FColor> colors;
|
||||||
TArray<FVector2D> uvs;
|
TArray<FVector> darkColors;
|
||||||
TArray<FColor> colors;
|
|
||||||
TArray<FVector> darkColors;
|
int idx = 0;
|
||||||
|
int meshSection = 0;
|
||||||
int idx = 0;
|
UMaterialInstanceDynamic *lastMaterial = nullptr;
|
||||||
int meshSection = 0;
|
|
||||||
UMaterialInstanceDynamic* lastMaterial = nullptr;
|
ClearAllMeshSections();
|
||||||
|
|
||||||
ClearAllMeshSections();
|
// Early out if skeleton is invisible
|
||||||
|
if (Skeleton->getColor().a == 0) return;
|
||||||
// Early out if skeleton is invisible
|
|
||||||
if (Skeleton->getColor().a == 0) return;
|
float depthOffset = 0;
|
||||||
|
unsigned short quadIndices[] = {0, 1, 2, 0, 2, 3};
|
||||||
float depthOffset = 0;
|
|
||||||
unsigned short quadIndices[] = { 0, 1, 2, 0, 2, 3 };
|
for (size_t i = 0; i < Skeleton->getSlots().size(); ++i) {
|
||||||
|
Vector<float> *attachmentVertices = &worldVertices;
|
||||||
for (size_t i = 0; i < Skeleton->getSlots().size(); ++i) {
|
unsigned short *attachmentIndices = nullptr;
|
||||||
Vector<float>* attachmentVertices = &worldVertices;
|
int numVertices;
|
||||||
unsigned short* attachmentIndices = nullptr;
|
int numIndices;
|
||||||
int numVertices;
|
AtlasRegion *attachmentAtlasRegion = nullptr;
|
||||||
int numIndices;
|
spine::Color attachmentColor;
|
||||||
AtlasRegion* attachmentAtlasRegion = nullptr;
|
attachmentColor.set(1, 1, 1, 1);
|
||||||
spine::Color attachmentColor;
|
float *attachmentUvs = nullptr;
|
||||||
attachmentColor.set(1, 1, 1, 1);
|
|
||||||
float* attachmentUvs = nullptr;
|
Slot *slot = Skeleton->getDrawOrder()[i];
|
||||||
|
Attachment *attachment = slot->getAttachment();
|
||||||
Slot* slot = Skeleton->getDrawOrder()[i];
|
|
||||||
Attachment* attachment = slot->getAttachment();
|
if (slot->getColor().a == 0 || !slot->getBone().isActive()) {
|
||||||
|
clipper.clipEnd(*slot);
|
||||||
if (slot->getColor().a == 0 || !slot->getBone().isActive()) {
|
continue;
|
||||||
clipper.clipEnd(*slot);
|
}
|
||||||
continue;
|
|
||||||
}
|
if (!attachment) {
|
||||||
|
clipper.clipEnd(*slot);
|
||||||
if (!attachment) {
|
continue;
|
||||||
clipper.clipEnd(*slot);
|
}
|
||||||
continue;
|
if (!attachment->getRTTI().isExactly(RegionAttachment::rtti) && !attachment->getRTTI().isExactly(MeshAttachment::rtti) && !attachment->getRTTI().isExactly(ClippingAttachment::rtti)) {
|
||||||
}
|
clipper.clipEnd(*slot);
|
||||||
if (!attachment->getRTTI().isExactly(RegionAttachment::rtti) && !attachment->getRTTI().isExactly(MeshAttachment::rtti) && !attachment->getRTTI().isExactly(ClippingAttachment::rtti)) {
|
continue;
|
||||||
clipper.clipEnd(*slot);
|
}
|
||||||
continue;
|
|
||||||
}
|
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
|
||||||
|
RegionAttachment *regionAttachment = (RegionAttachment *) attachment;
|
||||||
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
|
|
||||||
RegionAttachment* regionAttachment = (RegionAttachment*)attachment;
|
// Early out if region is invisible
|
||||||
|
if (regionAttachment->getColor().a == 0) {
|
||||||
// Early out if region is invisible
|
clipper.clipEnd(*slot);
|
||||||
if (regionAttachment->getColor().a == 0) {
|
continue;
|
||||||
clipper.clipEnd(*slot);
|
}
|
||||||
continue;
|
|
||||||
}
|
attachmentColor.set(regionAttachment->getColor());
|
||||||
|
attachmentAtlasRegion = (AtlasRegion *) regionAttachment->getRendererObject();
|
||||||
attachmentColor.set(regionAttachment->getColor());
|
regionAttachment->computeWorldVertices(slot->getBone(), *attachmentVertices, 0, 2);
|
||||||
attachmentAtlasRegion = (AtlasRegion*)regionAttachment->getRendererObject();
|
attachmentIndices = quadIndices;
|
||||||
regionAttachment->computeWorldVertices(slot->getBone(), *attachmentVertices, 0, 2);
|
attachmentUvs = regionAttachment->getUVs().buffer();
|
||||||
attachmentIndices = quadIndices;
|
numVertices = 4;
|
||||||
attachmentUvs = regionAttachment->getUVs().buffer();
|
numIndices = 6;
|
||||||
numVertices = 4;
|
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
|
||||||
numIndices = 6;
|
MeshAttachment *mesh = (MeshAttachment *) attachment;
|
||||||
}
|
|
||||||
else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
|
// Early out if region is invisible
|
||||||
MeshAttachment* mesh = (MeshAttachment*)attachment;
|
if (mesh->getColor().a == 0) {
|
||||||
|
clipper.clipEnd(*slot);
|
||||||
// Early out if region is invisible
|
continue;
|
||||||
if (mesh->getColor().a == 0) {
|
}
|
||||||
clipper.clipEnd(*slot);
|
|
||||||
continue;
|
attachmentColor.set(mesh->getColor());
|
||||||
}
|
attachmentAtlasRegion = (AtlasRegion *) mesh->getRendererObject();
|
||||||
|
mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), *attachmentVertices, 0, 2);
|
||||||
attachmentColor.set(mesh->getColor());
|
attachmentIndices = mesh->getTriangles().buffer();
|
||||||
attachmentAtlasRegion = (AtlasRegion*)mesh->getRendererObject();
|
attachmentUvs = mesh->getUVs().buffer();
|
||||||
mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), *attachmentVertices, 0, 2);
|
numVertices = mesh->getWorldVerticesLength() >> 1;
|
||||||
attachmentIndices = mesh->getTriangles().buffer();
|
numIndices = mesh->getTriangles().size();
|
||||||
attachmentUvs = mesh->getUVs().buffer();
|
} else /* clipping */ {
|
||||||
numVertices = mesh->getWorldVerticesLength() >> 1;
|
ClippingAttachment *clip = (ClippingAttachment *) attachment;
|
||||||
numIndices = mesh->getTriangles().size();
|
clipper.clipStart(*slot, clip);
|
||||||
}
|
continue;
|
||||||
else /* clipping */ {
|
}
|
||||||
ClippingAttachment* clip = (ClippingAttachment*)attachment;
|
|
||||||
clipper.clipStart(*slot, clip);
|
// if the user switches the atlas data while not having switched
|
||||||
continue;
|
// to the correct skeleton data yet, we won't find any regions.
|
||||||
}
|
// ignore regions for which we can't find a material
|
||||||
|
UMaterialInstanceDynamic *material = nullptr;
|
||||||
// if the user switches the atlas data while not having switched
|
switch (slot->getData().getBlendMode()) {
|
||||||
// to the correct skeleton data yet, we won't find any regions.
|
case BlendMode_Normal:
|
||||||
// ignore regions for which we can't find a material
|
if (!pageToNormalBlendMaterial.Contains(attachmentAtlasRegion->page)) {
|
||||||
UMaterialInstanceDynamic* material = nullptr;
|
clipper.clipEnd(*slot);
|
||||||
switch (slot->getData().getBlendMode()) {
|
continue;
|
||||||
case BlendMode_Normal:
|
}
|
||||||
if (!pageToNormalBlendMaterial.Contains(attachmentAtlasRegion->page)) {
|
material = pageToNormalBlendMaterial[attachmentAtlasRegion->page];
|
||||||
clipper.clipEnd(*slot);
|
break;
|
||||||
continue;
|
case BlendMode_Additive:
|
||||||
}
|
if (!pageToAdditiveBlendMaterial.Contains(attachmentAtlasRegion->page)) {
|
||||||
material = pageToNormalBlendMaterial[attachmentAtlasRegion->page];
|
clipper.clipEnd(*slot);
|
||||||
break;
|
continue;
|
||||||
case BlendMode_Additive:
|
}
|
||||||
if (!pageToAdditiveBlendMaterial.Contains(attachmentAtlasRegion->page)) {
|
material = pageToAdditiveBlendMaterial[attachmentAtlasRegion->page];
|
||||||
clipper.clipEnd(*slot);
|
break;
|
||||||
continue;
|
case BlendMode_Multiply:
|
||||||
}
|
if (!pageToMultiplyBlendMaterial.Contains(attachmentAtlasRegion->page)) {
|
||||||
material = pageToAdditiveBlendMaterial[attachmentAtlasRegion->page];
|
clipper.clipEnd(*slot);
|
||||||
break;
|
continue;
|
||||||
case BlendMode_Multiply:
|
}
|
||||||
if (!pageToMultiplyBlendMaterial.Contains(attachmentAtlasRegion->page)) {
|
material = pageToMultiplyBlendMaterial[attachmentAtlasRegion->page];
|
||||||
clipper.clipEnd(*slot);
|
break;
|
||||||
continue;
|
case BlendMode_Screen:
|
||||||
}
|
if (!pageToScreenBlendMaterial.Contains(attachmentAtlasRegion->page)) {
|
||||||
material = pageToMultiplyBlendMaterial[attachmentAtlasRegion->page];
|
clipper.clipEnd(*slot);
|
||||||
break;
|
continue;
|
||||||
case BlendMode_Screen:
|
}
|
||||||
if (!pageToScreenBlendMaterial.Contains(attachmentAtlasRegion->page)) {
|
material = pageToScreenBlendMaterial[attachmentAtlasRegion->page];
|
||||||
clipper.clipEnd(*slot);
|
break;
|
||||||
continue;
|
default:
|
||||||
}
|
if (!pageToNormalBlendMaterial.Contains(attachmentAtlasRegion->page)) {
|
||||||
material = pageToScreenBlendMaterial[attachmentAtlasRegion->page];
|
clipper.clipEnd(*slot);
|
||||||
break;
|
continue;
|
||||||
default:
|
}
|
||||||
if (!pageToNormalBlendMaterial.Contains(attachmentAtlasRegion->page)) {
|
material = pageToNormalBlendMaterial[attachmentAtlasRegion->page];
|
||||||
clipper.clipEnd(*slot);
|
}
|
||||||
continue;
|
|
||||||
}
|
if (clipper.isClipping()) {
|
||||||
material = pageToNormalBlendMaterial[attachmentAtlasRegion->page];
|
clipper.clipTriangles(attachmentVertices->buffer(), attachmentIndices, numIndices, attachmentUvs, 2);
|
||||||
}
|
attachmentVertices = &clipper.getClippedVertices();
|
||||||
|
numVertices = clipper.getClippedVertices().size() >> 1;
|
||||||
if (clipper.isClipping()) {
|
attachmentIndices = clipper.getClippedTriangles().buffer();
|
||||||
clipper.clipTriangles(attachmentVertices->buffer(), attachmentIndices, numIndices, attachmentUvs, 2);
|
numIndices = clipper.getClippedTriangles().size();
|
||||||
attachmentVertices = &clipper.getClippedVertices();
|
attachmentUvs = clipper.getClippedUVs().buffer();
|
||||||
numVertices = clipper.getClippedVertices().size() >> 1;
|
if (clipper.getClippedTriangles().size() == 0) {
|
||||||
attachmentIndices = clipper.getClippedTriangles().buffer();
|
clipper.clipEnd(*slot);
|
||||||
numIndices = clipper.getClippedTriangles().size();
|
continue;
|
||||||
attachmentUvs = clipper.getClippedUVs().buffer();
|
}
|
||||||
if (clipper.getClippedTriangles().size() == 0) {
|
}
|
||||||
clipper.clipEnd(*slot);
|
|
||||||
continue;
|
if (lastMaterial != material) {
|
||||||
}
|
Flush(meshSection, vertices, indices, normals, uvs, colors, darkColors, lastMaterial);
|
||||||
}
|
lastMaterial = material;
|
||||||
|
idx = 0;
|
||||||
if (lastMaterial != material) {
|
}
|
||||||
Flush(meshSection, vertices, indices, normals, uvs, colors, darkColors, lastMaterial);
|
|
||||||
lastMaterial = material;
|
SetMaterial(meshSection, material);
|
||||||
idx = 0;
|
|
||||||
}
|
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);
|
||||||
SetMaterial(meshSection, material);
|
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 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);
|
float dr = slot->hasDarkColor() ? slot->getDarkColor().r : 0.0f;
|
||||||
uint8 b = static_cast<uint8>(Skeleton->getColor().b * slot->getColor().b * attachmentColor.b * 255);
|
float dg = slot->hasDarkColor() ? slot->getDarkColor().g : 0.0f;
|
||||||
uint8 a = static_cast<uint8>(Skeleton->getColor().a * slot->getColor().a * attachmentColor.a * 255);
|
float db = slot->hasDarkColor() ? slot->getDarkColor().b : 0.0f;
|
||||||
|
|
||||||
float dr = slot->hasDarkColor() ? slot->getDarkColor().r : 0.0f;
|
float *verticesPtr = attachmentVertices->buffer();
|
||||||
float dg = slot->hasDarkColor() ? slot->getDarkColor().g : 0.0f;
|
for (int j = 0; j < numVertices << 1; j += 2) {
|
||||||
float db = slot->hasDarkColor() ? slot->getDarkColor().b : 0.0f;
|
colors.Add(FColor(r, g, b, a));
|
||||||
|
darkColors.Add(FVector(dr, dg, db));
|
||||||
float* verticesPtr = attachmentVertices->buffer();
|
vertices.Add(FVector(verticesPtr[j], depthOffset, verticesPtr[j + 1]));
|
||||||
for (int j = 0; j < numVertices << 1; j += 2) {
|
uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1]));
|
||||||
colors.Add(FColor(r, g, b, a));
|
}
|
||||||
darkColors.Add(FVector(dr, dg, db));
|
|
||||||
vertices.Add(FVector(verticesPtr[j], depthOffset, verticesPtr[j + 1]));
|
int firstIndex = indices.Num();
|
||||||
uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1]));
|
for (int j = 0; j < numIndices; j++) {
|
||||||
}
|
indices.Add(idx + attachmentIndices[j]);
|
||||||
|
}
|
||||||
int firstIndex = indices.Num();
|
|
||||||
for (int j = 0; j < numIndices; j++) {
|
|
||||||
indices.Add(idx + attachmentIndices[j]);
|
//Calculate total triangle to add on this loof.
|
||||||
}
|
|
||||||
|
int TriangleInitialCount = firstIndex / 3;
|
||||||
|
|
||||||
|
int TriangleToAddNum = indices.Num() / 3 - TriangleInitialCount;
|
||||||
//Calculate total triangle to add on this loof.
|
|
||||||
|
int FirstVertexIndex = vertices.Num() - numVertices;
|
||||||
int TriangleInitialCount = firstIndex / 3;
|
|
||||||
|
//loof through all the triangles and resolve to be reversed if the triangle has winding order as CCW.
|
||||||
int TriangleToAddNum = indices.Num() / 3 - TriangleInitialCount;
|
|
||||||
|
for (int j = 0; j < TriangleToAddNum; j++) {
|
||||||
int FirstVertexIndex = vertices.Num() - numVertices;
|
|
||||||
|
const int TargetTringleIndex = firstIndex + j * 3;
|
||||||
//loof through all the triangles and resolve to be reversed if the triangle has winding order as CCW.
|
|
||||||
|
if (FVector::CrossProduct(
|
||||||
for (int j = 0; j < TriangleToAddNum; j++) {
|
vertices[indices[TargetTringleIndex + 2]] - vertices[indices[TargetTringleIndex]],
|
||||||
|
vertices[indices[TargetTringleIndex + 1]] - vertices[indices[TargetTringleIndex]])
|
||||||
const int TargetTringleIndex = firstIndex + j * 3;
|
.Y < 0.f) {
|
||||||
|
|
||||||
if (FVector::CrossProduct(
|
const int32 targetVertex = indices[TargetTringleIndex];
|
||||||
vertices[indices[TargetTringleIndex + 2]] - vertices[indices[TargetTringleIndex]],
|
indices[TargetTringleIndex] = indices[TargetTringleIndex + 2];
|
||||||
vertices[indices[TargetTringleIndex + 1]] - vertices[indices[TargetTringleIndex]]).Y < 0.f)
|
indices[TargetTringleIndex + 2] = targetVertex;
|
||||||
{
|
}
|
||||||
|
}
|
||||||
const int32 targetVertex = indices[TargetTringleIndex];
|
|
||||||
indices[TargetTringleIndex] = indices[TargetTringleIndex + 2];
|
|
||||||
indices[TargetTringleIndex + 2] = targetVertex;
|
FVector normal = FVector(0, 1, 0);
|
||||||
|
|
||||||
}
|
//Add normals for vertices.
|
||||||
}
|
|
||||||
|
for (int j = 0; j < numVertices; j++) {
|
||||||
|
|
||||||
|
normals.Add(normal);
|
||||||
FVector normal = FVector(0, 1, 0);
|
}
|
||||||
|
|
||||||
//Add normals for vertices.
|
idx += numVertices;
|
||||||
|
depthOffset += this->DepthOffset;
|
||||||
for (int j = 0; j < numVertices; j++) {
|
|
||||||
|
clipper.clipEnd(*slot);
|
||||||
normals.Add(normal);
|
}
|
||||||
|
|
||||||
}
|
Flush(meshSection, vertices, indices, normals, uvs, colors, darkColors, lastMaterial);
|
||||||
|
clipper.clipEnd();
|
||||||
idx += numVertices;
|
}
|
||||||
depthOffset += this->DepthOffset;
|
|
||||||
|
|
||||||
clipper.clipEnd(*slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
Flush(meshSection, vertices, indices, normals, uvs, colors, darkColors, lastMaterial);
|
|
||||||
clipper.clipEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef LOCTEXT_NAMESPACE
|
#undef LOCTEXT_NAMESPACE
|
||||||
Loading…
x
Reference in New Issue
Block a user