diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/LoadAssetMaterialsCommandlet.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/LoadAssetMaterialsCommandlet.cpp index 15962b169..fa93dabb1 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/LoadAssetMaterialsCommandlet.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/LoadAssetMaterialsCommandlet.cpp @@ -17,19 +17,19 @@ ULoadAssetMaterialsCommandlet::ULoadAssetMaterialsCommandlet() { - // Set necessary flags to run commandlet - IsClient = false; - IsEditor = true; - IsServer = false; - LogToConsole = true; + // Set necessary flags to run commandlet + IsClient = false; + IsEditor = true; + IsServer = false; + LogToConsole = true; #if WITH_EDITORONLY_DATA - static ConstructorHelpers::FObjectFinder RoadPainterBlueprint(TEXT( - "Blueprint'/Game/Carla/Blueprints/LevelDesign/RoadPainterPreset.RoadPainterPreset'")); + static ConstructorHelpers::FObjectFinder RoadPainterBlueprint(TEXT( + "Blueprint'/Game/Carla/Blueprints/LevelDesign/RoadPainterPreset.RoadPainterPreset'")); - RoadPainterSubclass = (UClass*)RoadPainterBlueprint.Object->GeneratedClass; - + RoadPainterSubclass = (UClass*)RoadPainterBlueprint.Object->GeneratedClass; + #endif } @@ -75,18 +75,18 @@ void ULoadAssetMaterialsCommandlet::GenerateJsonInfoFile(const FString &MapName) void ULoadAssetMaterialsCommandlet::ApplyRoadPainterMaterials(const FString &LoadedMapName) { GenerateJsonInfoFile(LoadedMapName); - ARoadPainterWrapper *RoadPainterBp = World->SpawnActor(RoadPainterSubclass); - if (RoadPainterBp) - { - //Needed to call events in editor-mode - FEditorScriptExecutionGuard ScriptGuard; + ARoadPainterWrapper *RoadPainterBp = World->SpawnActor(RoadPainterSubclass); + if (RoadPainterBp) + { + //Needed to call events in editor-mode + FEditorScriptExecutionGuard ScriptGuard; RoadPainterBp->ClearAllEvent(); RoadPainterBp->ReadConfigFile(LoadedMapName); RoadPainterBp->SetBlueprintVariables(); //Spawn the decals loaded in via the JSON file RoadPainterBp->SpawnDecalsEvent(); - } + } } FString ULoadAssetMaterialsCommandlet::GetFirstPackagePath(const FString &PackageName) const @@ -149,11 +149,11 @@ FPackageParams ULoadAssetMaterialsCommandlet::ParseParams(const FString &InParam TArray Tokens; TArray Params; TMap ParamVals; - + ParseCommandLine(*InParams, Tokens, Params); - + FPackageParams PackageParams; - + // Parse and store Package name FParse::Value(*InParams, TEXT("PackageName="), PackageParams.Name); @@ -213,12 +213,12 @@ int32 ULoadAssetMaterialsCommandlet::Main(const FString &Params) FAssetsPaths AssetsPaths = GetAssetsPathFromPackage(PackageParams.Name); LoadAssetsMaterials(PackageParams.Name, AssetsPaths.MapsPaths); - + #if WITH_EDITOR - UEditorLoadingAndSavingUtils::SaveDirtyPackages(true, true); + UEditorLoadingAndSavingUtils::SaveDirtyPackages(true, true); #endif - return 0; + return 0; } #endif \ No newline at end of file diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.cpp index 5a3e70275..6d8163f7f 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.cpp @@ -81,6 +81,7 @@ ARoadPainterWrapper::ARoadPainterWrapper(){ DecalNamesMap.Add("crack7", ConstructorHelpers::FObjectFinder(TEXT("MaterialInstanceConstant'/Game/Carla/Static/Decals/Road/Cracks/DI_RoadCrack15.DI_RoadCrack15'")).Object); DecalNamesMap.Add("crack8", ConstructorHelpers::FObjectFinder(TEXT("MaterialInstanceConstant'/Game/Carla/Static/Decals/Road/Cracks/DI_RoadCrack16.DI_RoadCrack16'")).Object); + //Decal names array DecalNamesArray = {"drip1", "drip2", "drip3", "dirt1", "dirt2", "dirt3", "dirt4", "dirt5", "roadline1", "roadline2", "roadline3", "roadline4", "roadline5", @@ -136,12 +137,15 @@ void ARoadPainterWrapper::ReadJsonAndPrepareRoadPainter(){ { if (RoadMeshActor->GetName().Contains("Roads_Road", ESearchCase::Type::CaseSensitive) == true) { - //Create the dynamic material instance for the road (which will hold the map size and road texture) - UMaterialInstanceDynamic* MI = UMaterialInstanceDynamic::Create(RoadNodeMasterMaterial, NULL); - MI->CopyParameterOverrides((UMaterialInstance*)RoadNodePresetMaterial); - MI->SetScalarParameterValue(FName("Map units (CM)"), MapSize); - MI->SetTextureParameterValue(FName("Texture Mask"), RoadTexture); - RoadMeshActor->GetStaticMeshComponent()->SetMaterial(0, MI); + if (RoadMeshActor->GetStaticMeshComponent()->GetMaterial(0)->GetName().Contains("MaterialInstance", ESearchCase::Type::CaseSensitive) == false) { + + //Create the dynamic material instance for the road (which will hold the map size and road texture) + UMaterialInstanceDynamic* MI = UMaterialInstanceDynamic::Create(RoadNodeMasterMaterial, NULL); + MI->CopyParameterOverrides((UMaterialInstance*)RoadNodePresetMaterial); + MI->SetScalarParameterValue(FName("Map units (CM)"), MapSize); + MI->SetTextureParameterValue(FName("Texture Mask"), RoadTexture); + RoadMeshActor->GetStaticMeshComponent()->SetMaterial(0, MI); + } } } } @@ -196,10 +200,24 @@ void ARoadPainterWrapper::ReadJsonAndPaintRoads() { //Get the boolean we need bool AreRoadsPainted = JsonParsed->GetBoolField(TEXT("painted_roads")); if (AreRoadsPainted == false) { - + + //Switch the material mask to R(ed) channel. + //This means rendering the roads to texture only using the R mask + SwitchMaterialMaskEvent(0); //Render all roads to texture PaintAllRoadsEvent(); + //Switch the material mask to G(reen) channel. + SwitchMaterialMaskEvent(1); + PaintAllRoadsEvent(); + + //Switch the material mask to B(lue) channel. + SwitchMaterialMaskEvent(2); + PaintAllRoadsEvent(); + + //Set back to default + SwitchMaterialMaskEvent(0); + //We write our variables TSharedPtr RootObject = MakeShareable(new FJsonObject()); //Are the textures already loaded? @@ -269,24 +287,24 @@ const FString ARoadPainterWrapper::GenerateTexture() UTexture2D *InternalTexture2D = NewObject(UTexture2D::StaticClass()); if (RoadTexture) { - //Prevent the object and all its descedants from being deleted during garbage collecion + //Prevent the object and all its descendants from being deleted during garbage collection RoadTexture->AddToRoot(); RoadTexture->RenderTargetFormat = ETextureRenderTargetFormat::RTF_RGBA8; - RoadTexture->SizeX = 2048; - RoadTexture->SizeY = 2048; + RoadTexture->SizeX = 4096; + RoadTexture->SizeY = 4096; RoadTexture->AddressX = TextureAddress::TA_Wrap; RoadTexture->AddressY = TextureAddress::TA_Wrap; - + //Initialize the platform data to store necessary information regarding our texture asset InternalTexture2D->AddToRoot(); InternalTexture2D->PlatformData = new FTexturePlatformData(); - InternalTexture2D->PlatformData->SizeX = 2048; - InternalTexture2D->PlatformData->SizeY = 2048; + InternalTexture2D->PlatformData->SizeX = 4096; + InternalTexture2D->PlatformData->SizeY = 4096; InternalTexture2D->AddressX = TextureAddress::TA_Wrap; InternalTexture2D->AddressY = TextureAddress::TA_Wrap; #if WITH_EDITORONLY_DATA - InternalTexture2D->Source.Init(2048, 2048, 1, 1, ETextureSourceFormat::TSF_RGBA8); + InternalTexture2D->Source.Init(4096, 4096, 1, 1, ETextureSourceFormat::TSF_RGBA8); #endif InternalTexture2D->UpdateResource(); @@ -294,14 +312,14 @@ const FString ARoadPainterWrapper::GenerateTexture() //Set the texture render target internal texture RoadTexture->UpdateTexture2D(InternalTexture2D, ETextureSourceFormat::TSF_RGBA8); #if WITH_EDITORONLY_DATA - RoadTexture->Source.Init(2048, 2048, 1, 1, ETextureSourceFormat::TSF_RGBA8); + RoadTexture->Source.Init(4096, 4096, 1, 1, ETextureSourceFormat::TSF_RGBA8); #endif RoadTexture->UpdateResource(); Package->MarkPackageDirty(); - + //Notify the editor we created a new asset FAssetRegistryModule::AssetCreated(RoadTexture); - + //Auto-save the new asset FString PackageFilename = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension()); UPackage::SavePackage(Package, RoadTexture, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, *PackageFilename, GError, nullptr, true, true, SAVE_NoError); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.h index d39130d00..dc0a6d1a4 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.h @@ -61,50 +61,56 @@ public: /// Event used for setting the size of the map via blueprint UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") - void ZSizeEvent(); + void ZSizeEvent(); /// Event used for painting by actor points /// generated on the road (created during the import process) via blueprint UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") - void PaintByActorEvent(); + void PaintByActorEvent(); /// Event used for painting as a whole square via blueprint UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") - void PaintOverSquareEvent(); + void PaintOverSquareEvent(); /// Event used for painting as a whole circle via blueprint UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") - void PaintOverCircleEvent(); + void PaintOverCircleEvent(); /// Event used for painting the road map to the selected texture via blueprint UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") - void PaintAllRoadsEvent(); + void PaintAllRoadsEvent(); /// Event used for spawning meshes by actor points /// generated on the road (created during the import process) via blueprint UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") - void SpawnMeshesByActorEvent(); + void SpawnMeshesByActorEvent(); /// Event used for spawning meshes via blueprint UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") - void SpawnMeshesEvent(); + void SpawnMeshesEvent(); /// Event used for spawning decals via blueprint UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") - void SpawnDecalsEvent(); + void SpawnDecalsEvent(); + + /// Change the material mask for painting the roads as RGB format + /// This is used for multitexturing (blending different materials with one another) + /// R = 1, G = 2, B = 3 + UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") + void SwitchMaterialMaskEvent(int MaskType); /// Event for clearing the materials on the road via blueprint UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") - void ClearMaterialEvent(); + void ClearMaterialEvent(); /// Event for clearing the materials close to the actor points /// generated on the road (created during the import process) via blueprint UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") - void ClearMaterialByActorEvent(); + void ClearMaterialByActorEvent(); /// Event for clearing all the materials on the road via blueprint UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") - void ClearAllEvent(); + void ClearAllEvent(); /// Event for setting the necessary variables in blueprint in order to paint the roads UFUNCTION(BlueprintImplementableEvent, Category = "RoadPainter Wrapper") diff --git a/Util/BuildTools/Import.py b/Util/BuildTools/Import.py index 5999f6239..bb34d9901 100755 --- a/Util/BuildTools/Import.py +++ b/Util/BuildTools/Import.py @@ -153,17 +153,17 @@ def generate_decals_file(folder): 'crack7': '5', 'crack8': '5', 'decal_scale' : { - 'x_axis' : '1.0', - 'y_axis' : '1.0', - 'z_axis' : '1.0'}, + 'x_axis' : '0.7', + 'y_axis' : '0.7', + 'z_axis' : '0.7'}, 'fixed_decal_offset': { - 'x_axis' : '0.0', - 'y_axis' : '0.0', - 'z_axis' : '0.0'}, - 'decal_min_scale' : '1.0', + 'x_axis' : '30.0', + 'y_axis' : '30.0', + 'z_axis' : '30.0'}, + 'decal_min_scale' : '0.5', 'decal_max_scale' : '1.0', - 'decal_random_yaw' : '360.0', - 'random_offset' : '0.0' + 'decal_random_yaw' : '180.0', + 'random_offset' : '15.0' }); # build and write the .json