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;
54 FString JsonConfigFile;
56 TArray<FString> FileList;
58 *(FString(
"roadpainter_decals.json")),
true,
false,
false);
60 if(FFileHelper::LoadFileToString(JsonConfigFile, *(
IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*FileList[0]))))
62 TSharedPtr<FJsonObject> JsonParsed;
63 TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonConfigFile);
64 if(FJsonSerializer::Deserialize(JsonReader, JsonParsed))
67 auto DecalJsonArray = JsonParsed->GetArrayField(TEXT(
"decals"));
68 for(
auto &DecalJsonValue : DecalJsonArray)
70 const auto DecalJsonObject = DecalJsonValue->AsObject();
74 FString JsonMapName = DecalJsonObject->GetStringField(TEXT(
"map_name"));
75 if(JsonMapName.Equals(CurrentMapName) ==
true)
79 for (
const TPair<FString, FString>& Pair : DecalNamesMap) {
80 if (DecalJsonObject->HasField(Pair.Key) ==
true) {
102 FVector ObjectVector;
103 ObjectVector.X = (float)JsonObject->GetNumberField(TEXT(
"x_axis"));
104 ObjectVector.Y = (float)JsonObject->GetNumberField(TEXT(
"y_axis"));
105 ObjectVector.Z = (float)JsonObject->GetNumberField(TEXT(
"z_axis"));
float DecalMaxScale
Maximum scale to be applied to the decals.
FVector FixedDecalOffset
Min offset from one decal to another.
float DecalRandomYaw
The decal yaw to be applied randomly.
TArray< UMaterialInstance * > DecalMaterials
The decals used on the road.
FDecalsProperties DecalPropertiesConfig
Variable used for storing the JSON values of the decals so it can be later used by the blueprint (Roa...
void BeginPlay() override
static T Get(carla::rpc::Response< T > &response)
TArray< int32 > DecalNumToSpawn
How many decals (or material instances) of each, should be applied to the road.
float DecalMinScale
Min scale to be applied to the decals.
FVector ReadVectorFromJsonObject(TSharedPtr< FJsonObject > JsonObject)
Function to read 3D vectors from a JSON file.
void ReadConfigFile(const FString &CurrentMapName, const TMap< FString, FString > &DecalNamesMap)
Function for reading the decals configuration file (in JSON format)
float RandomOffset
Random offset from one decal to another.
FVector DecalScale
Scale of each decal on the road.