diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp index f8fd1450c..dfc63c047 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp @@ -161,7 +161,7 @@ void USpineSkeletonRendererComponent::TickComponent (float DeltaTime, ELevelTick } } -void USpineSkeletonRendererComponent::Flush (int &Idx, TArray &Vertices, TArray &Indices, TArray &Uvs, TArray &Colors, UMaterialInstanceDynamic* Material) { +void USpineSkeletonRendererComponent::Flush (int &Idx, TArray &Vertices, TArray &Indices, TArray &Uvs, TArray &Colors, TArray& Colors2, UMaterialInstanceDynamic* Material) { if (Vertices.Num() == 0) return; SetMaterial(Idx, Material); CreateMeshSection(Idx, Vertices, Indices, TArray(), Uvs, Colors, TArray(), false); @@ -169,6 +169,7 @@ void USpineSkeletonRendererComponent::Flush (int &Idx, TArray &Vertices Indices.SetNum(0); Uvs.SetNum(0); Colors.SetNum(0); + Colors2.SetNum(0); Idx++; } @@ -177,7 +178,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(spSkeleton* Skeleton) { TArray indices; TArray uvs; TArray colors; - TArray darkColors; + TArray darkColors; TArray attachmentVertices; attachmentVertices.SetNumUninitialized(2 * 1024); @@ -252,7 +253,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(spSkeleton* Skeleton) { } if (lastMaterial != material) { - Flush(meshSection, vertices, indices, uvs, colors, lastMaterial); + Flush(meshSection, vertices, indices, uvs, colors, darkColors, lastMaterial); lastMaterial = material; idx = 0; } @@ -264,8 +265,13 @@ void USpineSkeletonRendererComponent::UpdateMesh(spSkeleton* Skeleton) { uint8 b = static_cast(Skeleton->color.b * slot->color.b * attachmentColor.b * 255); uint8 a = static_cast(Skeleton->color.a * slot->color.a * attachmentColor.a * 255); + float dr = slot->darkColor ? slot->darkColor->r : 0.0f; + float dg = slot->darkColor ? slot->darkColor->g : 0.0f; + float db = slot->darkColor ? slot->darkColor->b : 0.0f; + for (int j = 0; j < numVertices << 1; j += 2) { colors.Add(FColor(r, g, b, a)); + darkColors.Add(FProcMeshTangent(dr, dg, db)); vertices.Add(FVector(attachmentVertices[j], depthOffset, attachmentVertices[j + 1])); uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1])); } @@ -278,7 +284,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(spSkeleton* Skeleton) { depthOffset += this->DepthOffset; } - Flush(meshSection, vertices, indices, uvs, colors, lastMaterial); + Flush(meshSection, vertices, indices, uvs, colors,darkColors, lastMaterial); } #undef LOCTEXT_NAMESPACE diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonRendererComponent.h b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonRendererComponent.h index 53ab642e9..c78ec0e62 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonRendererComponent.h +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonRendererComponent.h @@ -71,7 +71,7 @@ public: protected: void UpdateMesh (spSkeleton* Skeleton); - void Flush (int &Idx, TArray &Vertices, TArray &Indices, TArray &Uvs, TArray &Colors, UMaterialInstanceDynamic* Material); + void Flush (int &Idx, TArray &Vertices, TArray &Indices, TArray &Uvs, TArray &Colors, TArray &Colors2, UMaterialInstanceDynamic* Material); // Need to hold on to the dynamic instances, or the GC will kill us while updating them UPROPERTY()