Fixed spaces and tabs and updated textures

This commit is contained in:
Roel Algaba Brizuela 2021-04-21 18:14:30 +02:00 committed by bernat
parent 4f1add75ee
commit f4e8dd2d0b
4 changed files with 82 additions and 58 deletions

View File

@ -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<UBlueprint> RoadPainterBlueprint(TEXT(
"Blueprint'/Game/Carla/Blueprints/LevelDesign/RoadPainterPreset.RoadPainterPreset'"));
static ConstructorHelpers::FObjectFinder<UBlueprint> 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<ARoadPainterWrapper>(RoadPainterSubclass);
if (RoadPainterBp)
{
//Needed to call events in editor-mode
FEditorScriptExecutionGuard ScriptGuard;
ARoadPainterWrapper *RoadPainterBp = World->SpawnActor<ARoadPainterWrapper>(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<FString> Tokens;
TArray<FString> Params;
TMap<FString, FString> 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

View File

@ -81,6 +81,7 @@ ARoadPainterWrapper::ARoadPainterWrapper(){
DecalNamesMap.Add("crack7", ConstructorHelpers::FObjectFinder<UMaterialInstance>(TEXT("MaterialInstanceConstant'/Game/Carla/Static/Decals/Road/Cracks/DI_RoadCrack15.DI_RoadCrack15'")).Object);
DecalNamesMap.Add("crack8", ConstructorHelpers::FObjectFinder<UMaterialInstance>(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<FJsonObject> RootObject = MakeShareable(new FJsonObject());
//Are the textures already loaded?
@ -269,24 +287,24 @@ const FString ARoadPainterWrapper::GenerateTexture()
UTexture2D *InternalTexture2D = NewObject<UTexture2D>(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);

View File

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

View File

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