diff --git a/VertexAnimToolset/Source/VertexAnimToolset/Private/VertexAnimProfile.cpp b/VertexAnimToolset/Source/VertexAnimToolset/Private/VertexAnimProfile.cpp index 2df540f..dfc10a2 100644 --- a/VertexAnimToolset/Source/VertexAnimToolset/Private/VertexAnimProfile.cpp +++ b/VertexAnimToolset/Source/VertexAnimToolset/Private/VertexAnimProfile.cpp @@ -2,14 +2,6 @@ #include "VertexAnimProfile.h" -#include "UObject/ObjectMacros.h" -#include "Runtime/Engine/Classes/Engine/CanvasRenderTarget2D.h" - -#include "Runtime/Engine/Classes/Kismet/KismetRenderingLibrary.h" - -#include "Rendering/SkeletalMeshModel.h" - - int32 UVertexAnimProfile::CalcTotalNumOfFrames_Vert() const { int32 Out = 0; diff --git a/VertexAnimToolset/Source/VertexAnimToolset/Private/VertexAnimToolset.cpp b/VertexAnimToolset/Source/VertexAnimToolset/Private/VertexAnimToolset.cpp index 01c7046..0332be5 100644 --- a/VertexAnimToolset/Source/VertexAnimToolset/Private/VertexAnimToolset.cpp +++ b/VertexAnimToolset/Source/VertexAnimToolset/Private/VertexAnimToolset.cpp @@ -3,9 +3,6 @@ #include "VertexAnimToolset.h" //-------------------------------------- -#include "Interfaces/IPluginManager.h" -#include "Misc/Paths.h" -#include "ShaderCore.h" #define LOCTEXT_NAMESPACE "FVertexAnimToolsetModule" diff --git a/VertexAnimToolset/Source/VertexAnimToolset/Public/VertexAnimToolset.h b/VertexAnimToolset/Source/VertexAnimToolset/Public/VertexAnimToolset.h index 365e1f1..c47da5e 100644 --- a/VertexAnimToolset/Source/VertexAnimToolset/Public/VertexAnimToolset.h +++ b/VertexAnimToolset/Source/VertexAnimToolset/Public/VertexAnimToolset.h @@ -5,7 +5,6 @@ #include "CoreMinimal.h" #include "Modules/ModuleInterface.h" -#include "Modules/ModuleManager.h" class FVertexAnimToolsetModule : public IModuleInterface { diff --git a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VATEditorUtils.cpp b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VATEditorUtils.cpp index a76f6bd..b7f9eee 100644 --- a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VATEditorUtils.cpp +++ b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VATEditorUtils.cpp @@ -2,106 +2,29 @@ #include "VATEditorUtils.h" - -#include "IPersonaToolkit.h" -#include "Rendering/SkeletalMeshModel.h" -#include "Rendering/SkeletalMeshRenderData.h" - +#include "AnimationRuntime.h" +#include "AssetRegistryModule.h" +#include "RenderingThread.h" +#include "SkeletalRenderPublic.h" +#include "StaticMeshResources.h" +#include "VertexAnimProfile.h" #include "Animation/DebugSkelMeshComponent.h" - - -#include "Textures/SlateIcon.h" -#include "Styling/SlateTypes.h" -#include "Framework/Commands/UIAction.h" -#include "Framework/Commands/UICommandList.h" -#include "Framework/MultiBox/MultiBoxExtender.h" -#include "Framework/MultiBox/MultiBoxBuilder.h" - +#include "Developer/AssetTools/Public/AssetToolsModule.h" +#include "Developer/AssetTools/Public/IAssetTools.h" +#include "Dialogs/DlgPickAssetPath.h" +#include "Engine/SkeletalMesh.h" #include "Engine/StaticMesh.h" -#include "Materials/Material.h" -#include "Materials/MaterialInstanceDynamic.h" - -#include "RawMesh.h" -#include "StaticMeshResources.h" -#include "MeshBuild.h" - +#include "Misc/MessageDialog.h" #include "Rendering/SkeletalMeshModel.h" #include "Rendering/SkeletalMeshRenderData.h" - -#include "Engine/SkeletalMesh.h" -#include "SkeletalRenderPublic.h" #include "Runtime/Engine/Private/SkeletalRenderCPUSkin.h" -#include "Animation/MorphTarget.h" - -#include "Developer/AssetTools/Public/IAssetTools.h" -#include "Developer/AssetTools/Public/AssetToolsModule.h" - -#include "Toolkits/AssetEditorManager.h" -#include "Dialogs/DlgPickAssetPath.h" -#include "AssetRegistryModule.h" - -#include "VertexAnimProfile.h" - - -#include "Framework/Notifications/NotificationManager.h" -#include "Widgets/Notifications/SNotificationList.h" - -#include "Engine.h" - -#include "Misc/FeedbackContext.h" -#include "Misc/MessageDialog.h" - -#include "IPersonaPreviewScene.h" -#include "AssetViewerSettings.h" -#include "RenderingThread.h" - -#include "Components/PoseableMeshComponent.h" - -#include "AnimationRuntime.h" - //-------------------------------------- -#include "Interfaces/IPluginManager.h" -#include "Misc/Paths.h" -#include "ShaderCore.h" - -#include "VertexAnimUtils.h" - -#include "Animation/AnimSequence.h" - -#include "Kismet/KismetRenderingLibrary.h" - +#include "MeshDescription.h" #include "PackageTools.h" - -#include "Animation/AnimSequence.h" - -#include "Rendering/SkinWeightVertexBuffer.h" - - -#include "Misc/App.h" -#include "RenderingThread.h" -#include "GameFramework/PlayerController.h" -#include "ContentStreaming.h" -#include "DrawDebugHelpers.h" -#include "UnrealEngine.h" -#include "SkeletalRenderPublic.h" -//#include "SkeletalRenderCPUSkin.h" -//#include "SkeletalRenderGPUSkin.h" -//#include "SkeletalRenderStatic.h" -#include "Animation/AnimStats.h" -#include "Engine/SkeletalMeshSocket.h" -#include "PhysicsEngine/PhysicsAsset.h" -#include "EngineGlobals.h" -#include "PrimitiveSceneProxy.h" -#include "Engine/CollisionProfile.h" -#include "Rendering/SkinWeightVertexBuffer.h" -#include "SkeletalMeshTypes.h" -#include "Animation/MorphTarget.h" -#include "AnimationRuntime.h" - +#include "VertexAnimUtils.h" #include "Animation/AnimSingleNodeInstance.h" - -#include "MeshDescription.h" +#include "Rendering/SkinWeightVertexBuffer.h" #define LOCTEXT_NAMESPACE "VATEditorUtils" @@ -110,7 +33,7 @@ static void MapSkinVerts( UVertexAnimProfile* InProfile, const TArray & SkinVerts, TArray & UniqueVertsSourceID, TArray & OutUVSet_Vert) { - TArray UniqueVerts; + TArray UniqueVerts; TArray UniqueID; UniqueID.SetNumZeroed(SkinVerts.Num()); @@ -143,21 +66,20 @@ static void MapSkinVerts( if (InProfile->AutoSize) { - int32 XSize = FMath::Min(InProfile->MaxWidth, (int32)FMath::RoundUpToPowerOfTwo(UniqueVerts.Num())); - InProfile->RowsPerFrame_Vert = FMath::CeilToInt((float)(UniqueVerts.Num()) / (float)(XSize)); + const int32 XSize = FMath::Min(InProfile->MaxWidth, static_cast(FMath::RoundUpToPowerOfTwo(UniqueVerts.Num()))); + InProfile->RowsPerFrame_Vert = FMath::CeilToInt(static_cast(UniqueVerts.Num()) / static_cast(XSize)); InProfile->OverrideSize_Vert = FIntPoint( XSize, FMath::RoundUpToPowerOfTwo(InProfile->CalcTotalRequiredHeight_Vert())); } else { - InProfile->RowsPerFrame_Vert = //FMath::CeilToInt((float)(UniqueVerts.Num()) / (float)(InProfile->OverrideSize.X)); - FMath::RoundUpToPowerOfTwo((float)(UniqueVerts.Num()) / (float)(InProfile->OverrideSize_Vert.X)); + InProfile->RowsPerFrame_Vert = FMath::RoundUpToPowerOfTwo(static_cast(UniqueVerts.Num()) / static_cast(InProfile->OverrideSize_Vert.X)); } const float XStep = 1.f / InProfile->OverrideSize_Vert.X; const float YStep = 1.f / InProfile->OverrideSize_Vert.Y; - const FVector2D HalfStep = FVector2D(XStep, YStep) / 2; + TArray UniqueMappedUVs; UniqueMappedUVs.SetNum(UniqueVerts.Num()); @@ -184,7 +106,7 @@ static void MapActiveBones( { if (InProfile->AutoSize) { - int32 XSize = FMath::Clamp((int32)FMath::RoundUpToPowerOfTwo(NumBones), 8, InProfile->MaxWidth); + const int32 XSize = FMath::Clamp(static_cast(FMath::RoundUpToPowerOfTwo(NumBones)), 8, InProfile->MaxWidth); InProfile->OverrideSize_Bone = FIntPoint( XSize, @@ -198,18 +120,11 @@ static void MapActiveBones( for (int32 i = 0; i < NumBones; i++) { - if (true) - { - // I SWITCHED THESE to have the UVs lined horizontally. - const int32 GridX = i % InProfile->OverrideSize_Bone.X; - const int32 GridY = i / InProfile->OverrideSize_Bone.X; - const FVector2D GridUV = FVector2D(GridX * XStep, GridY * YStep); - UniqueMappedUVs[i] = GridUV; - } - else - { - UniqueMappedUVs[i] = FVector2D(); - } + // I SWITCHED THESE to have the UVs lined horizontally. + const int32 GridX = i % InProfile->OverrideSize_Bone.X; + const int32 GridY = i / InProfile->OverrideSize_Bone.X; + const FVector2D GridUV = FVector2D(GridX * XStep, GridY * YStep); + UniqueMappedUVs[i] = GridUV; } OutUVSet_Bone = UniqueMappedUVs; @@ -234,8 +149,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; @@ -270,8 +185,6 @@ static void SkinnedMeshVATData( { int32 LODIndexRead = FMath::Min(OverallLODIndex, NumLODs - 1); - FSkeletalMeshLODInfo& SrcLODInfo = *(InSkinnedMeshComponent->SkeletalMesh->GetLODInfo(LODIndexRead)); - // Get the CPU skinned verts for this LOD, WAIT, if it changes LOD on each loop, does that not mean it changes?? TArray FinalVertices; InSkinnedMeshComponent->GetCPUSkinnedVertices(FinalVertices, LODIndexRead); @@ -296,15 +209,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; @@ -323,12 +236,10 @@ static void SkinnedMeshVATData( FSkeletalMeshLODRenderData& LODData = SkeletalMeshRenderData.LODRenderData[LODIndexRead]; { - const FSkinWeightVertexBuffer& SkinWeightVertexBuffer = *LODData.GetSkinWeightVertexBuffer(); - auto SkinData = LODData.GetSkinWeightVertexBuffer(); check(SkinData->GetNumVertices() == FinalVertices.Num()); - for (int32 s = 0; s < (int32)SkinData->GetNumVertices(); s++) + for (int32 s = 0; s < static_cast(SkinData->GetNumVertices()); s++) { int32 SectionIndex; int32 VertIndex; @@ -352,15 +263,15 @@ static void SkinnedMeshVATData( }; const float Sum = - ((float)InfluenceWeights[0] / 255.f) + ((float)InfluenceWeights[1] / 255.f) - + ((float)InfluenceWeights[2] / 255.f) + ((float)InfluenceWeights[3] / 255.f); + (static_cast(InfluenceWeights[0]) / 255.f) + (static_cast(InfluenceWeights[1]) / 255.f) + + (static_cast(InfluenceWeights[2]) / 255.f) + (static_cast(InfluenceWeights[3]) / 255.f); const float Rest = 1.f - Sum; FLinearColor W = FLinearColor( - ((float)InfluenceWeights[0] / 255.f) + Rest, - ((float)InfluenceWeights[1] / 255.f), - ((float)InfluenceWeights[2] / 255.f), - ((float)InfluenceWeights[3] / 255.f)); + (static_cast(InfluenceWeights[0]) / 255.f) + Rest, + (static_cast(InfluenceWeights[1]) / 255.f), + (static_cast(InfluenceWeights[2]) / 255.f), + (static_cast(InfluenceWeights[3]) / 255.f)); thisLODSkinWeightColor[s] = W.ToFColor(false); @@ -436,7 +347,7 @@ void GatherAndBakeAllAnimVertData( constexpr bool bRecreateRenderStateImmediately = true; // 1º switch to CPU skinning { - const int32 InLODIndex = 0; + constexpr int32 InLODIndex = 0; { if (USkinnedMeshComponent* MasterPoseComponentPtr = PreviewComponent->MasterPoseComponent.Get()) { @@ -462,7 +373,7 @@ void GatherAndBakeAllAnimVertData( } // 2º Make Sure it in ref pose - PreviewComponent->EnablePreview(true, NULL); + PreviewComponent->EnablePreview(true, nullptr); PreviewComponent->RefreshBoneTransforms(nullptr); PreviewComponent->ClearMotionVector(); FlushRenderingCommands(); @@ -485,21 +396,18 @@ void GatherAndBakeAllAnimVertData( - TArray ZeroedPos; + TArray ZeroedPos; ZeroedPos.SetNumZeroed(PerFrameArrayNum_Vert); - TArray ZeroedNorm; + TArray ZeroedNorm; ZeroedNorm.SetNumZeroed(PerFrameArrayNum_Vert); // YOW, need different sizes for vert and bone textures. - TArray ZeroedBonePos; + TArray ZeroedBonePos; ZeroedBonePos.SetNumZeroed(PerFrameArrayNum_Bone); - TArray ZeroedBoneRot; + TArray ZeroedBoneRot; ZeroedBoneRot.SetNumZeroed(PerFrameArrayNum_Bone); - 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,11 +447,11 @@ 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; - const FVector DeltaNormal = FinalVerts[VertID].TangentZ.ToFVector() - RefPoseFinalVerts[VertID].TangentZ.ToFVector(); + const FVector3f DeltaNormal = FinalVerts[VertID].TangentZ.ToFVector3f() - RefPoseFinalVerts[VertID].TangentZ.ToFVector3f(); ZeroedNorm[IndexInZeroed] = DeltaNormal; } @@ -558,11 +466,11 @@ 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); + PreviewComponent->EnablePreview(true, nullptr); PreviewComponent->RefreshBoneTransforms(nullptr); PreviewComponent->ClearMotionVector(); FlushRenderingCommands(); @@ -574,9 +482,8 @@ void GatherAndBakeAllAnimVertData( FQuat RefQuat = RefTM.GetRotation(); QuatSave(RefQuat); const int32 GlobalID = GlobalRefSkeleton.FindBoneIndex(RefSkeleton.GetBoneName(B)); - ZeroedBonePos[GlobalID] = RefTM.GetLocation(); - ZeroedBoneRot[GlobalID] = FVector4(RefQuat.X, RefQuat.Y, RefQuat.Z, RefQuat.W); - //UE_LOG(LogUnrealMath, Warning, TEXT("%s"), *ZeroedBonePos[B].ToString()); + ZeroedBonePos[GlobalID] = static_cast(RefTM.GetLocation()); + ZeroedBoneRot[GlobalID] = FVector4f(RefQuat.X, RefQuat.Y, RefQuat.Z, RefQuat.W); } GridBonePos.Append(ZeroedBonePos); GridBoneRot.Append(ZeroedBoneRot); @@ -610,14 +517,14 @@ void GatherAndBakeAllAnimVertData( { const int32 GlobalID = GlobalRefSkeleton.FindBoneIndex(RefSkeleton.GetBoneName(k)); - FVector Pos = RefToLocal[k].GetOrigin(); + FVector3f Pos = RefToLocal[k].GetOrigin(); ZeroedBonePos[GlobalID] = Pos; MaxValuePosBone = FMath::Max(MaxValuePosBone, Pos.GetAbsMax()); - FQuat Q = RefToLocal[k].ToQuat(); + FQuat Q = static_cast(RefToLocal[k].ToQuat()); QuatSave(Q); - ZeroedBoneRot[GlobalID] = FVector4(Q.X, Q.Y, Q.Z, Q.W); + ZeroedBoneRot[GlobalID] = FVector4f(Q.X, Q.Y, Q.Z, Q.W); } } @@ -629,7 +536,7 @@ void GatherAndBakeAllAnimVertData( // 4º Put Mesh back into ref pose { - PreviewComponent->EnablePreview(true, NULL); + PreviewComponent->EnablePreview(true, nullptr); PreviewComponent->RefreshBoneTransforms(nullptr); PreviewComponent->ClearMotionVector(); @@ -647,7 +554,10 @@ void GatherAndBakeAllAnimVertData( Profile->MaxValueOffset_Vert = MaxValueOffset; Profile->MaxValuePosition_Bone = MaxValuePosBone; - Profile->MarkPackageDirty(); + if (!Profile->MarkPackageDirty()) + { + UE_LOG(LogTemp, Warning, TEXT("Could not save profile")); + } OutGridVertPos = GridVertPos; OutGridVertNormal = GridVertNormal; @@ -703,29 +613,31 @@ static void EncodeData_Quat(const bool HD, const TArray & VectorData, if (FMath::Abs(VectorValue[0]) > Max) { BigComp = 0; - Bit0 = 0, Bit1 = 0; + Bit0 = Bit1 = false; Max = FMath::Abs(VectorValue[0]); WinnerValue = FVector(VectorValue[1], VectorValue[2], VectorValue[3]); } if (FMath::Abs(VectorValue[1]) > Max) { BigComp = 1; - Bit0 = 0, Bit1 = 1; + Bit0 = false; + Bit1 = true; Max = FMath::Abs(VectorValue[1]); WinnerValue = FVector(VectorValue[0], VectorValue[2], VectorValue[3]); } if (FMath::Abs(VectorValue[2]) > Max) { BigComp = 2; - Bit0 = 1, Bit1 = 0; + Bit0 = true; + Bit1 = false; Max = FMath::Abs(VectorValue[2]); WinnerValue = FVector(VectorValue[0], VectorValue[1], VectorValue[3]); } if (FMath::Abs(VectorValue[3]) > Max) { BigComp = 3; - Bit0 = 1, Bit1 = 1; - Max = FMath::Abs(VectorValue[3]); + Bit0 = Bit1 = true; + WinnerValue = FVector(VectorValue[0], VectorValue[1], VectorValue[2]); } @@ -736,53 +648,26 @@ static void EncodeData_Quat(const bool HD, const TArray & VectorData, const float MaxDim = WinnerValue.GetAbsMax(); // for now no bit based encoding, just have quats be always HDR (double precission). - if (false) + if (MaxDim > 0.f) { - /* - if (MaxDim > 0.f) - { - FVector4 Encoded = FVertexAnimUtils::BitEncodeVecId_HD(WinnerValue, 1.0, BigComp); - if(HD) - Data[i] = FLinearColor(Encoded); - else - Data[i] = FLinearColor(FVertexAnimUtils::BitEncodeVecId(WinnerValue, 1.0, BigComp)); - - UE_LOG(LogUnrealMath, Warning, TEXT("Vec Value %s || Id %i || Result Encode %s"), - *WinnerValue.ToString(), BigComp, *Encoded.ToString()); - } - else - { - Data[i] = FLinearColor(0, 0, 0, 1); - }*/ + const float R = FMath::Max(0.001f, FVertexAnimUtils::EncodeFloat(WinnerValue.X, MaxDim)) * (Bit0 ? 1.0 : -1.0); + const float G = FMath::Max(0.001f, FVertexAnimUtils::EncodeFloat(WinnerValue.Y, MaxDim)) * (Bit1 ? 1.0 : -1.0); + const float B = WinnerValue.Z / MaxDim; + const float A = -1.0 + ((MaxDim / 1.0) * 2.0);// + + Data[i] = FLinearColor(R, G, B, A); } else { - if (MaxDim > 0.f) - { - - float R = FMath::Max(0.001f, FVertexAnimUtils::EncodeFloat(WinnerValue.X, MaxDim)) * (Bit0 ? 1.0 : -1.0); - //R = FVertexAnimUtils::EncodeFloat(R * (Bit0 ? 1.0 : -1.0), 1.0); - - float G = FMath::Max(0.001f, FVertexAnimUtils::EncodeFloat(WinnerValue.Y, MaxDim)) * (Bit1 ? 1.0 : -1.0); - //G = FVertexAnimUtils::EncodeFloat(G * (Bit1 ? 1.0 : -1.0), 1.0); - - float B = WinnerValue.Z / MaxDim;// FVertexAnimUtils::EncodeFloat(WinnerValue.Z, MaxDim); - - float A = -1.0 + ((MaxDim / 1.0) * 2.0);// - - Data[i] = FLinearColor(R, G, B, A); - } - else - { - Data[i] = FLinearColor(0, 0, 0, 1); - } + Data[i] = FLinearColor(0, 0, 0, 1); } + } } static UTexture2D* SetTexture2( - UWorld* World, const FString PackagePath, const FString Name, - UTexture2D* Texture, + UWorld* World, const FString PackagePath, const FString Name, + const UTexture2D* Texture, const int32 InSizeX, const int32 InSizeY, const TArray & Data, //const TArray & VectorData, EObjectFlags InObjectFlags) @@ -790,15 +675,14 @@ static UTexture2D* SetTexture2( UTexture2D* NewTexture; { - - if (Texture != NULL) + if (Texture != nullptr) { NewTexture = NewObject(Texture->GetOuter(), FName(*Texture->GetName()), InObjectFlags); } else { - UPackage* Package = CreatePackage(NULL, *(PackagePath + Name)); + UPackage* Package = CreatePackage(*(PackagePath + Name)); check(Package); Package->FullyLoad(); @@ -810,7 +694,7 @@ static UTexture2D* SetTexture2( checkf(NewTexture, TEXT("%s"), *Name); NewTexture->Source.Init(InSizeX, InSizeY, /*NumSlices=*/ 1, /*NumMips=*/ 1, TSF_RGBA16F); - uint32* TextureData = (uint32*)NewTexture->Source.LockMip(0); + uint32* TextureData = reinterpret_cast(NewTexture->Source.LockMip(0)); const int32 TextureDataSize = NewTexture->Source.CalcMipSize(0); FMemory::Memcpy(TextureData, Data.GetData(), TextureDataSize); // this did not blow up @@ -819,7 +703,10 @@ static UTexture2D* SetTexture2( NewTexture->PostEditChange(); - NewTexture->MarkPackageDirty(); + if (!NewTexture->MarkPackageDirty()) + { + UE_LOG(LogTemp, Warning, TEXT("Could not save the new texture")); + } } return NewTexture; @@ -827,46 +714,35 @@ static UTexture2D* SetTexture2( float FVATEditorUtils::PackBits(const uint32& bit) { - /* - int32 f16 = bit; - f16 += 1024; - int32 sign = (f16 & (0x8000)) << 16; - int32 expVar = ((((f16 >> 10) & 0x1f) - 15 + 127) << 23); - int32 mant = (f16 & 0x3ff) << 13; - f16 = (sign | expVar) | mant; - return f16; - */ - - uint32 f16 = static_cast(bit); + uint32 f16 = bit; f16 += 1024; - uint32 sign = (f16 & (0x8000)) << 16; - uint32 expVar = //(f16 & 0x7fff) == 0 ? 0 : + const uint32 sign = (f16 & (0x8000)) << 16; + const uint32 expVar = //(f16 & 0x7fff) == 0 ? 0 : (/*shift*/((/*bit. and*/ (/*bit.shift*/ f16 >> 10) & 0x1f) - 15 + 127) << 23); - uint32 mant = (f16 & 0x3ff) << 13; + const uint32 mant = (f16 & 0x3ff) << 13; f16 = /*bit. or*/ (/*bit. or*/ sign | expVar) | mant; - //return f16; - //UE_LOG(LogUnrealMath, Warning, TEXT("HH %i || %i"), bit, f16); // printing 0 - //return f16;// asfloat_O(f16); + return static_cast(f16); } int FVATEditorUtils::UnPackBits(const float N) { - uint32 uRes32 = static_cast(N);// asuint(N); + const uint32 uRes32 = static_cast(N);// asuint(N); const uint32 sign2 = ((uRes32 >> 16) & 0x8000); - const uint32 exp2 = ((((const int)((uRes32 >> 23) & 0xff)) - 127 + 15) << 10); + const uint32 exp2 = ((static_cast((uRes32 >> 23) & 0xff) - 127 + 15) << 10); const uint32 mant2 = ((uRes32 >> 13) & 0x3ff); const uint32 bits = (sign2 | exp2 | mant2); const uint32 result = bits - 1024; - return float(result); + + return static_cast(result); } void FVATEditorUtils::DoBakeProcess(UDebugSkelMeshComponent* PreviewComponent) { PreviewComponent->GlobalAnimRateScale = 0.f; - UVertexAnimProfile* Profile = NULL; + UVertexAnimProfile* Profile = nullptr; FString MeshName; FString PackageName; @@ -905,8 +781,8 @@ void FVATEditorUtils::DoBakeProcess(UDebugSkelMeshComponent* PreviewComponent) } - bool DoAnimBake = (Profile != NULL) && !bOnlyCreateStaticMesh; - bool DoStaticMesh = (Profile != NULL); + bool DoAnimBake = (Profile != nullptr) && !bOnlyCreateStaticMesh; + bool DoStaticMesh = (Profile != nullptr); if ((!DoAnimBake) && (!DoStaticMesh)) return; @@ -973,7 +849,10 @@ void FVATEditorUtils::DoBakeProcess(UDebugSkelMeshComponent* PreviewComponent) } Profile->StaticMesh = StaticMesh; - Profile->MarkPackageDirty(); + if (!Profile->MarkPackageDirty()) + { + UE_LOG(LogTemp, Warning, TEXT("Could not save Profile")); + } } @@ -1014,9 +893,11 @@ void FVATEditorUtils::DoBakeProcess(UDebugSkelMeshComponent* PreviewComponent) Profile->NormalsTexture->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap; Profile->NormalsTexture->SRGB = false; Profile->NormalsTexture->Modify(); - Profile->NormalsTexture->MarkPackageDirty(); - Profile->NormalsTexture->PostEditChange(); - Profile->NormalsTexture->UpdateResource(); + if (Profile->NormalsTexture->MarkPackageDirty()) + { + Profile->NormalsTexture->PostEditChange(); + Profile->NormalsTexture->UpdateResource(); + } } @@ -1034,9 +915,11 @@ void FVATEditorUtils::DoBakeProcess(UDebugSkelMeshComponent* PreviewComponent) Profile->OffsetsTexture->CompressionSettings = TextureCompressionSettings::TC_HDR; Profile->OffsetsTexture->SRGB = false; Profile->OffsetsTexture->Modify(); - Profile->OffsetsTexture->MarkPackageDirty(); - Profile->OffsetsTexture->PostEditChange(); - Profile->OffsetsTexture->UpdateResource(); + if (Profile->OffsetsTexture->MarkPackageDirty()) + { + Profile->OffsetsTexture->PostEditChange(); + Profile->OffsetsTexture->UpdateResource(); + } } } @@ -1062,9 +945,11 @@ void FVATEditorUtils::DoBakeProcess(UDebugSkelMeshComponent* PreviewComponent) Profile->BoneRotTexture->CompressionSettings = TextureCompressionSettings::TC_HDR; Profile->BoneRotTexture->SRGB = false; Profile->BoneRotTexture->Modify(); - Profile->BoneRotTexture->MarkPackageDirty(); - Profile->BoneRotTexture->PostEditChange(); - Profile->BoneRotTexture->UpdateResource(); + if (Profile->BoneRotTexture->MarkPackageDirty()) + { + Profile->BoneRotTexture->PostEditChange(); + Profile->BoneRotTexture->UpdateResource(); + } } { @@ -1082,9 +967,11 @@ void FVATEditorUtils::DoBakeProcess(UDebugSkelMeshComponent* PreviewComponent) Profile->BonePosTexture->SRGB = false; Profile->BonePosTexture->Modify(); - Profile->BonePosTexture->MarkPackageDirty(); - Profile->BonePosTexture->PostEditChange(); - Profile->BonePosTexture->UpdateResource(); + if (Profile->BonePosTexture->MarkPackageDirty()) + { + Profile->BonePosTexture->PostEditChange(); + Profile->BonePosTexture->UpdateResource(); + } } } @@ -1092,10 +979,10 @@ void FVATEditorUtils::DoBakeProcess(UDebugSkelMeshComponent* PreviewComponent) } } -void FVATEditorUtils::UVChannelsToSkeletalMesh(USkeletalMesh* Skel, const int32 LODIndex, const int32 UVChannelStart, TArray>& UVChannels) +void FVATEditorUtils::UVChannelsToSkeletalMesh(const USkeletalMesh* Skel, const int32 LODIndex, const int32 UVChannelStart, TArray>& UVChannels) { check((UVChannelStart + UVChannels.Num()) <= MAX_TEXCOORDS); - check(UVChannelStart < (int32)Skel->GetImportedModel()->LODModels[LODIndex].NumTexCoords); + check(UVChannelStart < static_cast(Skel->GetImportedModel()->LODModels[LODIndex].NumTexCoords)); Skel->GetImportedModel()->LODModels[LODIndex].NumTexCoords = UVChannelStart + UVChannels.Num(); @@ -1109,7 +996,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] = static_cast(UVChannels[j][i]); } } } @@ -1168,9 +1055,8 @@ void FVATEditorUtils::IntoIslands(const TArray& IndexBuffer, const TArray TArray PerTriIsland; PerTriIsland.Init(INDEX_NONE, NewIndexBuffer.Num() / 3); - - int32 NumTris = NewIndexBuffer.Num() / 3; + const int32 NumTris = NewIndexBuffer.Num() / 3; int32 NumIslands = 0; while (true) @@ -1191,7 +1077,7 @@ void FVATEditorUtils::IntoIslands(const TArray& IndexBuffer, const TArray PerTriIsland[Winner] = NumIslands; NumIslands++; - TArray CurrNeigs = { Winner }; + TArray CurrNeigs = { Winner }; while (true) { @@ -1236,13 +1122,13 @@ void FVATEditorUtils::ClosestUVPivotAssign( for (int32 i = 0; i < IndexBuffer.Num(); i+=3) { - FVector2D A = UVs[IndexBuffer[i]]; - FVector2D B = UVs[IndexBuffer[i+1]]; - FVector2D C = UVs[IndexBuffer[i+2]]; + const FVector2D A = UVs[IndexBuffer[i]]; + const FVector2D B = UVs[IndexBuffer[i+1]]; + const FVector2D C = UVs[IndexBuffer[i+2]]; - FVector VA = FVector(A.X, A.Y, 0.0); - FVector VB = FVector(B.X, B.Y, 0.0); - FVector VC = FVector(C.X, C.Y, 0.0); + const FVector VA = FVector(A.X, A.Y, 0.0); + const FVector VB = FVector(B.X, B.Y, 0.0); + const FVector VC = FVector(C.X, C.Y, 0.0); for (int32 j = 0; j < PivotUVPos.Num(); j++) { @@ -1258,7 +1144,7 @@ void FVATEditorUtils::ClosestUVPivotAssign( for (int32 i = 0; i < IndexBuffer.Num(); i += 3) { - int32 IslandID = IslandIDs[i / 3]; + const int32 IslandID = IslandIDs[i / 3]; FVector2D A = UVs[IndexBuffer[i]]; FVector2D B = UVs[IndexBuffer[i + 1]]; FVector2D C = UVs[IndexBuffer[i + 2]]; @@ -1270,9 +1156,9 @@ void FVATEditorUtils::ClosestUVPivotAssign( { if (PerPivotIsland[j] == IslandID) { - float DA = FVector2D::Distance(A, PivotUVPos[j]); - float DB = FVector2D::Distance(B, PivotUVPos[j]); - float DC = FVector2D::Distance(C, PivotUVPos[j]); + const float DA = FVector2D::Distance(A, PivotUVPos[j]); + const float DB = FVector2D::Distance(B, PivotUVPos[j]); + const float DC = FVector2D::Distance(C, PivotUVPos[j]); if (DA < LA) { diff --git a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimToolsetEditor.cpp b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimToolsetEditor.cpp index 4024cdf..b19974f 100644 --- a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimToolsetEditor.cpp +++ b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimToolsetEditor.cpp @@ -1,93 +1,30 @@ // Copyright 2019-2021 Rexocrates. All Rights Reserved. #include "VertexAnimToolsetEditor.h" - +#include "AnimationRuntime.h" +#include "AssetRegistryModule.h" +#include "IPersonaPreviewScene.h" #include "IPersonaToolkit.h" -#include "Rendering/SkeletalMeshModel.h" -#include "Rendering/SkeletalMeshRenderData.h" - #include "Animation/DebugSkelMeshComponent.h" - - -#include "Textures/SlateIcon.h" -#include "Styling/SlateTypes.h" +#include "Developer/AssetTools/Public/AssetToolsModule.h" #include "Framework/Commands/UIAction.h" #include "Framework/Commands/UICommandList.h" -#include "Framework/MultiBox/MultiBoxExtender.h" #include "Framework/MultiBox/MultiBoxBuilder.h" - -#include "Engine/StaticMesh.h" -#include "Materials/Material.h" -#include "Materials/MaterialInstanceDynamic.h" - -#include "RawMesh.h" -#include "StaticMeshResources.h" -#include "MeshBuild.h" - -#include "Rendering/SkeletalMeshModel.h" -#include "Rendering/SkeletalMeshRenderData.h" - -#include "Engine/SkeletalMesh.h" -#include "SkeletalRenderPublic.h" -#include "Runtime/Engine/Private/SkeletalRenderCPUSkin.h" - -#include "Animation/MorphTarget.h" - -#include "Developer/AssetTools/Public/IAssetTools.h" -#include "Developer/AssetTools/Public/AssetToolsModule.h" - -#include "Toolkits/AssetEditorManager.h" -#include "Dialogs/DlgPickAssetPath.h" -#include "AssetRegistryModule.h" - -#include "VertexAnimUtils.h" -#include "VertexAnimProfile.h" - - -#include "Framework/Notifications/NotificationManager.h" -#include "Widgets/Notifications/SNotificationList.h" - -//#include "Engine.h" - +#include "Framework/MultiBox/MultiBoxExtender.h" #include "Misc/FeedbackContext.h" -#include "Misc/MessageDialog.h" - -#include "IPersonaPreviewScene.h" -#include "AssetViewerSettings.h" -#include "RenderingThread.h" - -#include "Components/PoseableMeshComponent.h" - -#include "AnimationRuntime.h" +#include "Textures/SlateIcon.h" //-------------------------------------- -#include "Interfaces/IPluginManager.h" -#include "Misc/Paths.h" -#include "ShaderCore.h" - -#include "Animation/AnimSequence.h" - -//#include "Runtime/Engine/Classes/Kismet/KismetRenderingLibrary.h" - -#include "Kismet/KismetRenderingLibrary.h" - -#include "PackageTools.h" - #include "VATEditorUtils.h" #define LOCTEXT_NAMESPACE "FVertexAnimToolsetEditorModule" -//#define YESSCENETICK void FVertexAnimToolsetEditorModule::StartupModule() { // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module // hook up level editor extension for skeletal mesh conversion - - //FString PluginShaderDir = FPaths::Combine(IPluginManager::Get().FindPlugin(TEXT("VertexAnimToolset"))->GetBaseDir(), TEXT("Shaders")); - //AddShaderSourceDirectoryMapping(TEXT("/Plugin/VertexAnimToolset"), PluginShaderDir); - - + ModuleLoadedDelegateHandle = FModuleManager::Get().OnModulesChanged().AddLambda([this](FName InModuleName, EModuleChangeReason InChangeReason) { if (InChangeReason == EModuleChangeReason::ModuleLoaded) @@ -105,7 +42,6 @@ void FVertexAnimToolsetEditorModule::ShutdownModule() { // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, // we call this function before unloading the module. - //RemoveAnimationEditorToolbarExtender(); // This is not causing the stuck on exiting Unreal?? RemoveSkeletalMeshEditorToolbarExtender(); @@ -130,19 +66,18 @@ TSharedRef FVertexAnimToolsetEditorModule::GetAnimationEditorToolbarE } -void FVertexAnimToolsetEditorModule::HandleAddSkeletalMeshActionExtenderToToolbar(FToolBarBuilder & ParentToolbarBuilder, UDebugSkelMeshComponent * InMeshComponent) +void FVertexAnimToolsetEditorModule::HandleAddSkeletalMeshActionExtenderToToolbar(FToolBarBuilder & ParentToolbarBuilder, UDebugSkelMeshComponent * InMeshComponent) const { - ParentToolbarBuilder.AddToolBarButton( FUIAction(FExecuteAction::CreateLambda([this, InMeshComponent]() - { - FVATEditorUtils::DoBakeProcess(InMeshComponent); - })), + { + FVATEditorUtils::DoBakeProcess(InMeshComponent); + })), NAME_None, LOCTEXT("BakeAnim", "Bake Anim"), LOCTEXT("BakeAnimToTextureTooltip", "Bake animation frames to textures"), FSlateIcon("EditorStyle", "Persona.TogglePreviewAsset", "Persona.TogglePreviewAsset.Small") - ); + ); } void FVertexAnimToolsetEditorModule::AddSkeletalMeshEditorToolbarExtender() @@ -155,7 +90,7 @@ void FVertexAnimToolsetEditorModule::AddSkeletalMeshEditorToolbarExtender() SkeletalMeshEditorExtenderHandle = ToolbarExtenders.Last().GetHandle(); } -void FVertexAnimToolsetEditorModule::RemoveSkeletalMeshEditorToolbarExtender() +void FVertexAnimToolsetEditorModule::RemoveSkeletalMeshEditorToolbarExtender() const { ISkeletalMeshEditorModule* SkeletalMeshEditorModule = FModuleManager::Get().GetModulePtr("SkeletalMeshEditor"); if (SkeletalMeshEditorModule) @@ -168,10 +103,7 @@ void FVertexAnimToolsetEditorModule::RemoveSkeletalMeshEditorToolbarExtender() TSharedRef FVertexAnimToolsetEditorModule::GetSkeletalMeshEditorToolbarExtender(const TSharedRef CommandList, TSharedRef InSkeletalMeshEditor) { TSharedRef Extender = MakeShareable(new FExtender); - - //UMeshComponent* MeshComponent = InSkeletalMeshEditor->GetPersonaToolkit()->GetPreviewMeshComponent(); UDebugSkelMeshComponent* MeshComponent = InSkeletalMeshEditor->GetPersonaToolkit()->GetPreviewMeshComponent(); - Extender->AddToolBarExtension( "Asset", EExtensionHook::After, diff --git a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimUtils.cpp b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimUtils.cpp index 24214cc..d6148a9 100644 --- a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimUtils.cpp +++ b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Private/VertexAnimUtils.cpp @@ -2,148 +2,48 @@ #include "VertexAnimUtils.h" -#include "IAnimationEditor.h" - -#include "VertexAnimProfile.h" - -#include "Misc/MessageDialog.h" -#include "Modules/ModuleManager.h" -#include "Misc/PackageName.h" -#include "Widgets/Layout/SBorder.h" -#include "Widgets/Text/STextBlock.h" -#include "Widgets/Layout/SUniformGridPanel.h" -#include "Widgets/Input/SEditableTextBox.h" -#include "Widgets/Input/SButton.h" -#include "Widgets/Input/SCheckBox.h" - -#include "EditorStyleSet.h" +#include "AnimationRuntime.h" +#include "AssetRegistryModule.h" +#include "AssetViewerSettings.h" +#include "ContentBrowserModule.h" #include "Editor.h" +#include "EditorStyleSet.h" +#include "IAnimationEditor.h" #include "IContentBrowserSingleton.h" -#include "ContentBrowserModule.h" - -#include "Engine/TextureRenderTarget2D.h" - - -#include "Rendering/SkeletalMeshModel.h" -#include "Rendering/SkeletalMeshRenderData.h" - -#include "Engine/SkeletalMesh.h" -#include "SkeletalRenderPublic.h" -#include "Runtime/Engine/Private/SkeletalRenderCPUSkin.h" - -#include "Animation/MorphTarget.h" -#include "VertexAnimProfile.h" - -#include "MeshDescriptionOperations.h" -#include "UVMapSettings.h" +#include "IPersonaPreviewScene.h" #include "MeshAttributeArray.h" #include "MeshDescription.h" -#include "MeshAttributes.h" - - -#include "Animation/AnimSequence.h" - -#include "Misc/FeedbackContext.h" - - - - - -#include "IPersonaToolkit.h" -#include "Rendering/SkeletalMeshModel.h" -#include "Rendering/SkeletalMeshRenderData.h" - -#include "Animation/DebugSkelMeshComponent.h" - - -#include "Textures/SlateIcon.h" -#include "Styling/SlateTypes.h" -#include "Framework/Commands/UIAction.h" -#include "Framework/Commands/UICommandList.h" -#include "Framework/MultiBox/MultiBoxExtender.h" -#include "Framework/MultiBox/MultiBoxBuilder.h" - -#include "Engine/StaticMesh.h" -#include "Materials/Material.h" -#include "Materials/MaterialInstanceDynamic.h" - #include "RawMesh.h" -#include "StaticMeshResources.h" -#include "MeshBuild.h" - -#include "Rendering/SkeletalMeshModel.h" -#include "Rendering/SkeletalMeshRenderData.h" - -#include "Engine/SkeletalMesh.h" #include "SkeletalRenderPublic.h" -#include "Runtime/Engine/Private/SkeletalRenderCPUSkin.h" - -#include "Animation/MorphTarget.h" - -#include "Developer/AssetTools/Public/IAssetTools.h" +#include "StaticMeshResources.h" +#include "VertexAnimProfile.h" +#include "Animation/DebugSkelMeshComponent.h" #include "Developer/AssetTools/Public/AssetToolsModule.h" - -#include "Toolkits/AssetEditorManager.h" +#include "Developer/AssetTools/Public/IAssetTools.h" #include "Dialogs/DlgPickAssetPath.h" -#include "AssetRegistryModule.h" - -#include "VertexAnimProfile.h" - - +#include "Engine/SkeletalMesh.h" +#include "Engine/StaticMesh.h" #include "Framework/Notifications/NotificationManager.h" -#include "Widgets/Notifications/SNotificationList.h" - -#include "Engine.h" - +#include "Materials/MaterialInstanceDynamic.h" #include "Misc/FeedbackContext.h" #include "Misc/MessageDialog.h" - -#include "IPersonaPreviewScene.h" -#include "AssetViewerSettings.h" -#include "RenderingThread.h" - -#include "Components/PoseableMeshComponent.h" - -#include "AnimationRuntime.h" +#include "Misc/PackageName.h" +#include "Modules/ModuleManager.h" +#include "Rendering/SkeletalMeshModel.h" +#include "Rendering/SkeletalMeshRenderData.h" +#include "Runtime/Engine/Private/SkeletalRenderCPUSkin.h" +#include "Styling/SlateTypes.h" +#include "Widgets/Input/SButton.h" +#include "Widgets/Input/SCheckBox.h" +#include "Widgets/Layout/SBorder.h" +#include "Widgets/Layout/SUniformGridPanel.h" +#include "Widgets/Notifications/SNotificationList.h" +#include "Widgets/Text/STextBlock.h" //-------------------------------------- -#include "Interfaces/IPluginManager.h" -#include "Misc/Paths.h" -#include "ShaderCore.h" - -#include "VertexAnimUtils.h" - -#include "Animation/AnimSequence.h" - -#include "Kismet/KismetRenderingLibrary.h" - -#include "PackageTools.h" - -#include "Animation/AnimSequence.h" - -#include "Rendering/SkinWeightVertexBuffer.h" - - -#include "Misc/App.h" -#include "RenderingThread.h" -#include "GameFramework/PlayerController.h" -#include "ContentStreaming.h" -#include "DrawDebugHelpers.h" -#include "UnrealEngine.h" -#include "SkeletalRenderPublic.h" - -#include "Animation/AnimStats.h" -#include "Engine/SkeletalMeshSocket.h" -#include "PhysicsEngine/PhysicsAsset.h" -#include "EngineGlobals.h" -#include "PrimitiveSceneProxy.h" -#include "Engine/CollisionProfile.h" -#include "Rendering/SkinWeightVertexBuffer.h" -#include "SkeletalMeshTypes.h" -#include "Animation/MorphTarget.h" -#include "AnimationRuntime.h" #include "Animation/AnimSingleNodeInstance.h" +#include "GameFramework/PlayerController.h" #define LOCTEXT_NAMESPACE "PickAssetDialog" @@ -168,21 +68,21 @@ FVector4 FVertexAnimUtils::BitEncodeVecId(const FVector T, const float Bound, co { const FVector N = ((T / Bound) +1.0) * 0.5; - uint32 RI = N.X * 1023; - uint32 GI = N.Y * 1023; - uint32 BI = N.Z * 1023; + const uint32 RI = N.X * 1023; + const uint32 GI = N.Y * 1023; + const uint32 BI = N.Z * 1023; - uint8 R8 = (uint8)(RI); - uint8 G8 = (uint8)(GI); - uint8 B8 = (uint8)(BI); + const uint8 R8 = static_cast(RI); + const uint8 G8 = static_cast(GI); + const uint8 B8 = static_cast(BI); // Should I be doing and & on these?? - uint8 RA = (uint8)((RI >> 8) & 0x3); - uint8 GA = (uint8)((GI >> 6) & 0xc); - uint8 BA = (uint8)((BI >> 4) & 0x30); - uint8 IA = (uint8)(Id) << 6; + const uint8 RA = static_cast((RI >> 8) & 0x3); + const uint8 GA = static_cast((GI >> 6) & 0xc); + const uint8 BA = static_cast((BI >> 4) & 0x30); + const uint8 IA = static_cast(Id) << 6; - uint8 A8 = ((RA | GA) | BA) | IA; + const uint8 A8 = ((RA | GA) | BA) | IA; return FVector4(R8 / 255.0, G8 / 255.0, B8 / 255.0, A8 / 255.0); } @@ -191,44 +91,39 @@ FVector4 FVertexAnimUtils::BitEncodeVecId_HD(const FVector T, const float Bound, { const FVector N = ((T / Bound) + 1.0) * 0.5; - uint32 RI = N.X * 0xFFFFF; - uint32 GI = N.Y * 0xFFFFF; - uint32 BI = N.Z * 0xFFFFF; + const uint32 RI = N.X * 0xFFFFF; + const uint32 GI = N.Y * 0xFFFFF; + const uint32 BI = N.Z * 0xFFFFF; - uint16 R8 = (uint16)(RI); - uint16 G8 = (uint16)(GI); - uint16 B8 = (uint16)(BI); + const uint16 R8 = static_cast(RI); + const uint16 G8 = static_cast(GI); + const uint16 B8 = static_cast(BI); // Should I be doing and & on these?? - uint16 RA = (uint16)((RI >> 16) & 0xF); - uint16 GA = (uint16)((GI >> 12) & 0xF0); - uint16 BA = (uint16)((BI >> 8) & 0xF00); - uint16 IA = (uint16)(Id) << 12; - - //UE_LOG(LogUnrealMath, Warning, TEXT("RI %i, R8 %i || RA %i || IA %i"), RI, R8, RA, IA); - - uint16 A8 = ((RA | GA) | BA) | IA; + const uint16 RA = static_cast((RI >> 16) & 0xF); + const uint16 GA = static_cast((GI >> 12) & 0xF0); + const uint16 BA = static_cast((BI >> 8) & 0xF00); + const uint16 IA = static_cast(Id) << 12; + + const uint16 A8 = ((RA | GA) | BA) | IA; return FVector4( -1.0 + ((R8 / 65535.0) * 2.0), -1.0 + ((G8 / 65535.0) * 2.0), -1.0 + ((B8 / 65535.0) * 2.0), -1.0 + ((A8 / 65535.0) * 2.0)); - } int32 FVertexAnimUtils::Grid2DIndex(const int32& X, const int32& Y, const int32& Width) { //(LocationX * GridSize.Height) + LocationY // CellIndex - //return (X * Height) + Y; return (Y * Width) + X; } // This should be Y with Width int32 FVertexAnimUtils::Grid2D_X(const int32 & Index, const int32 & Width) { // Original // X = CellIndex / GridSize.Height - //return Index % Height; return Index % Width; } @@ -236,12 +131,9 @@ int32 FVertexAnimUtils::Grid2D_X(const int32 & Index, const int32 & Width) int32 FVertexAnimUtils::Grid2D_Y(const int32 & Index, const int32 & Width) { // For Y = CellIndex % GridSize.Height - //return Index / Height; return Index / Width; } - - // Helper function for ConvertMeshesToStaticMesh static void AddOrDuplicateMaterial(UMaterialInterface* InMaterialInterface, const FString& InPackageName, TArray& OutMaterials) { @@ -249,12 +141,12 @@ static void AddOrDuplicateMaterial(UMaterialInterface* InMaterialInterface, cons { // Convert runtime material instances to new concrete material instances // Create new package - FString OriginalMaterialName = InMaterialInterface->GetName(); + const FString OriginalMaterialName = InMaterialInterface->GetName(); FString MaterialPath = FPackageName::GetLongPackagePath(InPackageName) / OriginalMaterialName; FString MaterialName; - FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked("AssetTools"); + const FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked("AssetTools"); AssetToolsModule.Get().CreateUniqueAssetName(MaterialPath, TEXT(""), MaterialPath, MaterialName); - UPackage* MaterialPackage = CreatePackage(NULL, *MaterialPath); + UPackage* MaterialPackage = CreatePackage(*MaterialPath); // Duplicate the object into the new package UMaterialInterface* NewMaterialInterface = DuplicateObject(InMaterialInterface, MaterialPackage, *MaterialName); @@ -266,11 +158,11 @@ static void AddOrDuplicateMaterial(UMaterialInterface* InMaterialInterface, cons MaterialInstanceDynamic->K2_CopyMaterialInstanceParameters(OldMaterialInstanceDynamic); } - NewMaterialInterface->MarkPackageDirty(); - - FAssetRegistryModule::AssetCreated(NewMaterialInterface); - - InMaterialInterface = NewMaterialInterface; + if (NewMaterialInterface->MarkPackageDirty()) + { + FAssetRegistryModule::AssetCreated(NewMaterialInterface); + InMaterialInterface = NewMaterialInterface; + } } OutMaterials.Add(InMaterialInterface); @@ -289,7 +181,7 @@ static void ProcessMaterials(ComponentType* InComponent, const FString& InPackag } // Helper function for ConvertMeshesToStaticMesh -static bool IsValidSkinnedMeshComponent(USkinnedMeshComponent* InComponent) +static bool IsValidSkinnedMeshComponent(const USkinnedMeshComponent* InComponent) { return InComponent && InComponent->MeshObject && InComponent->IsVisible(); } @@ -318,7 +210,7 @@ static void SkinnedMeshToRawMeshes(USkinnedMeshComponent* InSkinnedMeshComponent for (int32 OverallLODIndex = 0; OverallLODIndex < InOverallMaxLODs; OverallLODIndex++) { - int32 LODIndexRead = FMath::Min(OverallLODIndex, NumLODs - 1); + const int32 LODIndexRead = FMath::Min(OverallLODIndex, NumLODs - 1); FRawMesh& RawMesh = OutRawMeshes[OverallLODIndex]; FRawMeshTracker& RawMeshTracker = OutRawMeshTrackers[OverallLODIndex]; @@ -336,10 +228,12 @@ 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)); + RawMesh.VertexPositions.Add(static_cast>( + InComponentToWorld.TransformPosition(static_cast( + FinalVertices[VertIndex].Position)))); } - const uint32 NumTexCoords = FMath::Min(LODData.StaticVertexBuffers.StaticMeshVertexBuffer.GetNumTexCoords(), (uint32)MAX_MESH_TEXTURE_COORDS); + const uint32 NumTexCoords = FMath::Min(LODData.StaticVertexBuffers.StaticMeshVertexBuffer.GetNumTexCoords(), static_cast(MAX_MESH_TEXTURE_COORDS)); const int32 NumSections = LODData.RenderSections.Num(); FRawStaticIndexBuffer16or32Interface& IndexBuffer = *LODData.MultiSizeIndexContainer.GetIndexBuffer(); @@ -357,10 +251,10 @@ static void SkinnedMeshToRawMeshes(USkinnedMeshComponent* InSkinnedMeshComponent RawMesh.WedgeIndices.Add(BaseVertexIndex + VertexIndexForWedge); const FFinalSkinVertex& SkinnedVertex = FinalVertices[VertexIndexForWedge]; - const FVector TangentX = InComponentToWorld.TransformVector(SkinnedVertex.TangentX.ToFVector()); - const FVector TangentZ = InComponentToWorld.TransformVector(SkinnedVertex.TangentZ.ToFVector()); - const FVector4 UnpackedTangentZ = SkinnedVertex.TangentZ.ToFVector4(); - const FVector TangentY = (TangentZ ^ TangentX).GetSafeNormal() * UnpackedTangentZ.W; + const FVector3f TangentX = static_cast>(InComponentToWorld.TransformVector(SkinnedVertex.TangentX.ToFVector())); + const FVector3f TangentZ = static_cast>(InComponentToWorld.TransformVector(SkinnedVertex.TangentZ.ToFVector())); + const FVector4f UnpackedTangentZ = SkinnedVertex.TangentZ.ToFVector4f(); + const FVector3f TangentY = (TangentZ ^ TangentX).GetSafeNormal() * UnpackedTangentZ.W; RawMesh.WedgeTangentX.Add(TangentX); RawMesh.WedgeTangentY.Add(TangentY); @@ -394,7 +288,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 @@ -466,16 +360,10 @@ UStaticMesh* FVertexAnimUtils::ConvertMeshesToStaticMesh(const TArray(MeshComponent); - UStaticMeshComponent* StaticMeshComponent = Cast(MeshComponent); - if (IsValidSkinnedMeshComponent(SkinnedMeshComponent)) { OverallMaxLODs = FMath::Max(SkinnedMeshComponent->MeshObject->GetSkeletalMeshRenderData().LODRenderData.Num(), OverallMaxLODs); } - else if (false)//(IsValidStaticMeshComponent(StaticMeshComponent)) - { - OverallMaxLODs = FMath::Max(StaticMeshComponent->GetStaticMesh()->RenderData->LODResources.Num(), OverallMaxLODs); - } } // Resize raw meshes to accommodate the number of LODs we will need @@ -488,16 +376,10 @@ UStaticMesh* FVertexAnimUtils::ConvertMeshesToStaticMesh(const TArrayGetComponentTransform().ToMatrixWithScale() * WorldToRoot; USkinnedMeshComponent* SkinnedMeshComponent = Cast(MeshComponent); - UStaticMeshComponent* StaticMeshComponent = Cast(MeshComponent); - if (IsValidSkinnedMeshComponent(SkinnedMeshComponent)) { SkinnedMeshToRawMeshes(SkinnedMeshComponent, OverallMaxLODs, ComponentToWorld, PackageName, RawMeshTrackers, RawMeshes, Materials); } - else if (false)//(IsValidStaticMeshComponent(StaticMeshComponent)) - { - //StaticMeshToRawMeshes(StaticMeshComponent, OverallMaxLODs, ComponentToWorld, PackageName, RawMeshTrackers, RawMeshes, Materials); - } } uint32 MaxInUseTextureCoordinate = 0; @@ -539,17 +421,17 @@ 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); + const uint32 LightMapIndex = FMath::Min(MaxInUseTextureCoordinate + 1, static_cast(MAX_MESH_TEXTURE_COORDS) - 1); // Add source to new StaticMesh for (FRawMesh& RawMesh : RawMeshes) @@ -572,14 +454,14 @@ UStaticMesh* FVertexAnimUtils::ConvertMeshesToStaticMesh(const TArrayStaticMaterials.Add(FStaticMaterial(Material)); + StaticMesh->GetStaticMaterials().Add(FStaticMaterial(Material)); } //Set the Imported version before calling the build StaticMesh->ImportVersion = EImportStaticMeshVersion::LastVersion; // Set light map coordinate index to match DstLightmapIndex - StaticMesh->LightMapCoordinateIndex = LightMapIndex; + StaticMesh->SetLightMapCoordinateIndex(LightMapIndex); // setup section info map for (int32 RawMeshLODIndex = 0; RawMeshLODIndex < RawMeshes.Num(); RawMeshLODIndex++) @@ -604,7 +486,10 @@ UStaticMesh* FVertexAnimUtils::ConvertMeshesToStaticMesh(const TArrayBuild(false); StaticMesh->PostEditChange(); - StaticMesh->MarkPackageDirty(); + if (!StaticMesh->MarkPackageDirty()) + { + UE_LOG(LogTemp, Warning, TEXT("Could not set the SM as dirty")); + } // Notify asset registry of new asset FAssetRegistryModule::AssetCreated(StaticMesh); @@ -649,20 +534,19 @@ void FVertexAnimUtils::VATUVsToStaticMeshLODs(UStaticMesh* StaticMesh, const int // Build a mapping of vertex positions to vertex colors. for (int32 WedgeIndex = 0; WedgeIndex < Mesh.WedgeIndices.Num(); ++WedgeIndex) { - int32 VertID = Mesh.WedgeIndices[WedgeIndex]; - FVector Position = Mesh.VertexPositions[VertID]; - + const int32 VertID = Mesh.WedgeIndices[WedgeIndex]; for (uint32 TexCoordIndex = 0; TexCoordIndex < MAX_MESH_TEXTURE_COORDS; TexCoordIndex++) { - if (TexCoordIndex <= NumUVChannels)//(!RawMeshTrackers[RawMeshIndex].bValidTexCoords[TexCoordIndex]) + if (TexCoordIndex <= NumUVChannels) { if ((TexCoordIndex == UVChannel)) { - // Mesh.WedgeTexCoords[TexCoordIndex].Empty(); 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] = static_cast(UVs[PaintingMeshLODIndex][VertID]); } else if(TexCoordIndex >= NumUVChannels) { @@ -677,7 +561,7 @@ void FVertexAnimUtils::VATUVsToStaticMeshLODs(UStaticMesh* StaticMesh, const int } // Determine which texture coordinate map should be used for storing/generating the lightmap UVs - const uint32 LightMapIndex = FMath::Min(UVChannel == NumUVChannels ? NumUVChannels + 1 : NumUVChannels, (uint32)MAX_MESH_TEXTURE_COORDS - 1); + const uint32 LightMapIndex = FMath::Min(UVChannel == NumUVChannels ? NumUVChannels + 1 : NumUVChannels, static_cast(MAX_MESH_TEXTURE_COORDS) - 1); StaticMesh->GetSourceModel(PaintingMeshLODIndex).BuildSettings.DstLightmapIndex = LightMapIndex; // Save the new raw mesh. @@ -686,9 +570,7 @@ void FVertexAnimUtils::VATUVsToStaticMeshLODs(UStaticMesh* StaticMesh, const int StaticMesh->ImportVersion = EImportStaticMeshVersion::LastVersion; // Set light map coordinate index to match DstLightmapIndex - StaticMesh->LightMapCoordinateIndex = LightMapIndex; - - + StaticMesh->SetLightMapCoordinateIndex(LightMapIndex); } } } @@ -696,7 +578,10 @@ void FVertexAnimUtils::VATUVsToStaticMeshLODs(UStaticMesh* StaticMesh, const int // Build mesh from source StaticMesh->Build(false); StaticMesh->PostEditChange(); - StaticMesh->MarkPackageDirty(); + if (!StaticMesh->MarkPackageDirty()) + { + UE_LOG(LogTemp, Warning, TEXT("Could not set the SM as dirty")); + } } void FVertexAnimUtils::VATColorsToStaticMeshLODs(UStaticMesh* StaticMesh, const TArray>& Colors) @@ -709,7 +594,6 @@ void FVertexAnimUtils::VATColorsToStaticMeshLODs(UStaticMesh* StaticMesh, const { if (StaticMesh->GetSourceModel(PaintingMeshLODIndex).IsRawMeshEmpty() == false) { - const uint32 NumUVChannels = StaticMesh->GetNumUVChannels(PaintingMeshLODIndex); // Extract the raw mesh. FRawMesh Mesh; StaticMesh->GetSourceModel(PaintingMeshLODIndex).LoadRawMesh(Mesh); @@ -724,8 +608,7 @@ void FVertexAnimUtils::VATColorsToStaticMeshLODs(UStaticMesh* StaticMesh, const // Build a mapping of vertex positions to vertex colors. for (int32 WedgeIndex = 0; WedgeIndex < Mesh.WedgeIndices.Num(); ++WedgeIndex) { - int32 VertID = Mesh.WedgeIndices[WedgeIndex]; - FVector Position = Mesh.VertexPositions[VertID]; + const int32 VertID = Mesh.WedgeIndices[WedgeIndex]; Mesh.WedgeColors[WedgeIndex] = Colors[PaintingMeshLODIndex][VertID]; } @@ -739,19 +622,16 @@ void FVertexAnimUtils::VATColorsToStaticMeshLODs(UStaticMesh* StaticMesh, const // Build mesh from source StaticMesh->Build(false); StaticMesh->PostEditChange(); - StaticMesh->MarkPackageDirty(); + if (!StaticMesh->MarkPackageDirty()) + { + UE_LOG(LogTemp, Warning, TEXT("Could not mark SM as dirty")); + } } - - - - void SPickAssetDialog::Construct(const FArguments& InArgs) { - - FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked("ContentBrowser"); - - TSharedPtr AssetPickerBox1 = SNew(SVerticalBox) + const FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked("ContentBrowser"); + const TSharedPtr AssetPickerBox1 = SNew(SVerticalBox) + SVerticalBox::Slot() .FillHeight(0.1) .FillHeight(0.1) @@ -759,36 +639,7 @@ void SPickAssetDialog::Construct(const FArguments& InArgs) SNew(STextBlock) .Text(LOCTEXT("Profile", "Profile")) ]; - - /* - TSharedPtr AssetPickerBox2 = SNew(SVerticalBox) - +SVerticalBox::Slot() - .FillHeight(0.1) - .FillHeight(0.1) - [ - SNew(STextBlock) - .Text(LOCTEXT("Offsets", "Offsets Render Target")) - ]; - - TSharedPtr AssetPickerBox3 = SNew(SVerticalBox) - + SVerticalBox::Slot() - .FillHeight(0.1) - .FillHeight(0.1) - [ - SNew(STextBlock) - .Text(LOCTEXT("Normals", "Normals Render Target")) - ]; - - TSharedPtr AssetPickerBox4 = SNew(SVerticalBox) - + SVerticalBox::Slot() - .FillHeight(0.1) - .FillHeight(0.1) - [ - SNew(STextBlock) - .Text(LOCTEXT("StaticMesh", "Static Mesh")) - ]; - */ - + { // Vertex Anim Profile { @@ -798,7 +649,7 @@ void SPickAssetDialog::Construct(const FArguments& InArgs) AssetPickerConfig.GetCurrentSelectionDelegates.Add(&GetCurrentSelectionDelegate_Profile); - AssetPickerConfig.OnShouldFilterAsset = FOnShouldFilterAsset::CreateSP(this, &SPickAssetDialog::Filter); + AssetPickerConfig.OnShouldFilterAsset = FOnShouldFilterAsset::CreateStatic(&SPickAssetDialog::Filter); AssetPickerConfig.bAllowNullSelection = true; AssetPickerConfig.InitialAssetViewType = EAssetViewType::List; AssetPickerConfig.ThumbnailScale = 1.f; @@ -822,143 +673,7 @@ void SPickAssetDialog::Construct(const FArguments& InArgs) PathPickerConfig.bAddDefaultPath = true; // - /* - SWindow::Construct(SWindow::FArguments() - .Title(InArgs._Title) - .SupportsMinimize(false) - .SupportsMaximize(false) - .ClientSize(FVector2D(1080, 720)) - [ - SNew(SVerticalBox) - - + SVerticalBox::Slot() - .Padding(2, 2, 2, 4) - .HAlign(HAlign_Fill) - [ - SNew(SBorder) - .BorderImage(FEditorStyle::GetBrush("ToolPanel.GroupBorder")) - [ - SNew(SVerticalBox) - - + SVerticalBox::Slot() - .FillHeight(1) - .Padding(3) - .HAlign(HAlign_Fill) - [ - SNew(SVerticalBox) - - + SVerticalBox::Slot() - .FillHeight(2) - .Padding(3) - [ - SNew(SHorizontalBox) - - + SHorizontalBox::Slot() - .FillWidth(1) - .HAlign(HAlign_Fill) - .VAlign(VAlign_Fill) - [ - AssetPickerBox1.ToSharedRef() - ] - ] - - + SVerticalBox::Slot() - .AutoHeight() - .Padding(3) - [ - SNew(SHorizontalBox) - + SHorizontalBox::Slot() - .AutoWidth() - .Padding(0, 0, 10, 0) - .VAlign(VAlign_Center) - [ - SNew(STextBlock) - .Text(LOCTEXT("CreateStaticMesh", "Create Static Mesh")) - ] - - + SHorizontalBox::Slot() - .AutoWidth() - .Padding(0, 0, 10, 0) - .VAlign(VAlign_Center) - [ - SNew(SCheckBox) - .ToolTipText(LOCTEXT("CreateStaticMesh_Tooltip", "Create Static Mesh with special UV channel for vertex animation")) - .IsChecked(ECheckBoxState::Checked) - .OnCheckStateChanged(this, &SPickAssetDialog::OnCheckedCreateStaticMesh) - - ] - - ] - - - + SVerticalBox::Slot() - .FillHeight(1) - .Padding(3) - .HAlign(HAlign_Fill) - [ - ContentBrowserModule.Get().CreatePathPicker(PathPickerConfig) - ] - - ] - - + SVerticalBox::Slot() - .AutoHeight() - .Padding(3) - [ - SNew(SHorizontalBox) - + SHorizontalBox::Slot() - .AutoWidth() - .Padding(0, 0, 10, 0) - .VAlign(VAlign_Center) - [ - SNew(STextBlock) - .Text(LOCTEXT("Name", "Name")) - ] - - + SHorizontalBox::Slot() - [ - SNew(SEditableTextBox) - .Text(AssetName) - .OnTextCommitted(this, &SPickAssetDialog::OnNameChange) - .MinDesiredWidth(250) - ] - ] - - ] - ] - - + SVerticalBox::Slot() - .AutoHeight() - .HAlign(HAlign_Right) - .VAlign(VAlign_Bottom) - [ - SNew(SUniformGridPanel) - .SlotPadding(FEditorStyle::GetMargin("StandardDialog.SlotPadding")) - .MinDesiredSlotWidth(FEditorStyle::GetFloat("StandardDialog.MinDesiredSlotWidth")) - .MinDesiredSlotHeight(FEditorStyle::GetFloat("StandardDialog.MinDesiredSlotHeight")) - + SUniformGridPanel::Slot(0, 0) - [ - SNew(SButton) - .Text(LOCTEXT("OK", "OK")) - .HAlign(HAlign_Center) - .ContentPadding(FEditorStyle::GetMargin("StandardDialog.ContentPadding")) - .OnClicked(this, &SPickAssetDialog::OnButtonClick, EAppReturnType::Ok) - ] - + SUniformGridPanel::Slot(1, 0) - [ - SNew(SButton) - .Text(LOCTEXT("Cancel", "Cancel")) - .HAlign(HAlign_Center) - .ContentPadding(FEditorStyle::GetMargin("StandardDialog.ContentPadding")) - .OnClicked(this, &SPickAssetDialog::OnButtonClick, EAppReturnType::Cancel) - ] - ] - ] - ); - */ - - SWindow::Construct(SWindow::FArguments() .Title(InArgs._Title) .SupportsMinimize(false) @@ -1075,51 +790,30 @@ FReply SPickAssetDialog::OnButtonClick(EAppReturnType::Type ButtonID) case 1: // NULL Profile FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("NULLProfile", "No Profile Selected")); return FReply::Unhandled(); - break; case 2: // Invalid Offsets or Normals Texture FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("NULLOffsetsNormalsTexture", "Selected Profile has invalid Offsets or Normals Texture")); return FReply::Unhandled(); - break; case 3: // No Width / Height correspondence between Profile and Offsets Texture FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("NoWidthHeightCorrespondenceOffsets", "Selected Profile has no Width / Height correspondence with Offsets texture")); return FReply::Unhandled(); - break; case 4: // No Width / Height correspondence between Profile and Normals Texture FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("Invalid Override Width Height", "Deactivated Auto Size, but invalid Override Size")); return FReply::Unhandled(); - break; case 5: // Profile has not Anims FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("SelectedProfileHasNoAnims", "Selected Profile has no Anims")); return FReply::Unhandled(); - break; case 6: // Invalid Sequence Ref FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("InvalidSequenceRefInProfile", "Selected Profile has anim with invalid Sequence Ref")); return FReply::Unhandled(); - break; case 7: // Anims have different Skeletons FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("DifferentSkeletonsInProfileAnims", "Selected Profile has anims with different skeletons")); return FReply::Unhandled(); - break; case 8: // Anim has Num of Frames less than 1 FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("AnimsInProfileWith0NumFrames", "Selected Profile has anim with Num Frames less than 1")); return FReply::Unhandled(); - break; default: break; }; - - // If no valid profile selected it doesnt get here - - UVertexAnimProfile* SelectedProfile = GetSelectedProfile(); - - if (bOnlyCreateStaticMesh) - { - if (false)//(!ValidatePackage()) - { - FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("InvalidPackage", "Invalid Package for static mesh")); - return FReply::Unhandled(); - } - } } //----------------------------------------------------------------------------------------------------- @@ -1132,7 +826,7 @@ FReply SPickAssetDialog::OnButtonClick(EAppReturnType::Type ButtonID) } /** Ensures supplied package name information is valid */ -bool SPickAssetDialog::ValidatePackage() +bool SPickAssetDialog::ValidatePackage() const { FText Reason; if (!FPackageName::IsValidLongPackageName(GetFullAssetPath().ToString(), false, &Reason) @@ -1143,11 +837,11 @@ bool SPickAssetDialog::ValidatePackage() } if (FPackageName::DoesPackageExist(GetFullAssetPath().ToString()) || - FindObject(NULL, *(AssetPath.ToString() + "/" + AssetName.ToString() + "." + AssetName.ToString())) != NULL) + FindObject(nullptr, *(AssetPath.ToString() + "/" + AssetName.ToString() + "." + AssetName.ToString())) != nullptr) { - if (GetSelectedProfile() != NULL) + if (GetSelectedProfile() != nullptr) { - if (GetSelectedProfile()->StaticMesh == FindObject(NULL, *(AssetPath.ToString() + "/" + AssetName.ToString() + "." + AssetName.ToString()))) + if (GetSelectedProfile()->StaticMesh == FindObject(nullptr, *(AssetPath.ToString() + "/" + AssetName.ToString() + "." + AssetName.ToString()))) { return true; } @@ -1177,7 +871,7 @@ const FText& SPickAssetDialog::GetAssetName() return AssetName; } -FText SPickAssetDialog::GetFullAssetPath() +FText SPickAssetDialog::GetFullAssetPath() const { return FText::FromString(AssetPath.ToString() + "/" + AssetName.ToString()); } @@ -1188,7 +882,7 @@ void SPickAssetDialog::OnCheckedOnlyCreateStaticMesh(ECheckBoxState NewCheckedSt { bOnlyCreateStaticMesh = true; } - else //if (NewCheckedState == ECheckBoxState::Unchecked) + else { bOnlyCreateStaticMesh = false; } @@ -1220,7 +914,7 @@ UVertexAnimProfile * SPickAssetDialog::GetSelectedProfile() const return StoredProfiles[0]; } - return NULL; + return nullptr; } @@ -1238,58 +932,71 @@ bool SPickAssetDialog::Filter(const FAssetData & AssetData) int32 SPickAssetDialog::ValidateProfile() const { UVertexAnimProfile* Profile = GetSelectedProfile(); - if (Profile != NULL) + if (Profile != nullptr) { // Invalid Offsets or Normals Texture - if ((!Profile->AutoSize) && (Profile->OverrideSize_Vert.GetMax() < 8)) return 4; + if ((!Profile->AutoSize) && (Profile->OverrideSize_Vert.GetMax() < 8)) + { + return 4; + } + // Profile has not Anims - if ((Profile->Anims_Vert.Num() == 0) && (Profile->Anims_Bone.Num() == 0)) return 5; - - - USkeleton* Skeleton = NULL; - if (Profile->Anims_Vert.Num()) - if (Profile->Anims_Vert[0].SequenceRef != NULL) Skeleton = Profile->Anims_Vert[0].SequenceRef->GetSkeleton(); - if (Profile->Anims_Bone.Num()) - if (Profile->Anims_Bone[0].SequenceRef != NULL) Skeleton = Profile->Anims_Bone[0].SequenceRef->GetSkeleton(); + if ((Profile->Anims_Vert.Num() == 0) && (Profile->Anims_Bone.Num() == 0)) + { + return 5; + } + + const USkeleton* Skeleton = nullptr; + if (Profile->Anims_Vert.Num() && Profile->Anims_Vert[0].SequenceRef != nullptr) + { + Skeleton = Profile->Anims_Vert[0].SequenceRef->GetSkeleton(); + } + if (!Skeleton && Profile->Anims_Bone.Num() > 0 && Profile->Anims_Bone[0].SequenceRef != nullptr) + { + Skeleton = Profile->Anims_Bone[0].SequenceRef->GetSkeleton(); + } + + + for (int32 i = 0; i < Profile->Anims_Vert.Num(); i++) { - for (int32 i = 0; i < Profile->Anims_Vert.Num(); i++) + // Invalid Sequence Ref + if (Profile->Anims_Vert[i].SequenceRef == nullptr) return 6; + + if (Profile->Anims_Vert[i].SequenceRef->GetSkeleton() != Skeleton) { - // Invalid Sequence Ref - if (Profile->Anims_Vert[i].SequenceRef == NULL) return 6; - - if (Profile->Anims_Vert[i].SequenceRef->GetSkeleton() != Skeleton) - { - // Anims have different Skeletons - return 7; - } - if ((Profile->Anims_Vert[i].NumFrames < 1)) - { - // Anim has Num Frames less than 1 - return 8; - } + // Anims have different Skeletons + return 7; + } + if ((Profile->Anims_Vert[i].NumFrames < 1)) + { + // Anim has Num Frames less than 1 + return 8; } } + + + for (int32 i = 0; i < Profile->Anims_Bone.Num(); i++) { - for (int32 i = 0; i < Profile->Anims_Bone.Num(); i++) + // Invalid Sequence Ref + if (Profile->Anims_Bone[i].SequenceRef == nullptr) { - // Invalid Sequence Ref - if (Profile->Anims_Bone[i].SequenceRef == NULL) return 6; + return 6; + } - if (Profile->Anims_Bone[i].SequenceRef->GetSkeleton() != Skeleton) - { - // Anims have different Skeletons - return 7; - } - if ((Profile->Anims_Bone[i].NumFrames < 1)) - { - // Anim has Num Frames less than 1 - return 8; - } + if (Profile->Anims_Bone[i].SequenceRef->GetSkeleton() != Skeleton) + { + // Anims have different Skeletons + return 7; + } + + if ((Profile->Anims_Bone[i].NumFrames < 1)) + { + // Anim has Num Frames less than 1 + return 8; } } - //Profile->LODInSkeletalMesh; return 0; } diff --git a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Public/VATEditorUtils.h b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Public/VATEditorUtils.h index 34aaa65..96ee46a 100644 --- a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Public/VATEditorUtils.h +++ b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Public/VATEditorUtils.h @@ -3,14 +3,7 @@ #pragma once #include "CoreMinimal.h" -#include "GPUSkinPublicDefs.h" -#include "UObject/ObjectMacros.h" -#include "UObject/Object.h" #include "Engine/EngineTypes.h" -#include "Components/SceneComponent.h" -#include "Engine/TextureStreamingTypes.h" -#include "Components/MeshComponent.h" -#include "Containers/SortedMap.h" class UDebugSkelMeshComponent; class UTextureRenderTarget2D; @@ -37,15 +30,16 @@ class VERTEXANIMTOOLSETEDITOR_API FVATEditorUtils static void SkelExtents(USkeletalMesh* Skel, TArray & VectorData); static void VectorDataToTextureColor(const TArray& InVectorData, TArray & Data); - // used for HDR Pivot Pos, Origin Pos, Origin Extents | ldr Pivot Directions (X, Y or Z) + + // used for HDR Pivot Pos, Origin Pos, Origin Extents | ldr Pivot Directions (X, Y or Z) static void VectorDataToUV(const TArray& InVectorData, const int32 StartIdx, TArray& UVs); - // used for ldr Pivot Directions (X, Y or Z) + + // used for ldr Pivot Directions (X, Y or Z) static void VectorDataToVertColor(const TArray& InVectorData, TArray& Colors); - static void UVChannelsToSkeletalMesh(USkeletalMesh* Skel, const int32 LODIndex, const int32 UVChannelStart, TArray>& UVChannels); + static void UVChannelsToSkeletalMesh(const USkeletalMesh* Skel, const int32 LODIndex, const int32 UVChannelStart, TArray>& UVChannels); static void UVChannelToStaticMesh(UStaticMesh* Mesh, const int32 TargetUVChannel, TArray & UVs); static void IntoIslands(const TArray & IndexBuffer, const TArray & UVs, TArray & OutIslandIDs, int32& OutNumIslands); - static void ClosestUVPivotAssign( - const TArray & IndexBuffer, const TArray & UVs, const TArray & PivotUVPos, TArray & VertPivotIDs); + static void ClosestUVPivotAssign(const TArray & IndexBuffer, const TArray & UVs, const TArray & PivotUVPos, TArray & VertPivotIDs); }; diff --git a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Public/VertexAnimToolsetEditor.h b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Public/VertexAnimToolsetEditor.h index 2fff35b..3c7f2c4 100644 --- a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Public/VertexAnimToolsetEditor.h +++ b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Public/VertexAnimToolsetEditor.h @@ -30,12 +30,12 @@ class FVertexAnimToolsetEditorModule : public IModuleInterface //void AddAnimationEditorToolbarExtender(); //void RemoveAnimationEditorToolbarExtender(); - void HandleAddSkeletalMeshActionExtenderToToolbar(FToolBarBuilder& ParentToolbarBuilder, UDebugSkelMeshComponent* InMeshComponent); + void HandleAddSkeletalMeshActionExtenderToToolbar(FToolBarBuilder& ParentToolbarBuilder, UDebugSkelMeshComponent* InMeshComponent) const; void AddSkeletalMeshEditorToolbarExtender(); - void RemoveSkeletalMeshEditorToolbarExtender(); + void RemoveSkeletalMeshEditorToolbarExtender() const; TSharedRef GetSkeletalMeshEditorToolbarExtender(const TSharedRef CommandList, TSharedRef InSkeletalMeshEditor); diff --git a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Public/VertexAnimUtils.h b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Public/VertexAnimUtils.h index 60fd6b1..0ad5f98 100644 --- a/VertexAnimToolset/Source/VertexAnimToolsetEditor/Public/VertexAnimUtils.h +++ b/VertexAnimToolset/Source/VertexAnimToolsetEditor/Public/VertexAnimUtils.h @@ -3,25 +3,11 @@ #pragma once #include "CoreMinimal.h" - +#include "ContentBrowserDelegates.h" #include "Input/Reply.h" #include "Widgets/DeclarativeSyntaxSupport.h" -#include "Widgets/SCompoundWidget.h" -#include "Engine/Texture2D.h" -#include "IDetailsView.h" - - -#include "Layout/Visibility.h" -#include "Widgets/SWidget.h" - -#include "IDetailCustomization.h" - -#include "Widgets/DeclarativeSyntaxSupport.h" -#include "Input/Reply.h" #include "Widgets/SWindow.h" -#include "ContentBrowserDelegates.h" - class UTextureRenderTarget2D; class FSkeletalMeshLODRenderData; @@ -92,7 +78,7 @@ class SPickAssetDialog : public SWindow VERTEXANIMTOOLSETEDITOR_API const FText& GetAssetName(); /** Gets the resulting full asset path (path+'/'+name) */ - VERTEXANIMTOOLSETEDITOR_API FText GetFullAssetPath(); + VERTEXANIMTOOLSETEDITOR_API FText GetFullAssetPath() const; void OnCheckedOnlyCreateStaticMesh(ECheckBoxState NewCheckedState); @@ -103,7 +89,7 @@ class SPickAssetDialog : public SWindow return bOnlyCreateStaticMesh; } - bool Filter(const FAssetData& AssetData); + static bool Filter(const FAssetData& AssetData); int32 ValidateProfile() const; @@ -116,7 +102,7 @@ class SPickAssetDialog : public SWindow void OnNameChange(const FText& NewName, ETextCommit::Type CommitInfo); FReply OnButtonClick(EAppReturnType::Type ButtonID); - bool ValidatePackage(); + bool ValidatePackage() const; EAppReturnType::Type UserResponse; diff --git a/VertexAnimToolset/VertexAnimToolset.uplugin b/VertexAnimToolset/VertexAnimToolset.uplugin index 7187cec..de51942 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", "CanContainContent": true, "Installed": false, "Modules": [