10 #include "FileHelper.h"
12#include "JsonObject.h"
13#include "JsonSerializer.h"
14#include "AssetRegistry/AssetRegistryModule.h"
15#include "Engine/StaticMeshActor.h"
16#include "Engine/TextureRenderTarget2D.h"
17#include "Kismet/GameplayStatics.h"
18#include "Kismet/KismetRenderingLibrary.h"
19#include "Materials/MaterialInstanceDynamic.h"
20#include "UObject/ConstructorHelpers.h"
24#if WITH_EDITORONLY_DATA
28 TArray<AActor*> MeshActors;
29 UGameplayStatics::GetAllActorsOfClass(GetWorld(), AStaticMeshActor::StaticClass(), MeshActors);
30 for (int32 i = 0; i < MeshActors.Num(); ++i) {
32 AStaticMeshActor *StaticMeshActor = Cast<AStaticMeshActor>(MeshActors[i]);
33 if (StaticMeshActor) {
35 if (StaticMeshActor->GetName().Contains(
"Curb", ESearchCase::Type::IgnoreCase) || StaticMeshActor->GetName().Contains(
"Gutter", ESearchCase::Type::IgnoreCase)) {
37 StaticMeshActor->GetStaticMeshComponent()->bReceivesDecals =
false;
57 FString JsonConfigFile;
59 TArray<FString> FileList;
60 IFileManager::Get().FindFilesRecursive(FileList, *(FPaths::ProjectContentDir()),
61 *(FString(
"roadpainter_decals.json")),
true,
false,
false);
63 if(FFileHelper::LoadFileToString(JsonConfigFile, *(IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*FileList[0]))))
65 TSharedPtr<FJsonObject> JsonParsed;
66 TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonConfigFile);
67 if(FJsonSerializer::Deserialize(JsonReader, JsonParsed))
70 auto DecalJsonArray = JsonParsed->GetArrayField(TEXT(
"decals"));
71 for(
auto &DecalJsonValue : DecalJsonArray)
73 const auto DecalJsonObject = DecalJsonValue->AsObject();
77 FString JsonMapName = DecalJsonObject->GetStringField(TEXT(
"map_name"));
78 if(JsonMapName.Equals(CurrentMapName) ==
true)
82 for (
const TPair<FString, FString>& Pair : DecalNamesMap) {
83 if (DecalJsonObject->HasField(Pair.Key) ==
true) {
105 FVector ObjectVector;
106 ObjectVector.X = (float)JsonObject->GetNumberField(TEXT(
"x_axis"));
107 ObjectVector.Y = (float)JsonObject->GetNumberField(TEXT(
"y_axis"));
108 ObjectVector.Z = (float)JsonObject->GetNumberField(TEXT(
"z_axis"));
FVector ReadVectorFromJsonObject(TSharedPtr< FJsonObject > JsonObject)
Function to read 3D vectors from a JSON file
void BeginPlay() override
FDecalsProperties DecalPropertiesConfig
Variable used for storing the JSON values of the decals so it can be later used by the blueprint (Roa...
void ReadConfigFile(const FString &CurrentMapName, const TMap< FString, FString > &DecalNamesMap)
Function for reading the decals configuration file (in JSON format)
float DecalRandomYaw
The decal yaw to be applied randomly
float DecalMaxScale
Maximum scale to be applied to the decals
TArray< int32 > DecalNumToSpawn
How many decals (or material instances) of each, should be applied to the road
float RandomOffset
Random offset from one decal to another
TArray< UMaterialInstance * > DecalMaterials
The decals used on the road
float DecalMinScale
Min scale to be applied to the decals
FVector DecalScale
Scale of each decal on the road
FVector FixedDecalOffset
Min offset from one decal to another