From 5487e17f60ae5e826dea5908fd7ca42edb627ba2 Mon Sep 17 00:00:00 2001 From: Axel Date: Thu, 9 Mar 2023 16:01:53 +0100 Subject: [PATCH] Making Omniverse code optional --- .../Source/CarlaTools/CarlaTools.Build.cs | 30 ++++++++++++++++--- .../CarlaTools/Private/USDImporterWidget.cpp | 9 +++++- Util/BuildTools/BuildCarlaUE4.bat | 17 +++++++---- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/CarlaTools.Build.cs b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/CarlaTools.Build.cs index ea147a4db..225c7a367 100644 --- a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/CarlaTools.Build.cs +++ b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/CarlaTools.Build.cs @@ -7,6 +7,7 @@ using UnrealBuildTool; public class CarlaTools : ModuleRules { bool UsingHoudini = true; + bool bUsingOmniverseConnector = false; private bool IsWindows(ReadOnlyTargetRules Target) { return (Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32); @@ -23,6 +24,21 @@ public class CarlaTools : ModuleRules bEnableExceptions = true; } + string CarlaPluginPath = Path.GetFullPath( ModuleDirectory ); + string ConfigDir = Path.GetFullPath(Path.Combine(CarlaPluginPath, "../../../../Config/")); + string OptionalModulesFile = Path.Combine(ConfigDir, "OptionalModules.ini"); + string[] text = System.IO.File.ReadAllLines(OptionalModulesFile); + foreach (string line in text) + { + if (line.Contains("Omniverse ON")) + { + Console.WriteLine("Enabling OmniverseConnector"); + bUsingOmniverseConnector = true; + PublicDefinitions.Add("WITH_OMNIVERSE"); + PrivateDefinitions.Add("WITH_OMNIVERSE"); + } + } + PublicIncludePaths.AddRange( new string[] { // ... add public include paths required here ... @@ -58,8 +74,6 @@ public class CarlaTools : ModuleRules "Slate", "SlateCore", "UnrealEd", - "OmniverseUSD", - "OmniverseRuntime", "Blutility", "UMG", "EditorScriptingUtilities", @@ -88,8 +102,16 @@ public class CarlaTools : ModuleRules "HoudiniEngineRuntime" }); } - - + if(bUsingOmniverseConnector) + { + PrivateDependencyModuleNames.AddRange( + new string[] + { + "OmniverseUSD", + "OmniverseRuntime" + }); + } + DynamicallyLoadedModuleNames.AddRange( new string[] { diff --git a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/USDImporterWidget.cpp b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/USDImporterWidget.cpp index 303a3a588..868f383f8 100644 --- a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/USDImporterWidget.cpp +++ b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/USDImporterWidget.cpp @@ -1,7 +1,9 @@ // Copyright (c) 2023 Computer Vision Center (CVC) at the Universitat Autonoma de Barcelona (UAB). This work is licensed under the terms of the MIT license. For a copy, see . #include "USDImporterWidget.h" -#include "USDCARLAInterface.h" +#ifdef WITH_OMNIVERSE + #include "USDCARLAInterface.h" +#endif #include "Kismet/GameplayStatics.h" #include "Modules/ModuleManager.h" #include "IMeshMergeUtilities.h" @@ -12,7 +14,12 @@ void UUSDImporterWidget::ImportUSDProp( const FString& USDPath, const FString& DestinationAssetPath, bool bAsBlueprint) { +#ifdef WITH_OMNIVERSE FUSDCARLAInterface::ImportUSD(USDPath, DestinationAssetPath, false, bAsBlueprint); +#else + UE_LOG(LogCarlaTools, Error, TEXT("Omniverse Plugin is not enabled")); +#endif + } void UUSDImporterWidget::ImportUSDVehicle( diff --git a/Util/BuildTools/BuildCarlaUE4.bat b/Util/BuildTools/BuildCarlaUE4.bat index 8d22589bb..2458808be 100644 --- a/Util/BuildTools/BuildCarlaUE4.bat +++ b/Util/BuildTools/BuildCarlaUE4.bat @@ -125,6 +125,15 @@ if not exist "%HOUDINI_PLUGIN_PATH%" ( rem Build Carla Editor rem +set OMNIVERSE_PATCH_FOLDER=%ROOT_PATH%Util\Patches\omniverse_4.26\ +set OMNIVERSE_PLUGIN_FOLDER=%UE4_ROOT%Engine\Plugins\Marketplace\NVIDIA\Omniverse\ +if exist %OMNIVERSE_PLUGIN_FOLDER% ( + set OMNIVERSE_PLUGIN_INSTALLED="Omniverse ON" + xcopy /Y /S /I "%OMNIVERSE_PATCH_FOLDER%USDCARLAInterface.h" "%OMNIVERSE_PLUGIN_FOLDER%Source\OmniverseUSD\Public\" > NUL + xcopy /Y /S /I "%OMNIVERSE_PATCH_FOLDER%USDCARLAInterface.cpp" "%OMNIVERSE_PLUGIN_FOLDER%Source\OmniverseUSD\Private\" > NUL +) else ( + set OMNIVERSE_PLUGIN_INSTALLED="Omniverse OFF" +) if %USE_CARSIM% == true ( py -3 %ROOT_PATH%Util/BuildTools/enable_carsim_to_uproject.py -f="%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject" -e @@ -138,14 +147,10 @@ if %USE_CHRONO% == true ( ) else ( set CHRONO_STATE="Chrono OFF" ) -set OPTIONAL_MODULES_TEXT=%CARSIM_STATE% %CHRONO_STATE% + +set OPTIONAL_MODULES_TEXT=%CARSIM_STATE% %CHRONO_STATE% %OMNIVERSE_PLUGIN_INSTALLED% echo %OPTIONAL_MODULES_TEXT% > "%ROOT_PATH%Unreal/CarlaUE4/Config/OptionalModules.ini" -set OMNIVERSE_PATCH_FOLDER=%ROOT_PATH%Util\Patches\omniverse_4.26\ -set OMNIVERSE_PLUGIN_FOLDER=%UE4_ROOT%Engine\Plugins\Marketplace\NVIDIA\Omniverse\ - -xcopy /Y /S /I "%OMNIVERSE_PATCH_FOLDER%USDCARLAInterface.h" "%OMNIVERSE_PLUGIN_FOLDER%Source\OmniverseUSD\Public\" > NUL -xcopy /Y /S /I "%OMNIVERSE_PATCH_FOLDER%USDCARLAInterface.cpp" "%OMNIVERSE_PLUGIN_FOLDER%Source\OmniverseUSD\Private\" > NUL if %BUILD_UE4_EDITOR% == true ( echo %FILE_N% Building Unreal Editor...