Merge remote-tracking branch 'origin/dev' into xisco
This commit is contained in:
commit
cb41a9b371
|
@ -0,0 +1,9 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#include "Carla.h"
|
||||
#include "WalkerAIController.h"
|
||||
|
||||
#include "Navigation/CrowdFollowingComponent.h"
|
||||
|
||||
AWalkerAIController::AWalkerAIController(const FObjectInitializer& ObjectInitializer)
|
||||
: Super(ObjectInitializer.SetDefaultSubobjectClass<UCrowdFollowingComponent>(TEXT("PathFollowingComponent"))) {}
|
|
@ -0,0 +1,16 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AIController.h"
|
||||
#include "WalkerAIController.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class CARLA_API AWalkerAIController : public AAIController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
AWalkerAIController(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
|
||||
};
|
|
@ -0,0 +1,13 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Engine/TargetPoint.h"
|
||||
#include "WalkerSpawnPoint.generated.h"
|
||||
|
||||
/// Used to set spawner locations for walkers in the level.
|
||||
UCLASS()
|
||||
class CARLA_API AWalkerSpawnPoint : public ATargetPoint
|
||||
{
|
||||
GENERATED_BODY()
|
||||
};
|
|
@ -0,0 +1,142 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#include "Carla.h"
|
||||
#include "WalkerSpawnerBase.h"
|
||||
|
||||
#include "Components/BoxComponent.h"
|
||||
#include "EngineUtils.h"
|
||||
#include "GameFramework/Character.h"
|
||||
|
||||
#include "WalkerAIController.h"
|
||||
#include "WalkerSpawnPoint.h"
|
||||
|
||||
// =============================================================================
|
||||
// -- Static local methods -----------------------------------------------------
|
||||
// =============================================================================
|
||||
|
||||
static AWalkerAIController *GetController(ACharacter *Walker)
|
||||
{
|
||||
return (Walker != nullptr ? Cast<AWalkerAIController>(Walker->GetController()) : nullptr);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// -- Constructor and destructor -----------------------------------------------
|
||||
// =============================================================================
|
||||
|
||||
AWalkerSpawnerBase::AWalkerSpawnerBase(const FObjectInitializer& ObjectInitializer) :
|
||||
Super(ObjectInitializer),
|
||||
RandomStream(Seed)
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
PrimaryActorTick.TickGroup = TG_PrePhysics;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// -- Overriden from AActor ----------------------------------------------------
|
||||
// =============================================================================
|
||||
|
||||
void AWalkerSpawnerBase::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
// Allocate space for walkers.
|
||||
Walkers.Reserve(NumberOfWalkers);
|
||||
|
||||
// Set seed for random numbers.
|
||||
if (!bUseFixedSeed) {
|
||||
RandomStream.GenerateNewSeed();
|
||||
} else {
|
||||
RandomStream.Initialize(Seed);
|
||||
}
|
||||
|
||||
// Find spawn points present in level.
|
||||
for (TActorIterator<AWalkerSpawnPoint> It(GetWorld()); It; ++It) {
|
||||
SpawnPoints.Add(*It);
|
||||
}
|
||||
UE_LOG(LogCarla, Log, TEXT("Found %d positions for spawning walkers"), SpawnPoints.Num());
|
||||
|
||||
if (SpawnPoints.Num() < 2) {
|
||||
bSpawnWalkers = false;
|
||||
UE_LOG(LogCarla, Error, TEXT("We don't have enough spawn points for walkers!"));
|
||||
}
|
||||
}
|
||||
|
||||
void AWalkerSpawnerBase::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
if (bSpawnWalkers && (NumberOfWalkers > Walkers.Num())) {
|
||||
// Try to spawn one walker.
|
||||
TryToSpawnRandomWalker();
|
||||
}
|
||||
|
||||
if (Walkers.Num() > 0) {
|
||||
// Check one walker and kill it if necessary.
|
||||
const int32 Index = (++CurrentIndexToCheck % Walkers.Num());
|
||||
auto Walker = Walkers[Index];
|
||||
auto Controller = GetController(Walker);
|
||||
if ((Controller == nullptr) || (Controller->GetMoveStatus() != EPathFollowingStatus::Moving)) {
|
||||
Walkers.RemoveAtSwap(Index);
|
||||
if (Walker != nullptr) {
|
||||
Walker->Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// -- Other member functions ---------------------------------------------------
|
||||
// =============================================================================
|
||||
|
||||
void AWalkerSpawnerBase::SetNumberOfWalkers(const int32 Count)
|
||||
{
|
||||
if (Count > 0) {
|
||||
bSpawnWalkers = true;
|
||||
NumberOfWalkers = Count;
|
||||
} else {
|
||||
bSpawnWalkers = false;
|
||||
}
|
||||
}
|
||||
|
||||
void AWalkerSpawnerBase::TryToSpawnRandomWalker()
|
||||
{
|
||||
auto SpawnPoint = GetRandomSpawnPoint();
|
||||
auto DestinationPoint = GetRandomSpawnPoint();
|
||||
if ((SpawnPoint != nullptr) && (DestinationPoint != nullptr)) {
|
||||
const auto StraightDistance =
|
||||
DestinationPoint->GetActorLocation() -
|
||||
SpawnPoint->GetActorLocation();
|
||||
if (StraightDistance.Size() >= MinimumWalkDistance) {
|
||||
SpawnWalkerAtSpawnPoint(*SpawnPoint, DestinationPoint->GetActorLocation());
|
||||
}
|
||||
} else {
|
||||
UE_LOG(LogCarla, Error, TEXT("Unable to find spawn point"));
|
||||
}
|
||||
}
|
||||
|
||||
void AWalkerSpawnerBase::SpawnWalkerAtSpawnPoint(
|
||||
const AWalkerSpawnPoint &SpawnPoint,
|
||||
const FVector &Destination)
|
||||
{
|
||||
ACharacter *Walker;
|
||||
SpawnWalker(SpawnPoint.GetActorTransform(), Walker);
|
||||
if ((Walker != nullptr) && !Walker->IsPendingKill()) {
|
||||
Walker->AIControllerClass = AWalkerAIController::StaticClass();
|
||||
Walker->SpawnDefaultController();
|
||||
auto Controller = GetController(Walker);
|
||||
if (Controller != nullptr) { // Sometimes fails...
|
||||
Controller->MoveToLocation(Destination);
|
||||
Walkers.Add(Walker);
|
||||
} else {
|
||||
UE_LOG(LogCarla, Error, TEXT("Something went wrong creating the controller for the new walker"));
|
||||
Walker->Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AWalkerSpawnPoint *AWalkerSpawnerBase::GetRandomSpawnPoint() const
|
||||
{
|
||||
return (SpawnPoints.Num() > 0 ?
|
||||
SpawnPoints[RandomStream.RandRange(0, SpawnPoints.Num() - 1)] :
|
||||
nullptr);
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "WalkerSpawnerBase.generated.h"
|
||||
|
||||
class AWalkerSpawnPoint;
|
||||
class UBoxComponent;
|
||||
|
||||
/// Base class for spawning walkers. Implement SpawnWalker in derived
|
||||
/// blueprints.
|
||||
///
|
||||
/// Walkers are spawned at a random AWalkerSpawnPoint present in the level, and
|
||||
/// walk until its destination is reached at another random AWalkerSpawnPoint.
|
||||
UCLASS(Abstract)
|
||||
class CARLA_API AWalkerSpawnerBase : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
// ===========================================================================
|
||||
/// @name Constructor and destructor
|
||||
// ===========================================================================
|
||||
/// @{
|
||||
public:
|
||||
|
||||
AWalkerSpawnerBase(const FObjectInitializer& ObjectInitializer);
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
/// @name Overriden from AActor
|
||||
// ===========================================================================
|
||||
/// @{
|
||||
protected:
|
||||
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
/// @name Blueprintable functions
|
||||
// ===========================================================================
|
||||
/// @{
|
||||
protected:
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
const FRandomStream &GetRandomStream() const
|
||||
{
|
||||
return RandomStream;
|
||||
}
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void SpawnWalker(const FTransform &SpawnTransform, ACharacter *&SpawnedCharacter);
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
/// @name Other member functions
|
||||
// ===========================================================================
|
||||
/// @{
|
||||
public:
|
||||
|
||||
void SetNumberOfWalkers(int32 Count);
|
||||
|
||||
private:
|
||||
|
||||
void TryToSpawnRandomWalker();
|
||||
|
||||
void SpawnWalkerAtSpawnPoint(const AWalkerSpawnPoint &SpawnPoint, const FVector &Destination);
|
||||
|
||||
AWalkerSpawnPoint *GetRandomSpawnPoint() const;
|
||||
|
||||
/// @}
|
||||
|
||||
private:
|
||||
|
||||
/** If false, no walker will be spawned. */
|
||||
UPROPERTY(Category = "Walker Spawner", EditAnywhere)
|
||||
bool bSpawnWalkers = true;
|
||||
|
||||
/** Number of walkers to be present within the volume. */
|
||||
UPROPERTY(Category = "Walker Spawner", EditAnywhere, meta = (EditCondition = bSpawnWalkers, ClampMin = "1"))
|
||||
int32 NumberOfWalkers = 10;
|
||||
|
||||
/** Minimum walk distance in centimeters. */
|
||||
UPROPERTY(Category = "Walker Spawner", EditAnywhere, meta = (EditCondition = bSpawnWalkers))
|
||||
float MinimumWalkDistance = 1500.0f;
|
||||
|
||||
/** If false, a random seed is generated each time. */
|
||||
UPROPERTY(Category = "Walker Spawner", EditAnywhere, meta = (EditCondition = bSpawnWalkers))
|
||||
bool bUseFixedSeed = true;
|
||||
|
||||
/** Seed for spawning random walkers. */
|
||||
UPROPERTY(Category = "Walker Spawner", EditAnywhere, meta = (EditCondition = bUseFixedSeed))
|
||||
int32 Seed = 123456789;
|
||||
|
||||
UPROPERTY()
|
||||
FRandomStream RandomStream;
|
||||
|
||||
UPROPERTY(Category = "Walker Spawner", VisibleAnywhere, AdvancedDisplay)
|
||||
TArray<AWalkerSpawnPoint *> SpawnPoints;
|
||||
|
||||
UPROPERTY(Category = "Walker Spawner", VisibleAnywhere, AdvancedDisplay)
|
||||
TArray<ACharacter *> Walkers;
|
||||
|
||||
uint32 CurrentIndexToCheck = 0u;
|
||||
};
|
|
@ -30,11 +30,12 @@ public class Carla : ModuleRules
|
|||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"AIModule",
|
||||
"CoreUObject",
|
||||
"Engine",
|
||||
"PhysXVehicles",
|
||||
"Slate",
|
||||
"SlateCore",
|
||||
"PhysXVehicles"
|
||||
"SlateCore"
|
||||
// ... add private dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
|
|
|
@ -26,10 +26,8 @@ static bool CheckWeatherValidity(const FWeatherDescription &Weather)
|
|||
return true;
|
||||
}
|
||||
|
||||
TArray<FWeatherDescription> ADynamicWeather::LoadWeatherDescriptionsFromFile()
|
||||
void ADynamicWeather::LoadWeatherDescriptionsFromFile(TArray<FWeatherDescription> &Descriptions)
|
||||
{
|
||||
TArray<FWeatherDescription> Descriptions;
|
||||
|
||||
// Try to load config file.
|
||||
FString FileName;
|
||||
if (GetWeatherIniFileName(FileName)) {
|
||||
|
@ -46,9 +44,8 @@ TArray<FWeatherDescription> ADynamicWeather::LoadWeatherDescriptionsFromFile()
|
|||
if (Descriptions.Num() == 0) {
|
||||
UE_LOG(LogCarla, Warning, TEXT("No weather description found"));
|
||||
Descriptions.AddDefaulted(1u);
|
||||
Descriptions.Last().Name = TEXT("Default");
|
||||
}
|
||||
|
||||
return Descriptions;
|
||||
}
|
||||
|
||||
ADynamicWeather::ADynamicWeather(const FObjectInitializer& ObjectInitializer)
|
||||
|
|
|
@ -15,8 +15,8 @@ class CARLA_API ADynamicWeather : public AActor
|
|||
|
||||
public:
|
||||
|
||||
/// If none is found return the default one.
|
||||
static TArray<FWeatherDescription> LoadWeatherDescriptionsFromFile();
|
||||
/// If none is found, the default one is added.
|
||||
static void LoadWeatherDescriptionsFromFile(TArray<FWeatherDescription> &Descriptions);
|
||||
|
||||
ADynamicWeather(const FObjectInitializer& ObjectInitializer);
|
||||
|
||||
|
@ -62,17 +62,17 @@ private:
|
|||
#endif // WITH_EDITOR
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
|
||||
UPROPERTY()
|
||||
UArrowComponent *ArrowComponent;
|
||||
#endif // WITH_EDITORONLY_DATA
|
||||
|
||||
#if WITH_EDITOR
|
||||
UPROPERTY(Category = "Weather Description", EditAnywhere)
|
||||
bool bLoadFromConfigFile = false;
|
||||
|
||||
UPROPERTY(Category = "Weather Description", EditAnywhere)
|
||||
bool bSaveToConfigFile = false;
|
||||
#endif // WITH_EDITOR
|
||||
|
||||
#endif // WITH_EDITORONLY_DATA
|
||||
|
||||
UPROPERTY(Category = "Weather Description", EditAnywhere)
|
||||
FWeatherDescription Weather;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
USTRUCT()
|
||||
struct FCameraDescription
|
||||
{
|
||||
GENERATED_BODY()
|
||||
GENERATED_USTRUCT_BODY()
|
||||
|
||||
/** X size in pixels of the captured image. */
|
||||
UPROPERTY(Category = "Camera Description", EditDefaultsOnly, meta=(ClampMin = "1"))
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
USTRUCT()
|
||||
struct FCapturedImage
|
||||
{
|
||||
GENERATED_BODY()
|
||||
GENERATED_USTRUCT_BODY()
|
||||
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
uint32 SizeX = 0u;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#include "Carla.h"
|
||||
#include "CarlaGameMode.h"
|
||||
#include "CarlaGameModeBase.h"
|
||||
|
||||
#include "Engine/PlayerStartPIE.h"
|
||||
#include "EngineUtils.h"
|
||||
|
@ -14,9 +14,10 @@
|
|||
#include "CarlaSettings.h"
|
||||
#include "CarlaVehicleController.h"
|
||||
#include "Tagger.h"
|
||||
#include "TaggerDelegate.h"
|
||||
|
||||
ACarlaGameMode::ACarlaGameMode() :
|
||||
Super(),
|
||||
ACarlaGameModeBase::ACarlaGameModeBase(const FObjectInitializer& ObjectInitializer) :
|
||||
Super(ObjectInitializer),
|
||||
GameController(nullptr),
|
||||
PlayerController(nullptr)
|
||||
{
|
||||
|
@ -27,9 +28,11 @@ ACarlaGameMode::ACarlaGameMode() :
|
|||
GameStateClass = ACarlaGameState::StaticClass();
|
||||
PlayerStateClass = ACarlaPlayerState::StaticClass();
|
||||
HUDClass = ACarlaHUD::StaticClass();
|
||||
|
||||
TaggerDelegate = CreateDefaultSubobject<UTaggerDelegate>(TEXT("TaggerDelegate"));
|
||||
}
|
||||
|
||||
void ACarlaGameMode::InitGame(
|
||||
void ACarlaGameModeBase::InitGame(
|
||||
const FString &MapName,
|
||||
const FString &Options,
|
||||
FString &ErrorMessage)
|
||||
|
@ -44,9 +47,23 @@ 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!"));
|
||||
}
|
||||
|
||||
if (DynamicWeatherClass != nullptr) {
|
||||
DynamicWeather = GetWorld()->SpawnActor<ADynamicWeather>(DynamicWeatherClass);
|
||||
}
|
||||
|
||||
if (WalkerSpawnerClass != nullptr) {
|
||||
WalkerSpawner = GetWorld()->SpawnActor<AWalkerSpawnerBase>(WalkerSpawnerClass);
|
||||
}
|
||||
}
|
||||
|
||||
void ACarlaGameMode::RestartPlayer(AController* NewPlayer)
|
||||
void ACarlaGameModeBase::RestartPlayer(AController* NewPlayer)
|
||||
{
|
||||
check(NewPlayer != nullptr);
|
||||
TArray<APlayerStart *> UnOccupiedStartPoints;
|
||||
|
@ -67,22 +84,40 @@ void ACarlaGameMode::RestartPlayer(AController* NewPlayer)
|
|||
UE_LOG(LogCarla, Error, TEXT("No start spot found!"));
|
||||
}
|
||||
|
||||
void ACarlaGameMode::BeginPlay()
|
||||
void ACarlaGameModeBase::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
if (GameInstance->GetCarlaSettings().bSemanticSegmentationEnabled) {
|
||||
|
||||
const auto &CarlaSettings = GameInstance->GetCarlaSettings();
|
||||
|
||||
// Setup semantic segmentation if necessary.
|
||||
if (CarlaSettings.bSemanticSegmentationEnabled) {
|
||||
TagActorsForSemanticSegmentation();
|
||||
TaggerDelegate->SetSemanticSegmentationEnabled();
|
||||
}
|
||||
|
||||
// Change weather.
|
||||
if (DynamicWeather != nullptr) {
|
||||
const auto &Weather = CarlaSettings.GetActiveWeatherDescription();
|
||||
UE_LOG(LogCarla, Log, TEXT("Changing weather settings to \"%s\""), *Weather.Name);
|
||||
DynamicWeather->SetWeatherDescription(Weather);
|
||||
}
|
||||
|
||||
// Setup walkers.
|
||||
if (WalkerSpawner != nullptr) {
|
||||
WalkerSpawner->SetNumberOfWalkers(CarlaSettings.NumberOfPedestrians);
|
||||
}
|
||||
|
||||
GameController->BeginPlay();
|
||||
}
|
||||
|
||||
void ACarlaGameMode::Tick(float DeltaSeconds)
|
||||
void ACarlaGameModeBase::Tick(float DeltaSeconds)
|
||||
{
|
||||
Super::Tick(DeltaSeconds);
|
||||
GameController->Tick(DeltaSeconds);
|
||||
}
|
||||
|
||||
void ACarlaGameMode::RegisterPlayer(AController &NewPlayer)
|
||||
void ACarlaGameModeBase::RegisterPlayer(AController &NewPlayer)
|
||||
{
|
||||
check(GameController != nullptr);
|
||||
AddTickPrerequisiteActor(&NewPlayer);
|
||||
|
@ -91,7 +126,7 @@ void ACarlaGameMode::RegisterPlayer(AController &NewPlayer)
|
|||
AttachCaptureCamerasToPlayer(*PlayerController);
|
||||
}
|
||||
|
||||
void ACarlaGameMode::AttachCaptureCamerasToPlayer(AController &Player)
|
||||
void ACarlaGameModeBase::AttachCaptureCamerasToPlayer(AController &Player)
|
||||
{
|
||||
ACarlaVehicleController *Vehicle = Cast<ACarlaVehicleController>(&Player);
|
||||
if (Vehicle == nullptr) {
|
||||
|
@ -104,13 +139,13 @@ void ACarlaGameMode::AttachCaptureCamerasToPlayer(AController &Player)
|
|||
}
|
||||
}
|
||||
|
||||
void ACarlaGameMode::TagActorsForSemanticSegmentation()
|
||||
void ACarlaGameModeBase::TagActorsForSemanticSegmentation()
|
||||
{
|
||||
check(GetWorld() != nullptr);
|
||||
ATagger::TagActorsInLevel(*GetWorld(), true);
|
||||
}
|
||||
|
||||
APlayerStart *ACarlaGameMode::FindUnOccupiedStartPoints(
|
||||
APlayerStart *ACarlaGameModeBase::FindUnOccupiedStartPoints(
|
||||
AController *Player,
|
||||
TArray<APlayerStart *> &UnOccupiedStartPoints)
|
||||
{
|
|
@ -3,23 +3,26 @@
|
|||
#pragma once
|
||||
|
||||
#include "GameFramework/GameModeBase.h"
|
||||
#include "AI/WalkerSpawnerBase.h"
|
||||
#include "CarlaGameControllerBase.h"
|
||||
#include "CarlaGameMode.generated.h"
|
||||
#include "DynamicWeather.h"
|
||||
#include "CarlaGameModeBase.generated.h"
|
||||
|
||||
class APlayerStart;
|
||||
class ASceneCaptureCamera;
|
||||
class UTaggerDelegate;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class CARLA_API ACarlaGameMode : public AGameModeBase
|
||||
class CARLA_API ACarlaGameModeBase : public AGameModeBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
ACarlaGameMode();
|
||||
ACarlaGameModeBase(const FObjectInitializer& ObjectInitializer);
|
||||
|
||||
virtual void InitGame(const FString &MapName, const FString &Options, FString &ErrorMessage) override;
|
||||
|
||||
|
@ -29,6 +32,16 @@ public:
|
|||
|
||||
virtual void Tick(float DeltaSeconds) override;
|
||||
|
||||
protected:
|
||||
|
||||
/** The class of DynamicWeather to spawn. */
|
||||
UPROPERTY(Category = "CARLA Classes", EditAnywhere, BlueprintReadOnly)
|
||||
TSubclassOf<ADynamicWeather> DynamicWeatherClass;
|
||||
|
||||
/** The class of WalkerSpawner to spawn. */
|
||||
UPROPERTY(Category = "CARLA Classes", EditAnywhere, BlueprintReadOnly)
|
||||
TSubclassOf<AWalkerSpawnerBase> WalkerSpawnerClass;
|
||||
|
||||
private:
|
||||
|
||||
void RegisterPlayer(AController &NewPlayer);
|
||||
|
@ -52,4 +65,13 @@ private:
|
|||
|
||||
UPROPERTY()
|
||||
AController *PlayerController;
|
||||
|
||||
UPROPERTY()
|
||||
UTaggerDelegate *TaggerDelegate;
|
||||
|
||||
UPROPERTY()
|
||||
ADynamicWeather *DynamicWeather;
|
||||
|
||||
UPROPERTY()
|
||||
AWalkerSpawnerBase *WalkerSpawner;
|
||||
};
|
|
@ -4,10 +4,12 @@
|
|||
#include "CarlaSettings.h"
|
||||
|
||||
#include "CommandLine.h"
|
||||
#include "DynamicWeather.h"
|
||||
#include "IniFile.h"
|
||||
|
||||
// INI file sections.
|
||||
#define S_CARLA_SERVER TEXT("CARLA/Server")
|
||||
#define S_CARLA_LEVELSETTINGS TEXT("CARLA/LevelSettings")
|
||||
#define S_CARLA_SCENECAPTURE TEXT("CARLA/SceneCapture")
|
||||
|
||||
// =============================================================================
|
||||
|
@ -81,6 +83,17 @@ static void LoadSettingsFromFile(const FString &FileName, UCarlaSettings &Settin
|
|||
ConfigFile.GetInt(S_CARLA_SERVER, TEXT("WorldPort"), Settings.WorldPort);
|
||||
ConfigFile.GetInt(S_CARLA_SERVER, TEXT("WritePort"), Settings.WritePort);
|
||||
ConfigFile.GetInt(S_CARLA_SERVER, TEXT("ReadPort"), Settings.ReadPort);
|
||||
// LevelSettings.
|
||||
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("NumberOfVehicles"), Settings.NumberOfVehicles);
|
||||
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("NumberOfPedestrians"), Settings.NumberOfPedestrians);
|
||||
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("WeatherId"), Settings.WeatherId);
|
||||
Settings.WeatherDescriptions.Empty();
|
||||
ADynamicWeather::LoadWeatherDescriptionsFromFile(Settings.WeatherDescriptions);
|
||||
check(Settings.WeatherDescriptions.Num() > 0);
|
||||
if (static_cast<int32>(Settings.WeatherId) >= Settings.WeatherDescriptions.Num()) {
|
||||
UE_LOG(LogCarla, Error, TEXT("Provided weather id %d cannot be found"), Settings.WeatherId);
|
||||
Settings.WeatherId = 0u;
|
||||
}
|
||||
// SceneCapture.
|
||||
FString Cameras;
|
||||
ConfigFile.GetString(S_CARLA_SCENECAPTURE, TEXT("Cameras"), Cameras);
|
||||
|
@ -152,13 +165,21 @@ void UCarlaSettings::LogSettings() const
|
|||
UE_LOG(LogCarla, Log, TEXT("== CARLA Settings =============================================================="));
|
||||
UE_LOG(LogCarla, Log, TEXT("Settings file: %s"), *CurrentFileName);
|
||||
UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_SERVER);
|
||||
UE_LOG(LogCarla, Log, TEXT("Use Networking = %s"), (bUseNetworking ? TEXT("true") : TEXT("false")));
|
||||
UE_LOG(LogCarla, Log, TEXT("Use Networking = %s"), (bUseNetworking ? TEXT("True") : TEXT("False")));
|
||||
UE_LOG(LogCarla, Log, TEXT("World Port = %d"), WorldPort);
|
||||
UE_LOG(LogCarla, Log, TEXT("Write Port = %d"), WritePort);
|
||||
UE_LOG(LogCarla, Log, TEXT("Read Port = %d"), ReadPort);
|
||||
UE_LOG(LogCarla, Log, TEXT("Read Port = %d"), ReadPort);
|
||||
UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_LEVELSETTINGS);
|
||||
UE_LOG(LogCarla, Log, TEXT("Number Of Vehicles = %d"), NumberOfVehicles);
|
||||
UE_LOG(LogCarla, Log, TEXT("Number Of Pedestrians = %d"), NumberOfPedestrians);
|
||||
UE_LOG(LogCarla, Log, TEXT("Weather Id = %d"), WeatherId);
|
||||
UE_LOG(LogCarla, Log, TEXT("Found %d available weather settings."), WeatherDescriptions.Num());
|
||||
for (auto i = 0; i < WeatherDescriptions.Num(); ++i) {
|
||||
UE_LOG(LogCarla, Log, TEXT(" * %d - %s"), i, *WeatherDescriptions[i].Name);
|
||||
}
|
||||
UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_SCENECAPTURE);
|
||||
UE_LOG(LogCarla, Log, TEXT("Added %d cameras."), CameraDescriptions.Num());
|
||||
UE_LOG(LogCarla, Log, TEXT("Semantic Segmentation = %s"), (bSemanticSegmentationEnabled ? TEXT("enabled") : TEXT("disabled")));
|
||||
UE_LOG(LogCarla, Log, TEXT("Semantic Segmentation = %s"), (bSemanticSegmentationEnabled ? TEXT("Enabled") : TEXT("Disabled")));
|
||||
for (auto &Item : CameraDescriptions) {
|
||||
UE_LOG(LogCarla, Log, TEXT("[%s/%s]"), S_CARLA_SCENECAPTURE, *Item.Key);
|
||||
UE_LOG(LogCarla, Log, TEXT("Image Size = %dx%d"), Item.Value.ImageSizeX, Item.Value.ImageSizeY);
|
||||
|
@ -170,4 +191,5 @@ void UCarlaSettings::LogSettings() const
|
|||
}
|
||||
|
||||
#undef S_CARLA_SERVER
|
||||
#undef S_CARLA_LEVELSETTINGS
|
||||
#undef S_CARLA_SCENECAPTURE
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "UObject/NoExportTypes.h"
|
||||
#include "CameraDescription.h"
|
||||
#include "WeatherDescription.h"
|
||||
|
||||
#include "UObject/NoExportTypes.h"
|
||||
#include "CarlaSettings.generated.h"
|
||||
|
||||
/// Global settings for CARLA.
|
||||
|
@ -20,6 +22,11 @@ public:
|
|||
/** Log settings values. */
|
||||
void LogSettings() const;
|
||||
|
||||
const FWeatherDescription &GetActiveWeatherDescription() const
|
||||
{
|
||||
return WeatherDescriptions[WeatherId];
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** File name of the settings file used to load this settings. Empty if none used. */
|
||||
|
@ -48,6 +55,29 @@ public:
|
|||
UPROPERTY(Category = "CARLA Server", EditDefaultsOnly, meta = (EditCondition = bUseNetworking))
|
||||
uint32 ReadPort = 2002u;
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
/// @name Level Settings
|
||||
// ===========================================================================
|
||||
/// @{
|
||||
public:
|
||||
|
||||
/** Number of NPC vehicles to be spawned into the level. */
|
||||
UPROPERTY(Category = "Level Settings", EditDefaultsOnly)
|
||||
uint32 NumberOfVehicles = 5u;
|
||||
|
||||
/** Number of NPC pedestrians to be spawned into the level. */
|
||||
UPROPERTY(Category = "Level Settings", EditDefaultsOnly)
|
||||
uint32 NumberOfPedestrians = 15u;
|
||||
|
||||
/** Index of the weather setting to use. */
|
||||
UPROPERTY(Category = "Level Settings", EditDefaultsOnly)
|
||||
uint32 WeatherId = 0;
|
||||
|
||||
/** Available weather settings. */
|
||||
UPROPERTY(Category = "Level Settings", EditDefaultsOnly)
|
||||
TArray<FWeatherDescription> WeatherDescriptions;
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
/// @name Scene Capture
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
// 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);
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
|
|
@ -55,6 +55,10 @@ void FWeatherDescription::ReadFromConfigFile(const IniFile &ConfigFile, const FS
|
|||
LoadPrecipitationType(ConfigFile, *Section, TEXT("PrecipitationType"), PrecipitationType);
|
||||
CARLA_LOAD_FROM_INI(Float, PrecipitationAmount)
|
||||
CARLA_LOAD_FROM_INI(Float, PrecipitationAccumulation)
|
||||
// Wind.
|
||||
CARLA_LOAD_FROM_INI(Bool, bWind)
|
||||
CARLA_LOAD_FROM_INI(Float, WindIntensity)
|
||||
CARLA_LOAD_FROM_INI(Float, WindAngle)
|
||||
#undef CARLA_LOAD_FROM_INI
|
||||
}
|
||||
|
||||
|
@ -84,5 +88,9 @@ void FWeatherDescription::WriteToConfigFile(IniFile &ConfigFile) const
|
|||
ConfigFile.SetString(*Section, TEXT("PrecipitationType"), PrecipitationTypeToString(PrecipitationType));
|
||||
CARLA_WRITE_TO_INI(Float, PrecipitationAmount)
|
||||
CARLA_WRITE_TO_INI(Float, PrecipitationAccumulation)
|
||||
// Wind.
|
||||
CARLA_WRITE_TO_INI(Bool, bWind)
|
||||
CARLA_WRITE_TO_INI(Float, WindIntensity)
|
||||
CARLA_WRITE_TO_INI(Float, WindAngle)
|
||||
#undef CARLA_WRITE_TO_INI
|
||||
}
|
||||
|
|
|
@ -46,19 +46,19 @@ struct FWeatherDescription
|
|||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float SunBrightness;
|
||||
float SunBrightness = 50.0f;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float SunDirectionalLightIntensity;
|
||||
float SunDirectionalLightIntensity = 5.0f;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite)
|
||||
FLinearColor SunDirectionalLightColor;
|
||||
FLinearColor SunDirectionalLightColor = FLinearColor(255.0f, 240.0f, 195.0f);
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float SunIndirectLightIntensity;
|
||||
float SunIndirectLightIntensity = 6.0f;
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
|
@ -68,35 +68,35 @@ struct FWeatherDescription
|
|||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float CloudOpacity;
|
||||
float CloudOpacity = 10.0f;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float HorizontFalloff;
|
||||
float HorizontFalloff = 3.0f;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
|
||||
FLinearColor ZenithColor;
|
||||
FLinearColor ZenithColor = FLinearColor(0.0340f, 0.1092f, 0.2950f);
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
|
||||
FLinearColor HorizonColor;
|
||||
FLinearColor HorizonColor = FLinearColor(0.6599f, 0.8622f, 1.0f);
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
|
||||
FLinearColor CloudColor;
|
||||
FLinearColor CloudColor = FLinearColor(0.8558f, 0.9190f, 1.0f);
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
|
||||
FLinearColor OverallSkyColor;
|
||||
FLinearColor OverallSkyColor = FLinearColor(1.0f, 1.0f, 1.0f);
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float SkyLightIntensity;
|
||||
float SkyLightIntensity = 4.0f;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
|
||||
FLinearColor SkyLightColor;
|
||||
FLinearColor SkyLightColor = FLinearColor(0.1950f, 0.1851f, 0.1413f, 0.0f);
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
|
@ -114,11 +114,29 @@ struct FWeatherDescription
|
|||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Precipitation", EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bPrecipitation", ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float PrecipitationAmount = 0.0f;
|
||||
float PrecipitationAmount = 50.0f;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Precipitation", EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bPrecipitation", ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float PrecipitationAccumulation = 0.0f;
|
||||
float PrecipitationAccumulation = 50.0f;
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
/// @name Weather - Wind
|
||||
// ===========================================================================
|
||||
/// @{
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Wind", EditAnywhere, BlueprintReadWrite)
|
||||
bool bWind = false;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Wind", EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bWind", ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float WindIntensity = 20.0f;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Wind", EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bWind", ClampMin = "-180.0", ClampMax = "180.0"))
|
||||
float WindAngle = 0.0f;
|
||||
|
||||
/// @}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue