// Fill out your copyright notice in the Description page of Project Settings.
#include "UpdateAssetVersionLibrary.h"
#include "Runtime\Core\Public\Misc\FileHelper.h"
#include "Runtime\Core\Public\Misc\Paths.h"
#include "Misc\Paths.h"
#include "EdGraphUtilities.h"
#include "MaterialGraph/MaterialGraphNode.h"
#include "Windows/WindowsPlatformApplicationMisc.h"
#include "Kismet2/BlueprintEditorUtils.h"
#include "HAL\FileManagerGeneric.h"
#include "GenericPlatform/GenericPlatformApplicationMisc.h"
#include "MaterialGraph/MaterialGraphSchema.h"
#include "Runtime/Engine/Public/ImageUtils.h"
#include "Kismet\KismetSystemLibrary.h"
#include "Developer\DesktopPlatform\Public\IDesktopPlatform.h"
#include "Developer\DesktopPlatform\Public\DesktopPlatformModule.h"
#include "MaterialGraph/MaterialGraphNode_Comment.h"
FString UUpdateAssetVersionLibrary::OpenFileDialog(FString Dialog, FString OpenPath)
{
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
FString OutFolderName;
FString DefaultFile;
FString FileType = FString("*.uasset");
if (DesktopPlatform != nullptr) {
if (DesktopPlatform->OpenDirectoryDialog(nullptr, Dialog, OpenPath, OutFolderName)) {
OutFolderName.Append("/");
return OutFolderName;
}
}
return FString();
}
FString UUpdateAssetVersionLibrary::ConvertObsolutePathToRelativePath(FString ObPath, FString TailPath)
{
FString HeadPath = UKismetSystemLibrary::GetProjectContentDirectory();
for (uint16 Count = 0; Count < HeadPath.Len(); Count++) {
ObPath.RemoveAt(0);
}
FString HeadDir = "/Script/Engine.StaticMesh'/Game/";
HeadDir.Append(ObPath);
for (uint8 Count = 0; Count < 7; Count++) {
HeadDir.RemoveAt(HeadDir.Len() - 1);
TailPath.RemoveAt(TailPath.Len() - 1);
}
HeadDir.Append("." + TailPath + "'");
return HeadDir;
}
void UUpdateAssetVersionLibrary::ExportStaticMeshToFBX(FString Path)
{
//UStaticMesh* StaticMesh = LoadObject<UStaticMesh>(nullptr, TEXT("/Script/Engine.StaticMesh'/Game/FPWeapon/Mesh/FirstPersonProjectileMesh.FirstPersonProjectileMesh'"));
TArray<UObject*> ExportMesh;
//ExportMesh.Add(StaticMesh);
IAssetTools& assetTools = IAssetTools::Get();
IFileManager& FileManager = IFileManager::Get();
FFileManagerGeneric* FileManagerGeneric = new FFileManagerGeneric();
TArray<FString> AssetNames;
TArray<FString> AllStaticMeshUassetPath;
TArray<FString> IdentifyPath;
if(FileManagerGeneric != nullptr)
FileManagerGeneric->FindFiles(AssetNames, *Path, TEXT(""));
if (AssetNames.Num() != 0) {
for (auto AssetIter : AssetNames) {
FString RelativePath = ConvertObsolutePathToRelativePath(Path + AssetIter, AssetIter);
AllStaticMeshUassetPath.AddUnique(RelativePath);
}
for (auto PathIter : AllStaticMeshUassetPath) {
//if (FileManager.FileExists(*PathIter)) {
UStaticMesh* StaticMesh = LoadObject<UStaticMesh>(nullptr, *PathIter);
if (StaticMesh->IsValidLowLevel()) {
ExportMesh.Add(StaticMesh);
}
}
}
else {
return;
}
//FString("D:/ExportAssets")
assetTools.ExportAssetsWithDialog(ExportMesh, true);
}
bool UUpdateAssetVersionLibrary::WriteToTXT(FString Information, FString MaterialName)
{
uint16 Number = 0;
FString Dialog;
FString OutFolderName;
FString OpenPath = UKismetSystemLibrary::GetProjectContentDirectory();
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
DesktopPlatform->OpenDirectoryDialog(nullptr, Dialog, OpenPath, OutFolderName);
OutFolderName += ("/" + MaterialName);
while (1) {
FString PathTemp = OutFolderName + "_" + FString::FromInt(Number) + ".txt";
if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*PathTemp)) {
Number++;
}
else {
OutFolderName = PathTemp;
break;
}
}
bool isSuccess = FFileHelper::SaveStringToFile(Information, *OutFolderName);
return isSuccess;
}
vo
UE5 程序化批量导出staticmesh为FBX
于 2024-07-02 18:52:40 首次发布