Automatically tag objects on spawn
This commit is contained in:
parent
a9bc99e733
commit
02959b085c
|
@ -14,9 +14,10 @@
|
|||
#include "CarlaSettings.h"
|
||||
#include "CarlaVehicleController.h"
|
||||
#include "Tagger.h"
|
||||
#include "TaggerDelegate.h"
|
||||
|
||||
ACarlaGameMode::ACarlaGameMode() :
|
||||
Super(),
|
||||
ACarlaGameMode::ACarlaGameMode(const FObjectInitializer& ObjectInitializer) :
|
||||
Super(ObjectInitializer),
|
||||
GameController(nullptr),
|
||||
PlayerController(nullptr)
|
||||
{
|
||||
|
@ -27,6 +28,8 @@ ACarlaGameMode::ACarlaGameMode() :
|
|||
GameStateClass = ACarlaGameState::StaticClass();
|
||||
PlayerStateClass = ACarlaPlayerState::StaticClass();
|
||||
HUDClass = ACarlaHUD::StaticClass();
|
||||
|
||||
TaggerDelegate = CreateDefaultSubobject<UTaggerDelegate>(TEXT("TaggerDelegate"));
|
||||
}
|
||||
|
||||
void ACarlaGameMode::InitGame(
|
||||
|
@ -44,6 +47,12 @@ void ACarlaGameMode::InitGame(
|
|||
GameController = &GameInstance->GetGameController();
|
||||
GameController->Initialize(GameInstance->GetCarlaSettings());
|
||||
GameInstance->GetCarlaSettings().LogSettings();
|
||||
|
||||
if (TaggerDelegate != nullptr) {
|
||||
TaggerDelegate->RegisterSpawnHandler(GetWorld());
|
||||
} else {
|
||||
UE_LOG(LogCarla, Error, TEXT("Missing TaggerDelegate!"));
|
||||
}
|
||||
}
|
||||
|
||||
void ACarlaGameMode::RestartPlayer(AController* NewPlayer)
|
||||
|
@ -72,6 +81,7 @@ void ACarlaGameMode::BeginPlay()
|
|||
Super::BeginPlay();
|
||||
if (GameInstance->GetCarlaSettings().bSemanticSegmentationEnabled) {
|
||||
TagActorsForSemanticSegmentation();
|
||||
TaggerDelegate->SetSemanticSegmentationEnabled();
|
||||
}
|
||||
GameController->BeginPlay();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#include "Carla.h"
|
||||
#include "TaggerDelegate.h"
|
||||
|
||||
#include "Engine/World.h"
|
||||
#include "Tagger.h"
|
||||
|
||||
UTaggerDelegate::UTaggerDelegate() :
|
||||
ActorSpawnedDelegate(FOnActorSpawned::FDelegate::CreateUObject(this, &UTaggerDelegate::OnActorSpawned)) {}
|
||||
|
||||
void UTaggerDelegate::RegisterSpawnHandler(UWorld *InWorld)
|
||||
{
|
||||
InWorld->AddOnActorSpawnedHandler(ActorSpawnedDelegate);
|
||||
}
|
||||
|
||||
void UTaggerDelegate::OnActorSpawned(AActor* InActor)
|
||||
{
|
||||
if (InActor != nullptr) {
|
||||
ATagger::TagActor(*InActor, bSemanticSegmentationEnabled);
|
||||
|
||||
TArray<ECityObjectLabel> Tags;
|
||||
ATagger::GetTagsOfTaggedActor(*InActor, Tags);
|
||||
UE_LOG(LogCarla, Warning, TEXT("Tagged recently spawned actor \"%s\""), *InActor->GetName());
|
||||
for (auto Tag : Tags) {
|
||||
UE_LOG(LogCarla, Warning, TEXT(" - %d"), (uint8)Tag);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "TaggerDelegate.generated.h"
|
||||
|
||||
/// Used to tag every actor that is spawned into the world.
|
||||
UCLASS()
|
||||
class CARLA_API UTaggerDelegate : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UTaggerDelegate();
|
||||
|
||||
void RegisterSpawnHandler(UWorld *World);
|
||||
|
||||
void SetSemanticSegmentationEnabled(bool Enable = true)
|
||||
{
|
||||
bSemanticSegmentationEnabled = Enable;
|
||||
}
|
||||
|
||||
void OnActorSpawned(AActor *Actor);
|
||||
|
||||
private:
|
||||
|
||||
FOnActorSpawned::FDelegate ActorSpawnedDelegate;
|
||||
|
||||
bool bSemanticSegmentationEnabled = false;
|
||||
};
|
|
@ -68,10 +68,10 @@ static void SetStencilValue(
|
|||
UPrimitiveComponent &Component,
|
||||
const ECityObjectLabel &Label,
|
||||
const bool bSetRenderCustomDepth) {
|
||||
Component.SetCustomDepthStencilValue(CastEnum(Label));
|
||||
Component.SetRenderCustomDepth(
|
||||
bSetRenderCustomDepth &&
|
||||
!ATagger::MatchComponent(Component, ECityObjectLabel::None));
|
||||
Component.SetCustomDepthStencilValue(CastEnum(Label));
|
||||
(Label != ECityObjectLabel::None));
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
|
Loading…
Reference in New Issue