From 2dd54c823c5820af86b6cb5cb1e09bd24e20a33e Mon Sep 17 00:00:00 2001 From: Benjamin Thomas Blodgett Date: Mon, 11 Apr 2022 21:15:55 -0400 Subject: [PATCH] Update to compile on UE 5.0 --- .../Private/VATEditorUtils.cpp | 38 ++++++++++--------- .../Private/VertexAnimToolsetEditor.cpp | 2 +- .../Private/VertexAnimUtils.cpp | 29 ++++++++------ VertexAnimToolset/VertexAnimToolset.uplugin | 2 +- 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VATEditorUtils.cpp b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VATEditorUtils.cpp index a76f6bd..9ed5e3c 100644 --- a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VATEditorUtils.cpp +++ b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VATEditorUtils.cpp @@ -37,7 +37,8 @@ #include "Developer/AssetTools/Public/IAssetTools.h" #include "Developer/AssetTools/Public/AssetToolsModule.h" -#include "Toolkits/AssetEditorManager.h" +#include "Toolkits/ToolkitManager.h" + #include "Dialogs/DlgPickAssetPath.h" #include "AssetRegistryModule.h" @@ -110,7 +111,7 @@ static void MapSkinVerts( UVertexAnimProfile* InProfile, const TArray & SkinVerts, TArray & UniqueVertsSourceID, TArray & OutUVSet_Vert) { - TArray UniqueVerts; + TArray UniqueVerts; TArray UniqueID; UniqueID.SetNumZeroed(SkinVerts.Num()); @@ -234,8 +235,8 @@ static void SkinnedMeshVATData( const int32 NumLODs = InSkinnedMeshComponent->GetNumLODs(); - const auto& RefSkeleton = InSkinnedMeshComponent->SkeletalMesh->RefSkeleton; - const auto& GlobalRefSkeleton = InSkinnedMeshComponent->SkeletalMesh->Skeleton->GetReferenceSkeleton(); + const auto& RefSkeleton = InSkinnedMeshComponent->SkeletalMesh->GetRefSkeleton(); + const auto& GlobalRefSkeleton = InSkinnedMeshComponent->SkeletalMesh->GetSkeleton()->GetReferenceSkeleton(); TArray GridUVs_Vert; TArray GridUVs_Bone; @@ -296,15 +297,15 @@ static void SkinnedMeshVATData( for (int32 o = 0; o < FinalVertices.Num(); o++) { - const FVector Pos = FinalVertices[o].Position; + const FVector3f Pos = FinalVertices[o].Position; float Lowest = MAX_FLT; int32 WinnerID = INDEX_NONE; for (int32 u = 0; u < UniqueSourceID.Num(); u++) { - const FVector TargetPos = AnimMeshFinalVertices[UniqueSourceID[u]].Position; + const FVector3f TargetPos = AnimMeshFinalVertices[UniqueSourceID[u]].Position; - const float Dist = FVector::Dist(Pos, TargetPos); + const float Dist = FVector3f::Dist(Pos, TargetPos); if (Dist < Lowest) { Lowest = Dist; @@ -499,7 +500,7 @@ void GatherAndBakeAllAnimVertData( FSkeletalMeshRenderData& SkeletalMeshRenderData = PreviewComponent->MeshObject->GetSkeletalMeshRenderData(); FSkeletalMeshLODRenderData& LODData = SkeletalMeshRenderData.LODRenderData[0]; const auto& ActiveBoneIndices = LODData.ActiveBoneIndices; - TArray RefToLocal; + TArray RefToLocal; // 3º Store Values // Vert Anim @@ -539,12 +540,13 @@ void GatherAndBakeAllAnimVertData( { const int32 IndexInZeroed = k; const int32 VertID = UniqueSourceIDs[k]; - const FVector Delta = FinalVerts[VertID].Position - RefPoseFinalVerts[VertID].Position; + const FVector3f Delta = FinalVerts[VertID].Position - RefPoseFinalVerts[VertID].Position; MaxValueOffset = FMath::Max(Delta.GetAbsMax(), MaxValueOffset); - ZeroedPos[IndexInZeroed] = Delta; + ZeroedPos[IndexInZeroed] = FVector4(Delta); - const FVector DeltaNormal = FinalVerts[VertID].TangentZ.ToFVector() - RefPoseFinalVerts[VertID].TangentZ.ToFVector(); - ZeroedNorm[IndexInZeroed] = DeltaNormal; + const FVector3f DeltaNormal = FinalVerts[VertID].TangentZ.ToFVector3f() - RefPoseFinalVerts[VertID].TangentZ.ToFVector3f(); + ZeroedNorm[IndexInZeroed] = FVector4(DeltaNormal); + } GridVertPos.Append(ZeroedPos); @@ -558,8 +560,8 @@ void GatherAndBakeAllAnimVertData( // Bone Anim if (Profile->Anims_Bone.Num()) { - const auto& RefSkeleton = PreviewComponent->SkeletalMesh->RefSkeleton; - const auto& GlobalRefSkeleton = PreviewComponent->SkeletalMesh->Skeleton->GetReferenceSkeleton(); + const auto& RefSkeleton = PreviewComponent->SkeletalMesh->GetRefSkeleton(); + const auto& GlobalRefSkeleton = PreviewComponent->SkeletalMesh->GetSkeleton()->GetReferenceSkeleton(); // Ref Pose in Row 0 { PreviewComponent->EnablePreview(true, NULL); @@ -610,12 +612,12 @@ void GatherAndBakeAllAnimVertData( { const int32 GlobalID = GlobalRefSkeleton.FindBoneIndex(RefSkeleton.GetBoneName(k)); - FVector Pos = RefToLocal[k].GetOrigin(); - ZeroedBonePos[GlobalID] = Pos; + FVector3f Pos = RefToLocal[k].GetOrigin(); + ZeroedBonePos[GlobalID] = FVector4(Pos); MaxValuePosBone = FMath::Max(MaxValuePosBone, Pos.GetAbsMax()); - FQuat Q = RefToLocal[k].ToQuat(); + FQuat Q = FQuat(RefToLocal[k].ToQuat()); QuatSave(Q); ZeroedBoneRot[GlobalID] = FVector4(Q.X, Q.Y, Q.Z, Q.W); } @@ -1109,7 +1111,7 @@ void FVATEditorUtils::UVChannelsToSkeletalMesh(USkeletalMesh* Skel, const int32 int32 SoftIndex = 0; Skel->GetImportedModel()->LODModels[LODIndex].GetSectionFromVertexIndex(i, SectionIndex, SoftIndex); - Skel->GetImportedModel()->LODModels[LODIndex].Sections[SectionIndex].SoftVertices[SoftIndex].UVs[UVChannelStart+j] = UVChannels[j][i]; + Skel->GetImportedModel()->LODModels[LODIndex].Sections[SectionIndex].SoftVertices[SoftIndex].UVs[UVChannelStart+j] = FVector2f(UVChannels[j][i]); } } } diff --git a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimToolsetEditor.cpp b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimToolsetEditor.cpp index 4024cdf..f1f916a 100644 --- a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimToolsetEditor.cpp +++ b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimToolsetEditor.cpp @@ -36,7 +36,7 @@ #include "Developer/AssetTools/Public/IAssetTools.h" #include "Developer/AssetTools/Public/AssetToolsModule.h" -#include "Toolkits/AssetEditorManager.h" +#include "Toolkits/ToolkitManager.h" #include "Dialogs/DlgPickAssetPath.h" #include "AssetRegistryModule.h" diff --git a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimUtils.cpp b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimUtils.cpp index 24214cc..30dd881 100644 --- a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimUtils.cpp +++ b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimUtils.cpp @@ -83,7 +83,7 @@ #include "Developer/AssetTools/Public/IAssetTools.h" #include "Developer/AssetTools/Public/AssetToolsModule.h" -#include "Toolkits/AssetEditorManager.h" +#include "Toolkits/ToolkitManager.h" #include "Dialogs/DlgPickAssetPath.h" #include "AssetRegistryModule.h" @@ -336,7 +336,8 @@ static void SkinnedMeshToRawMeshes(USkinnedMeshComponent* InSkinnedMeshComponent // Copy skinned vertex positions for (int32 VertIndex = 0; VertIndex < FinalVertices.Num(); ++VertIndex) { - RawMesh.VertexPositions.Add(InComponentToWorld.TransformPosition(FinalVertices[VertIndex].Position)); + FVector4d vert = InComponentToWorld.TransformPosition(FVector(FinalVertices[VertIndex].Position)); + RawMesh.VertexPositions.Add(FVector3f(vert.X, vert.Y, vert.Z)); } const uint32 NumTexCoords = FMath::Min(LODData.StaticVertexBuffers.StaticMeshVertexBuffer.GetNumTexCoords(), (uint32)MAX_MESH_TEXTURE_COORDS); @@ -362,9 +363,9 @@ static void SkinnedMeshToRawMeshes(USkinnedMeshComponent* InSkinnedMeshComponent const FVector4 UnpackedTangentZ = SkinnedVertex.TangentZ.ToFVector4(); const FVector TangentY = (TangentZ ^ TangentX).GetSafeNormal() * UnpackedTangentZ.W; - RawMesh.WedgeTangentX.Add(TangentX); - RawMesh.WedgeTangentY.Add(TangentY); - RawMesh.WedgeTangentZ.Add(TangentZ); + RawMesh.WedgeTangentX.Add(FVector3f(TangentX)); + RawMesh.WedgeTangentY.Add(FVector3f(TangentY)); + RawMesh.WedgeTangentZ.Add(FVector3f(TangentZ)); for (uint32 TexCoordIndex = 0; TexCoordIndex < MAX_MESH_TEXTURE_COORDS; TexCoordIndex++) { @@ -394,7 +395,7 @@ static void SkinnedMeshToRawMeshes(USkinnedMeshComponent* InSkinnedMeshComponent // use the remapping of material indices if there is a valid value if (SrcLODInfo.LODMaterialMap.IsValidIndex(SectionIndex) && SrcLODInfo.LODMaterialMap[SectionIndex] != INDEX_NONE) { - MaterialIndex = FMath::Clamp(SrcLODInfo.LODMaterialMap[SectionIndex], 0, InSkinnedMeshComponent->SkeletalMesh->Materials.Num()); + MaterialIndex = FMath::Clamp(SrcLODInfo.LODMaterialMap[SectionIndex], 0, InSkinnedMeshComponent->SkeletalMesh->GetMaterials().Num()); } // copy face info @@ -474,7 +475,7 @@ UStaticMesh* FVertexAnimUtils::ConvertMeshesToStaticMesh(const TArrayGetStaticMesh()->RenderData->LODResources.Num(), OverallMaxLODs); + OverallMaxLODs = FMath::Max(StaticMeshComponent->GetStaticMesh()->GetRenderData()->LODResources.Num(), OverallMaxLODs); } } @@ -546,7 +547,7 @@ UStaticMesh* FVertexAnimUtils::ConvertMeshesToStaticMesh(const TArray(Package, *MeshName, RF_Public | RF_Standalone); StaticMesh->InitResources(); - StaticMesh->LightingGuid = FGuid::NewGuid(); + StaticMesh->SetLightingGuid(FGuid::NewGuid()); // Determine which texture coordinate map should be used for storing/generating the lightmap UVs const uint32 LightMapIndex = FMath::Min(MaxInUseTextureCoordinate + 1, (uint32)MAX_MESH_TEXTURE_COORDS - 1); @@ -572,7 +573,11 @@ UStaticMesh* FVertexAnimUtils::ConvertMeshesToStaticMesh(const TArrayStaticMaterials.Add(FStaticMaterial(Material)); + //StaticMesh->GetStaticMaterials().Add(FStaticMaterial(Material)); // Can we do this? Unsure of the async implication. + + auto materials = StaticMesh->GetStaticMaterials(); + materials.Add(FStaticMaterial(Material)); + StaticMesh->SetStaticMaterials(materials); } //Set the Imported version before calling the build @@ -650,7 +655,7 @@ void FVertexAnimUtils::VATUVsToStaticMeshLODs(UStaticMesh* StaticMesh, const int for (int32 WedgeIndex = 0; WedgeIndex < Mesh.WedgeIndices.Num(); ++WedgeIndex) { int32 VertID = Mesh.WedgeIndices[WedgeIndex]; - FVector Position = Mesh.VertexPositions[VertID]; + FVector Position = FVector(Mesh.VertexPositions[VertID]); for (uint32 TexCoordIndex = 0; TexCoordIndex < MAX_MESH_TEXTURE_COORDS; TexCoordIndex++) { @@ -662,7 +667,7 @@ void FVertexAnimUtils::VATUVsToStaticMeshLODs(UStaticMesh* StaticMesh, const int if (Mesh.WedgeTexCoords[TexCoordIndex].Num() != Mesh.WedgeIndices.Num()) Mesh.WedgeTexCoords[TexCoordIndex].SetNum(Mesh.WedgeIndices.Num()); - Mesh.WedgeTexCoords[TexCoordIndex][WedgeIndex] = UVs[PaintingMeshLODIndex][VertID]; + Mesh.WedgeTexCoords[TexCoordIndex][WedgeIndex] = FVector2f(UVs[PaintingMeshLODIndex][VertID]); } else if(TexCoordIndex >= NumUVChannels) { @@ -725,7 +730,7 @@ void FVertexAnimUtils::VATColorsToStaticMeshLODs(UStaticMesh* StaticMesh, const for (int32 WedgeIndex = 0; WedgeIndex < Mesh.WedgeIndices.Num(); ++WedgeIndex) { int32 VertID = Mesh.WedgeIndices[WedgeIndex]; - FVector Position = Mesh.VertexPositions[VertID]; + FVector Position = FVector(Mesh.VertexPositions[VertID]); Mesh.WedgeColors[WedgeIndex] = Colors[PaintingMeshLODIndex][VertID]; } diff --git a/VertexAnimToolset/VertexAnimToolset.uplugin b/VertexAnimToolset/VertexAnimToolset.uplugin index 41576e3..e49b0bc 100644 --- a/VertexAnimToolset/VertexAnimToolset.uplugin +++ b/VertexAnimToolset/VertexAnimToolset.uplugin @@ -10,7 +10,7 @@ "DocsURL": "https://github.com/Rexocrates/Vertex_Anim_Toolset/blob/main/Vertex%20Anim%20Toolset%20Documentation.pdf", "MarketplaceURL": "com.epicgames.launcher://ue/marketplace/content/d998b22372a44975b312e85cf663bbab", "SupportURL": "https://github.com/Rexocrates/Vertex_Anim_Toolset/issues", - "EngineVersion": "4.26.0", + "EngineVersion": "5.0.0", "CanContainContent": true, "Installed": true, "Modules": [