Changes for road materials.

This commit is contained in:
Roel Algaba Brizuela 2021-05-11 17:27:28 +02:00 committed by bernat
parent 170154aabd
commit f2c7a52a9d
4 changed files with 2 additions and 95 deletions

View File

@ -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);

View File

@ -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<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AStaticMeshActor::StaticClass(), FoundActors);
AStaticMeshActor *RoadMeshActor = nullptr;
for (int32 i = 0; i < FoundActors.Num(); ++i)
{
RoadMeshActor = Cast<AStaticMeshActor>(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<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AStaticMeshActor::StaticClass(), FoundActors);
AStaticMeshActor *RoadMeshActor = nullptr;
for (int32 i = 0; i < FoundActors.Num(); ++i)
{
RoadMeshActor = Cast<AStaticMeshActor>(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<FJsonObject> 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<TJsonWriter<TCHAR>> JsonWriter = TJsonWriterFactory<TCHAR>::Create(&JsonString);
FJsonSerializer::Serialize(RootObject.ToSharedRef(), JsonWriter);
//Save JSON file
FFileHelper::SaveStringToFile(JsonString, *AbsolutePathToFile);
}
}
}
const FString ARoadPainterWrapper::GenerateTexture()

View File

@ -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<FString, FString> DecalNamesMap;
UPROPERTY()
TArray<FString> RoadTextureBrushes;
/// Master material of the roads (necessary for creating material instances)
UPROPERTY()
FString RoadMasterMaterialName;
/// Material instance that copies
UPROPERTY()
FString RoadInstanceMaterialName;
};

View File

@ -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' : {