From 1f1c2798b2553388ed8851cd5b78e5d2cf6cc2d7 Mon Sep 17 00:00:00 2001 From: Roel Algaba Brizuela Date: Wed, 3 Mar 2021 11:04:04 +0100 Subject: [PATCH] Updated make import to apply RoadPainter materials --- .../PrepareAssetsForCookingCommandlet.cpp | 34 +++++++++-- .../PrepareAssetsForCookingCommandlet.h | 10 +++- .../Source/Carla/Util/RoadPainterWrapper.cpp | 11 ++++ .../Source/Carla/Util/RoadPainterWrapper.h | 56 +++++++++++++++++++ 4 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.cpp create mode 100644 Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.h diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/PrepareAssetsForCookingCommandlet.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/PrepareAssetsForCookingCommandlet.cpp index 1c98f0d47..e26f57b22 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/PrepareAssetsForCookingCommandlet.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/PrepareAssetsForCookingCommandlet.cpp @@ -11,6 +11,7 @@ #endif #include "HAL/PlatformFilemanager.h" #include "UObject/ConstructorHelpers.h" +#include "Materials/MaterialInstanceConstant.h" static bool ValidateStaticMesh(UStaticMesh *Mesh) { @@ -50,19 +51,32 @@ UPrepareAssetsForCookingCommandlet::UPrepareAssetsForCookingCommandlet() // Carla materials static ConstructorHelpers::FObjectFinder MarkingNode(TEXT( "Material'/Game/Carla/Static/GenericMaterials/LaneMarking/M_MarkingLane_W.M_MarkingLane_W'")); - static ConstructorHelpers::FObjectFinder RoadNode(TEXT( - "Material'/Game/Carla/Static/GenericMaterials/Masters/LowComplexity/M_Road1.M_Road1'")); + static ConstructorHelpers::FObjectFinder RoadNode(TEXT( + "MaterialInstanceConstant'/Game/Carla/Static/GenericMaterials/RoadPainterMaterials/M_Road_03.M_Road_03'")); + if (RoadNode.Object == NULL) { + + static ConstructorHelpers::FObjectFinder RoadNode(TEXT( + "Material'/Game/Carla/Static/GenericMaterials/Masters/LowComplexity/M_Road1.M_Road1'")); + RoadNodeMaterial = (UMaterial *)RoadNode.Object; + } + else { + + RoadNodeMaterialInstance = (UMaterialInstance *)RoadNode.Object; + } + static ConstructorHelpers::FObjectFinder RoadNodeAux(TEXT( "Material'/Game/Carla/Static/GenericMaterials/LaneMarking/M_MarkingLane_Y.M_MarkingLane_Y'")); static ConstructorHelpers::FObjectFinder TerrainNodeMaterial(TEXT( "Material'/Game/Carla/Static/GenericMaterials/Grass/M_Grass01.M_Grass01'")); static ConstructorHelpers::FObjectFinder SidewalkNode(TEXT( "Material'/Game/Carla/Static/GenericMaterials/CheapMaterials/M_SideWalkCheap01'")); + static ConstructorHelpers::FObjectFinder RoadPainterBlueprint(TEXT( + "Blueprint'/Game/Carla/Blueprints/LevelDesign/RoadPainterPreset.RoadPainterPreset_C'")); MarkingNodeMaterial = (UMaterial *) MarkingNode.Object; - RoadNodeMaterial = (UMaterial *) RoadNode.Object; MarkingNodeMaterialAux = (UMaterial *) RoadNodeAux.Object; SidewalkNodeMaterial = (UMaterial *) SidewalkNode.Object; + RoadPainterSubclass = RoadPainterBlueprint.Object; #endif } #if WITH_EDITORONLY_DATA @@ -171,6 +185,10 @@ TArray UPrepareAssetsForCookingCommandlet::SpawnMeshesToWorl SpawnedMeshes.Add(MeshActor); + ARoadPainterWrapper *RoadPainterBp = World->SpawnActor(RoadPainterSubclass); + RoadPainterBp->PaintAllRoadsEvent(); + RoadPainterBp->Destroy(); + if (bUseCarlaMaterials) { // Set Carla Materials depending on RoadRunner's Semantic Segmentation @@ -182,7 +200,15 @@ TArray UPrepareAssetsForCookingCommandlet::SpawnMeshesToWorl } else if (AssetName.Contains(SSTags::R_ROAD1) || AssetName.Contains(SSTags::R_ROAD2)) { - MeshActor->GetStaticMeshComponent()->SetMaterial(0, RoadNodeMaterial); + + if(RoadNodeMaterialInstance != NULL){ + + MeshActor->GetStaticMeshComponent()->SetMaterial(0, RoadNodeMaterialInstance); + } + else { + + MeshActor->GetStaticMeshComponent()->SetMaterial(0, RoadNodeMaterial); + } } else if (AssetName.Contains(SSTags::R_TERRAIN)) { diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/PrepareAssetsForCookingCommandlet.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/PrepareAssetsForCookingCommandlet.h index 22d17212f..4fb1fdf1c 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/PrepareAssetsForCookingCommandlet.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/PrepareAssetsForCookingCommandlet.h @@ -9,7 +9,7 @@ #include "Carla/OpenDrive/OpenDriveActor.h" #include "Commandlets/Commandlet.h" #include "Runtime/Engine/Classes/Engine/ObjectLibrary.h" - +#include "Util/RoadPainterWrapper.h" #include "Runtime/Engine/Classes/Engine/StaticMeshActor.h" #include "PrepareAssetsForCookingCommandlet.generated.h" @@ -153,6 +153,10 @@ private: UPROPERTY() UMaterial *MarkingNodeMaterial; + /// Material used by RoadPainter + UPROPERTY() + UMaterialInstance *RoadNodeMaterialInstance; + /// Workaround material for the RoadNode mesh UPROPERTY() UMaterial *RoadNodeMaterial; @@ -169,6 +173,10 @@ private: UPROPERTY() UMaterial *SidewalkNodeMaterial; + /// Subclass for acquiring the RoadPainter blueprint + UPROPERTY() + TSubclassOf RoadPainterSubclass; + /// Saves @a Package in .umap format in path @a PackagePath inside Unreal /// Content folder bool SavePackage(const FString &PackagePath, UPackage *Package) const; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.cpp new file mode 100644 index 000000000..d16c2f0c2 --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.cpp @@ -0,0 +1,11 @@ +// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma +// de Barcelona (UAB). +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#include "RoadPainterWrapper.h" + +ARoadPainterWrapper::ARoadPainterWrapper(){ + +} \ No newline at end of file diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.h new file mode 100644 index 000000000..9f794c86d --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/RoadPainterWrapper.h @@ -0,0 +1,56 @@ +// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma +// de Barcelona (UAB). +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "GameFramework/Actor.h" +#include "RoadPainterWrapper.generated.h" + +UCLASS() +class CARLA_API ARoadPainterWrapper : public AActor +{ + GENERATED_BODY() + +public: + + ARoadPainterWrapper(); + + UFUNCTION(BlueprintImplementableEvent, Category = "ARoadPainterWrapper") + void ZSizeEvent(); + + //Paint events + UFUNCTION(BlueprintImplementableEvent, Category = "ARoadPainterWrapper") + void PaintByActorEvent(); + + UFUNCTION(BlueprintImplementableEvent, Category = "ARoadPainterWrapper") + void PaintOverSquareEvent(); + + UFUNCTION(BlueprintImplementableEvent, Category = "ARoadPainterWrapper") + void PaintOverCircleEvent(); + + UFUNCTION(BlueprintImplementableEvent, Category = "ARoadPainterWrapper") + void PaintAllRoadsEvent(); + + //Spawn events + UFUNCTION(BlueprintImplementableEvent, Category = "ARoadPainterWrapper") + void SpawnMeshesByActorEvent(); + + UFUNCTION(BlueprintImplementableEvent, Category = "ARoadPainterWrapper") + void SpawnMeshesEvent(); + + UFUNCTION(BlueprintImplementableEvent, Category = "ARoadPainterWrapper") + void SpawnDecalsEvent(); + + //Clear events + UFUNCTION(BlueprintImplementableEvent, Category = "ARoadPainterWrapper") + void ClearMaterialEvent(); + + UFUNCTION(BlueprintImplementableEvent, Category = "ARoadPainterWrapper") + void ClearMaterialByActorEvent(); + + UFUNCTION(BlueprintImplementableEvent, Category = "ARoadPainterWrapper") + void ClearAllEvent(); +};