[ue4] More cleanup

This commit is contained in:
badlogic 2016-12-01 14:08:27 +01:00
parent dbc9c9fb5d
commit a125241bcc
8 changed files with 21 additions and 22 deletions

Binary file not shown.

View File

@ -16,18 +16,18 @@ void USpineSkeletonComponent::BeginPlay() {
void USpineSkeletonComponent::TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { void USpineSkeletonComponent::TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (lastAtlas != atlas || lastData != skeletonData) { if (lastAtlas != Atlas || lastData != SkeletonData) {
DisposeState(); DisposeState();
if (atlas && skeletonData) { if (Atlas && SkeletonData) {
spSkeletonData* data = skeletonData->GetSkeletonData(atlas->GetAtlas(false), false); spSkeletonData* data = SkeletonData->GetSkeletonData(Atlas->GetAtlas(false), false);
skeleton = spSkeleton_create(data); skeleton = spSkeleton_create(data);
stateData = spAnimationStateData_create(data); stateData = spAnimationStateData_create(data);
state = spAnimationState_create(stateData); state = spAnimationState_create(stateData);
} }
lastAtlas = atlas; lastAtlas = Atlas;
lastData = skeletonData; lastData = SkeletonData;
} }
if (state) { if (state) {

View File

@ -28,14 +28,14 @@ void USpineSkeletonRendererComponent::TickComponent (float DeltaTime, ELevelTick
AActor* owner = GetOwner(); AActor* owner = GetOwner();
if (owner) { if (owner) {
USpineSkeletonComponent* skeleton = Cast<USpineSkeletonComponent>(owner->GetComponentByClass(skeletonClass)); USpineSkeletonComponent* skeleton = Cast<USpineSkeletonComponent>(owner->GetComponentByClass(skeletonClass));
if (skeleton && !skeleton->IsBeingDestroyed() && skeleton->skeleton) { if (skeleton && !skeleton->IsBeingDestroyed() && skeleton->GetSkeleton()) {
if (atlasMaterials.Num() != skeleton->atlas->atlasPages.Num()) { if (atlasMaterials.Num() != skeleton->Atlas->atlasPages.Num()) {
atlasMaterials.SetNum(0); atlasMaterials.SetNum(0);
pageToMaterial.Empty(); pageToMaterial.Empty();
spAtlasPage* currPage = skeleton->atlas->GetAtlas(false)->pages; spAtlasPage* currPage = skeleton->Atlas->GetAtlas(false)->pages;
for (int i = 0; i < skeleton->atlas->atlasPages.Num(); i++) { for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) {
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(DefaultMaterial, owner); UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(DefaultMaterial, owner);
material->SetTextureParameterValue(TextureParameterName, skeleton->atlas->atlasPages[i]); material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
atlasMaterials.Add(material); atlasMaterials.Add(material);
pageToMaterial.Add(currPage, material); pageToMaterial.Add(currPage, material);
currPage = currPage->next; currPage = currPage->next;
@ -43,10 +43,10 @@ void USpineSkeletonRendererComponent::TickComponent (float DeltaTime, ELevelTick
} }
else { else {
pageToMaterial.Empty(); pageToMaterial.Empty();
spAtlasPage* currPage = skeleton->atlas->GetAtlas(false)->pages; spAtlasPage* currPage = skeleton->Atlas->GetAtlas(false)->pages;
for (int i = 0; i < skeleton->atlas->atlasPages.Num(); i++) { for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) {
UMaterialInstanceDynamic* current = atlasMaterials[i]; UMaterialInstanceDynamic* current = atlasMaterials[i];
UTexture2D* texture = skeleton->atlas->atlasPages[i]; UTexture2D* texture = skeleton->Atlas->atlasPages[i];
UTexture* oldTexture = nullptr; UTexture* oldTexture = nullptr;
if(!current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) { if(!current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(DefaultMaterial, owner); UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(DefaultMaterial, owner);
@ -57,8 +57,7 @@ void USpineSkeletonRendererComponent::TickComponent (float DeltaTime, ELevelTick
currPage = currPage->next; currPage = currPage->next;
} }
} }
spSkeleton_updateWorldTransform(skeleton->skeleton); UpdateMesh(skeleton->GetSkeleton());
UpdateMesh(skeleton->skeleton);
} }
} }
} }
@ -135,7 +134,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(spSkeleton* Skeleton) {
indices.Add(idx + 2); indices.Add(idx + 2);
indices.Add(idx + 3); indices.Add(idx + 3);
idx += 4; idx += 4;
depthOffset -= this->depthOffset; depthOffset += this->DepthOffset;
SetMaterial(meshSection, material); SetMaterial(meshSection, material);
} else if (attachment->type == SP_ATTACHMENT_MESH) { } else if (attachment->type == SP_ATTACHMENT_MESH) {
@ -158,17 +157,17 @@ void USpineSkeletonRendererComponent::UpdateMesh(spSkeleton* Skeleton) {
uint8 b = static_cast<uint8>(Skeleton->b * slot->b * 255); uint8 b = static_cast<uint8>(Skeleton->b * slot->b * 255);
uint8 a = static_cast<uint8>(Skeleton->a * slot->a * 255); uint8 a = static_cast<uint8>(Skeleton->a * slot->a * 255);
for (int i = 0; i < mesh->super.worldVerticesLength; i += 2) { for (int j = 0; j < mesh->super.worldVerticesLength; j += 2) {
colors.Add(FColor(r, g, b, a)); colors.Add(FColor(r, g, b, a));
vertices.Add(FVector(worldVertices[i], depthOffset, worldVertices[i + 1])); vertices.Add(FVector(worldVertices[j], depthOffset, worldVertices[j + 1]));
uvs.Add(FVector2D(mesh->uvs[i], mesh->uvs[i + 1])); uvs.Add(FVector2D(mesh->uvs[j], mesh->uvs[j + 1]));
} }
for (int i = 0; i < mesh->trianglesCount; i++) { for (int j = 0; j < mesh->trianglesCount; j++) {
indices.Add(idx + mesh->triangles[i]); indices.Add(idx + mesh->triangles[j]);
} }
idx += mesh->super.worldVerticesLength >> 1; idx += mesh->super.worldVerticesLength >> 1;
depthOffset -= this->depthOffset; depthOffset += this->DepthOffset;
SetMaterial(meshSection, material); SetMaterial(meshSection, material);
} }
} }