Projekt for SPIE - Avatar for safety briefing / managment event
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

102 lines
3.7 KiB

// Georgy Treshchev 2025.
#include "RuntimeMetaHumanLipSyncModule.h"
#include "Misc/EngineVersionComparison.h"
#if PLATFORM_WINDOWS && !UE_VERSION_OLDER_THAN(5, 6, 0)
#include "NNEOnnxruntime.h"
#elif PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX || PLATFORM_IOS
#include <onnxruntime_cxx_api.h>
#endif
#include "Modules/ModuleManager.h"
#include "Interfaces/IPluginManager.h"
#include "Misc/Paths.h"
DEFINE_LOG_CATEGORY(LogRuntimeMetaHumanLipSync);
void FRuntimeMetaHumanLipSyncModule::StartupModule()
{
#if PLATFORM_WINDOWS && !UE_VERSION_OLDER_THAN(5, 6, 0)
UE_LOG(LogRuntimeMetaHumanLipSync, Log, TEXT("Loading ONNX Runtime from NNEOnnxruntime module"));
const FString PluginDir = IPluginManager::Get().FindPlugin("NNERuntimeORT")->GetBaseDir();
const FString OrtSharedLibPath = FPaths::Combine(PluginDir, TEXT(PREPROCESSOR_TO_STRING(ONNXRUNTIME_SHAREDLIB_PATH)));
FPlatformProcess::PushDllDirectory(*FPaths::GetPath(OrtSharedLibPath));
OrtSharedLibHandle = FPlatformProcess::GetDllHandle(*OrtSharedLibPath);
FPlatformProcess::PopDllDirectory(*FPaths::GetPath(OrtSharedLibPath));
TUniquePtr<UE::NNEOnnxruntime::OrtApiFunctions> OrtApiFunctions = UE::NNEOnnxruntime::LoadApiFunctions(OrtSharedLibHandle);
if (!OrtApiFunctions.IsValid())
{
UE_LOG(LogRuntimeMetaHumanLipSync, Fatal, TEXT("Failed to load ONNX Runtime shared library functions!"));
return;
}
Ort::InitApi(OrtApiFunctions->OrtGetApiBase()->GetApi(ORT_API_VERSION));
#elif PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX || PLATFORM_IOS
#if PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX
const FString PluginDir = IPluginManager::Get().FindPlugin("RuntimeMetaHumanLipSync")->GetBaseDir();
const FString OrtSharedLibFilePath = FPaths::Combine(PluginDir, TEXT("Source"), TEXT("RuntimeMetaHumanLipSync"), TEXT(PREPROCESSOR_TO_STRING(ONNXRUNTIME_SHAREDLIB_PATH_TTS)));
const FString OrtSharedLibDirPath = FPaths::GetPath(OrtSharedLibFilePath);
UE_LOG(LogRuntimeMetaHumanLipSync, Log, TEXT("Loading ONNX Runtime dynamic/shared library from '%s'"), *OrtSharedLibFilePath);
FPlatformProcess::PushDllDirectory(*FPaths::GetPath(OrtSharedLibDirPath));
OrtSharedLibHandle = FPlatformProcess::GetDllHandle(*OrtSharedLibFilePath);
FPlatformProcess::PopDllDirectory(*FPaths::GetPath(OrtSharedLibDirPath));
#endif
Ort::InitApi();
#endif
}
void FRuntimeMetaHumanLipSyncModule::ShutdownModule()
{
}
FString FRuntimeMetaHumanLipSyncModule::GetModelDataAssetName() const
{
return TEXT("EpicMetaHumanLipSyncCpuModel");
}
FString FRuntimeMetaHumanLipSyncModule::GetModelDataPackagePath() const
{
return TEXT("/RuntimeMetaHumanLipSync/RealisticModelData");
}
FString FRuntimeMetaHumanLipSyncModule::GetModelDataFullPackagePath() const
{
return FPaths::Combine(GetModelDataPackagePath(), GetModelDataAssetName());
}
FString FRuntimeMetaHumanLipSyncModule::GetModelDataAssetPath() const
{
const FString AssetName = GetModelDataAssetName();
return FString::Printf(TEXT("%s.%s"), *FPaths::Combine(*GetModelDataPackagePath(), *AssetName), *AssetName);
}
FString FRuntimeMetaHumanLipSyncModule::GetMoodModelDataAssetName() const
{
return TEXT("EpicMetaHumanLipSyncMoodCpuModel");
}
FString FRuntimeMetaHumanLipSyncModule::GetMoodModelDataPackagePath() const
{
return TEXT("/RuntimeMetaHumanLipSync/RealisticModelData");
}
FString FRuntimeMetaHumanLipSyncModule::GetMoodModelDataFullPackagePath() const
{
return FPaths::Combine(GetMoodModelDataPackagePath(), GetMoodModelDataAssetName());
}
FString FRuntimeMetaHumanLipSyncModule::GetMoodModelDataAssetPath() const
{
const FString AssetName = GetMoodModelDataAssetName();
return FString::Printf(TEXT("%s.%s"), *FPaths::Combine(*GetMoodModelDataPackagePath(), *AssetName), *AssetName);
}
IMPLEMENT_MODULE(FRuntimeMetaHumanLipSyncModule, RuntimeMetaHumanLipSync);