From f2c7a52a9d579323e7a249921fddd7b2c37c40de Mon Sep 17 00:00:00 2001 From: Roel Algaba Brizuela Date: Tue, 11 May 2021 17:27:28 +0200 Subject: [PATCH] Changes for road materials. --- .../LoadAssetMaterialsCommandlet.cpp | 2 +- .../Source/Carla/Util/RoadPainterWrapper.cpp | 76 ------------------- .../Source/Carla/Util/RoadPainterWrapper.h | 13 ---- Util/BuildTools/Import.py | 6 +- 4 files changed, 2 insertions(+), 95 deletions(-) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/LoadAssetMaterialsCommandlet.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/LoadAssetMaterialsCommandlet.cpp index 1ac5ae020..b1d508669 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/LoadAssetMaterialsCommandlet.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/LoadAssetMaterialsCommandlet.cpp @@ -78,7 +78,7 @@ void ULoadAssetMaterialsCommandlet::LoadAssetsMaterials(const FString &PackageNa for (const auto &Map : MapsPaths) { AssetDatas.Empty(); - const FString DefaultPath = TEXT("/Game/") + PackageName + TEXT("/Maps/") + Map.Name; + const FString DefaultPath = TEXT("/Game/") + PackageName + TEXT("/Maps/"); MapObjectLibrary->LoadAssetDataFromPath(*DefaultPath); MapObjectLibrary->LoadAssetsFromAssetData(); MapObjectLibrary->GetAssetDataList(AssetDatas); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.cpp index ec6b1f054..44db2eb6c 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.cpp @@ -112,15 +112,6 @@ ARoadPainterWrapper::ARoadPainterWrapper(){ DecalNamesMap.Add("gum", "MaterialInstanceConstant'/Game/Carla/Static/Decals/Road/OilSplats/DI_Gum.DI_Gum'"); DecalNamesMap.Add("grate", "MaterialInstanceConstant'/Game/Carla/Static/Decals/Road/Manhole/DI_Grate_01_v2.DI_Grate_01_v2'"); - RoadMasterMaterialName = "Material'/Game/Carla/Static/GenericMaterials/RoadPainterMaterials/LargeMaps/M_RoadMasterTiled.M_RoadMasterTiled'"; - RoadInstanceMaterialName = "MaterialInstanceConstant'/Game/Carla/Static/GenericMaterials/RoadPainterMaterials/LargeMaps/M_Road_03_Tiled.M_Road_03_Tiled'"; - - RoadTextureBrushes.Add("Texture2D'/Game/Carla/Static/GenericMaterials/Tiles/HDTiles/M_SquareTile_v4_d.M_SquareTile_v4_d'"); - //RoadTextureBrushes.Add("Texture2D'/Game/Carla/Static/Decals/Road/OilSplats/Textures/GroundSplatter/T_GroundSplatter_d.T_GroundSplatter_d'"); - //RoadTextureBrushes.Add("Texture2D'/Game/Carla/Static/GenericMaterials/RoadStencil/Alphas/splat1.splat1'"); - //RoadTextureBrushes.Add("Texture2D'/Game/Carla/Static/GenericMaterials/RoadStencil/Alphas/splat2.splat2'"); - //RoadTextureBrushes.Add("Texture2D'/Game/Carla/Static/GenericMaterials/RoadStencil/Alphas/splat3.splat3'"); - #endif } @@ -132,74 +123,7 @@ void ARoadPainterWrapper::BeginPlay() void ARoadPainterWrapper::GenerateDynamicAssets() { - TArray FoundActors; - UGameplayStatics::GetAllActorsOfClass(GetWorld(), AStaticMeshActor::StaticClass(), FoundActors); - AStaticMeshActor *RoadMeshActor = nullptr; - for (int32 i = 0; i < FoundActors.Num(); ++i) - { - RoadMeshActor = Cast(FoundActors[i]); - if (RoadMeshActor) - { - ZSizeEvent(); - - FString TextureString; - //Get the string we need - bool IsRoadPainterReady = JsonParsed->GetBoolField(TEXT("prepared_roadpainter")); - if (IsRoadPainterReady == false) { - - //Generate the texture we need and save the name. - //This will be written into a .json file so we can look it up later - TextureString = GenerateTexture(); - } - - TArray FoundActors; - UGameplayStatics::GetAllActorsOfClass(GetWorld(), AStaticMeshActor::StaticClass(), FoundActors); - AStaticMeshActor *RoadMeshActor = nullptr; - - for (int32 i = 0; i < FoundActors.Num(); ++i) - { - RoadMeshActor = Cast(FoundActors[i]); - if (RoadMeshActor) - { - if (RoadMeshActor->GetName().Contains("Roads_Road", ESearchCase::Type::CaseSensitive) == true) - { - 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); - } - } - } - } - - //We write our variables - TSharedPtr RootObject = MakeShareable(new FJsonObject()); - //Are the textures ready? - RootObject->SetBoolField("prepared_roadpainter", true); - //Are the roads rendered to texture already? - RootObject->SetBoolField("painted_roads", false); - if (IsRoadPainterReady == false) { - - //We set the name of the newly generated texture into the json file - RootObject->SetStringField("texture_name", TextureString); - } - else { - - TextureString = JsonParsed->GetStringField("texture_name"); - RootObject->SetStringField("texture_name", TextureString); - } - - FString JsonString; - TSharedRef> JsonWriter = TJsonWriterFactory::Create(&JsonString); - FJsonSerializer::Serialize(RootObject.ToSharedRef(), JsonWriter); - //Save JSON file - FFileHelper::SaveStringToFile(JsonString, *AbsolutePathToFile); - } - } } const FString ARoadPainterWrapper::GenerateTexture() diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.h index 74000f358..6d1bc7cea 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.h @@ -80,9 +80,6 @@ public: UFUNCTION(BlueprintCallable, Category = "RoadPainter Wrapper") void GenerateDynamicAssets(); - UPROPERTY(BlueprintReadOnly, Category = "RoadPainter Wrapper") - UTexture2D *RoadBrushTexture; - /// Variable used for storing the JSON values of the decals /// so it can be later used by the blueprint (Road Painter Preset) UPROPERTY(BlueprintReadOnly, Category = "RoadPainter Wrapper") @@ -98,14 +95,4 @@ private: UPROPERTY() TMap DecalNamesMap; - UPROPERTY() - TArray RoadTextureBrushes; - - /// Master material of the roads (necessary for creating material instances) - UPROPERTY() - FString RoadMasterMaterialName; - - /// Material instance that copies - UPROPERTY() - FString RoadInstanceMaterialName; }; diff --git a/Util/BuildTools/Import.py b/Util/BuildTools/Import.py index a56e73a29..91a3c749b 100755 --- a/Util/BuildTools/Import.py +++ b/Util/BuildTools/Import.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!python # Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma de # Barcelona (UAB). @@ -143,16 +143,12 @@ def generate_decals_file(folder): 'cracksbig8': '10', 'mud1' : '10', 'mud5' : '10', - 'manhole1' : '10', - 'manhole2' : '10', - 'manhole3' : '10', 'oilsplat1' : '20', 'oilsplat2' : '20', 'oilsplat3' : '20', 'oilsplat4' : '20', 'oilsplat5' : '20', 'gum' : '30', - 'grate' : '10', 'crack1': '10', 'crack8': '10', 'decal_scale' : {