UE5基于RumtimeFBXImport插件使用C++加载服务器上fbx文件方法

UE5的RumtimeFBXImport插件其实只能加载本机的fbx文件,要加载服务器上的fbx文件的话,需要先将该fbx文件下载到本地,然后再使用RumtimeFBXImport插件加载。

示例文件如下:

cpp 复制代码
#include "Loader/WebLoader.h"
#include "Misc/FileHelper.h"
#include "Misc/Paths.h"
#include "HttpModule.h"
#include "Http.h"
#include "FBXImportManager.h"

AWebLoader::AWebLoader(){}

void AWebLoader::BeginPlay()
{
	Super::BeginPlay();

	if (WebFbxPath.Len() > 0)
	{
		LoadFileFromServer(WebFbxPath);
	}
}

void AWebLoader::LoadFileFromServer(const FString& URL)
{
	TSharedRef<IHttpRequest, ESPMode::ThreadSafe> HttpRequest = FHttpModule::Get().CreateRequest();
	HttpRequest->SetURL(URL);
	HttpRequest->SetVerb("GET");
	HttpRequest->OnProcessRequestComplete().BindUObject(this, &AWebLoader::OnFileDownloadComplete);
	HttpRequest->ProcessRequest();
}

void AWebLoader::OnFileDownloadComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
	if (bWasSuccessful && Response.IsValid() && Response->GetResponseCode() == EHttpResponseCodes::Ok)
	{
		FString ProjectRoot = FPaths::Combine(FPaths::ProjectDir(), LocalRelatedPath);
		FString FileName = FPaths::GetCleanFilename(WebFbxPath);
		FString LocalFullPath = FPaths::Combine(ProjectRoot, FileName);

		if (!FFileHelper::SaveArrayToFile(Response->GetContent(), *LocalFullPath))
		{
			UE_LOG(LogTemp, Error, TEXT("File downloaded failed!"));
			return;
		}
		//
		LoadLocalFBX(LocalFullPath);
	}
	else
	{
		UE_LOG(LogTemp, Error, TEXT("File download failed."));
	}
}

void AWebLoader::LoadLocalFBX(FString LocalFullPath)
{
	if (!FBXImportManager)
	{
		FBXImportManager = GetWorld()->SpawnActor<AFBXImportManager>();
	}

	FBXImportManager->InitializeFBXLoad();
	FBXImportManager->ImportFBXFile(LocalFullPath, FVector::UpVector, BaseMaterial, EFBXCollisionType::MeshCollision);
}
相关推荐
AI视觉网奇16 小时前
blender 导入fbx 黑色骨骼
学习·算法·ue5·blender
_风华ts1 天前
创建并使用AimOffset
ue5·动画·虚幻·虚幻引擎·aimoffset
AI视觉网奇1 天前
ue 角色驱动衣服 绑定衣服
笔记·学习·ue5
AI视觉网奇2 天前
3d数字人 ue blender 绑定衣服对齐 2026
学习·ue5
AI视觉网奇5 天前
ue metahuman自动绑定实战
笔记·学习·ue5
AI视觉网奇5 天前
ue 安装报错MD-DL ue 安装笔记
笔记·学习·ue5
zhangzhangkeji5 天前
UE5 多线程(6):FQueuedThreadPool 的使用,peek 函数,
ue5
AI视觉网奇5 天前
ue 导出 fbx
笔记·学习·ue5
zhangzhangkeji5 天前
UE5 多线程(5-3):锁的智能指针版本 FScopeLock 与 FScopeUnlock。
ue5
菜鸟z级6 天前
ubuntu18.04+realsense d415+ur5手眼标定,眼在手上
ue5·机器人·相机