Updated make import to apply RoadPainter materials

This commit is contained in:
Roel Algaba Brizuela 2021-03-03 11:04:04 +01:00 committed by bernat
parent 69a0da33a4
commit 1f1c2798b2
4 changed files with 106 additions and 5 deletions

View File

@ -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<UMaterial> MarkingNode(TEXT(
"Material'/Game/Carla/Static/GenericMaterials/LaneMarking/M_MarkingLane_W.M_MarkingLane_W'"));
static ConstructorHelpers::FObjectFinder<UMaterial> RoadNode(TEXT(
"Material'/Game/Carla/Static/GenericMaterials/Masters/LowComplexity/M_Road1.M_Road1'"));
static ConstructorHelpers::FObjectFinder<UMaterialInstanceConstant> RoadNode(TEXT(
"MaterialInstanceConstant'/Game/Carla/Static/GenericMaterials/RoadPainterMaterials/M_Road_03.M_Road_03'"));
if (RoadNode.Object == NULL) {
static ConstructorHelpers::FObjectFinder<UMaterial> 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<UMaterial> RoadNodeAux(TEXT(
"Material'/Game/Carla/Static/GenericMaterials/LaneMarking/M_MarkingLane_Y.M_MarkingLane_Y'"));
static ConstructorHelpers::FObjectFinder<UMaterial> TerrainNodeMaterial(TEXT(
"Material'/Game/Carla/Static/GenericMaterials/Grass/M_Grass01.M_Grass01'"));
static ConstructorHelpers::FObjectFinder<UMaterial> SidewalkNode(TEXT(
"Material'/Game/Carla/Static/GenericMaterials/CheapMaterials/M_SideWalkCheap01'"));
static ConstructorHelpers::FObjectFinder<UClass> 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<AStaticMeshActor *> UPrepareAssetsForCookingCommandlet::SpawnMeshesToWorl
SpawnedMeshes.Add(MeshActor);
ARoadPainterWrapper *RoadPainterBp = World->SpawnActor<ARoadPainterWrapper>(RoadPainterSubclass);
RoadPainterBp->PaintAllRoadsEvent();
RoadPainterBp->Destroy();
if (bUseCarlaMaterials)
{
// Set Carla Materials depending on RoadRunner's Semantic Segmentation
@ -182,7 +200,15 @@ TArray<AStaticMeshActor *> 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))
{

View File

@ -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<ARoadPainterWrapper> RoadPainterSubclass;
/// Saves @a Package in .umap format in path @a PackagePath inside Unreal
/// Content folder
bool SavePackage(const FString &PackagePath, UPackage *Package) const;

View File

@ -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 <https://opensource.org/licenses/MIT>.
#include "RoadPainterWrapper.h"
ARoadPainterWrapper::ARoadPainterWrapper(){
}

View File

@ -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 <https://opensource.org/licenses/MIT>.
#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();
};