Set up RootComponent in ASensor so we don't need to set it up on each individual sensor
This commit is contained in:
parent
7be45fc4a2
commit
cea948a7e1
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include "Carla.h"
|
||||
#include "Carla/Sensor/GnssSensor.h"
|
||||
#include "StaticMeshResources.h"
|
||||
|
||||
FActorDefinition AGnssSensor::GetSensorDefinition()
|
||||
{
|
||||
|
@ -16,11 +15,4 @@ AGnssSensor::AGnssSensor(const FObjectInitializer &ObjectInitializer)
|
|||
: Super(ObjectInitializer)
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = false;
|
||||
|
||||
auto MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("RootComponent"));
|
||||
MeshComp->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
|
||||
MeshComp->bHiddenInGame = true;
|
||||
MeshComp->CastShadow = false;
|
||||
MeshComp->PostPhysicsComponentTick.bCanEverTick = false;
|
||||
RootComponent = MeshComp;
|
||||
}
|
||||
|
|
|
@ -23,5 +23,4 @@ public:
|
|||
static FActorDefinition GetSensorDefinition();
|
||||
|
||||
AGnssSensor(const FObjectInitializer &ObjectInitializer);
|
||||
|
||||
};
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include "Carla.h"
|
||||
#include "Carla/Sensor/LaneInvasionSensor.h"
|
||||
#include "StaticMeshResources.h"
|
||||
|
||||
FActorDefinition ALaneInvasionSensor::GetSensorDefinition()
|
||||
{
|
||||
|
@ -16,11 +15,4 @@ ALaneInvasionSensor::ALaneInvasionSensor(const FObjectInitializer &ObjectInitial
|
|||
: Super(ObjectInitializer)
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = false;
|
||||
|
||||
auto MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("RootComponent"));
|
||||
MeshComp->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
|
||||
MeshComp->bHiddenInGame = true;
|
||||
MeshComp->CastShadow = false;
|
||||
MeshComp->PostPhysicsComponentTick.bCanEverTick = false;
|
||||
RootComponent = MeshComp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,5 +23,4 @@ public:
|
|||
static FActorDefinition GetSensorDefinition();
|
||||
|
||||
ALaneInvasionSensor(const FObjectInitializer &ObjectInitializer);
|
||||
|
||||
};
|
||||
|
|
|
@ -17,13 +17,6 @@ AObstacleDetectionSensor::AObstacleDetectionSensor(const FObjectInitializer &Obj
|
|||
: Super(ObjectInitializer)
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
auto MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("RootComponent"));
|
||||
MeshComp->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
|
||||
MeshComp->bHiddenInGame = true;
|
||||
MeshComp->CastShadow = false;
|
||||
MeshComp->PostPhysicsComponentTick.bCanEverTick = false;
|
||||
RootComponent = MeshComp;
|
||||
}
|
||||
|
||||
FActorDefinition AObstacleDetectionSensor::GetSensorDefinition()
|
||||
|
|
|
@ -47,5 +47,4 @@ private:
|
|||
bool bOnlyDynamics = false;
|
||||
|
||||
bool bDebugLineTrace = false;
|
||||
|
||||
};
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "DrawDebugHelpers.h"
|
||||
#include "Engine/CollisionProfile.h"
|
||||
#include "Runtime/Engine/Classes/Kismet/KismetMathLibrary.h"
|
||||
#include "StaticMeshResources.h"
|
||||
|
||||
FActorDefinition ARayCastLidar::GetSensorDefinition()
|
||||
{
|
||||
|
@ -23,13 +22,6 @@ ARayCastLidar::ARayCastLidar(const FObjectInitializer& ObjectInitializer)
|
|||
: Super(ObjectInitializer)
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
auto MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("RootComponent"));
|
||||
MeshComp->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
|
||||
MeshComp->bHiddenInGame = true;
|
||||
MeshComp->CastShadow = false;
|
||||
MeshComp->PostPhysicsComponentTick.bCanEverTick = false;
|
||||
RootComponent = MeshComp;
|
||||
}
|
||||
|
||||
void ARayCastLidar::Set(const FActorDescription &ActorDescription)
|
||||
|
|
|
@ -47,19 +47,6 @@ ASceneCaptureSensor::ASceneCaptureSensor(const FObjectInitializer &ObjectInitial
|
|||
PrimaryActorTick.bCanEverTick = true;
|
||||
PrimaryActorTick.TickGroup = TG_PrePhysics;
|
||||
|
||||
MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CamMesh"));
|
||||
|
||||
MeshComp->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
|
||||
|
||||
MeshComp->bHiddenInGame = true;
|
||||
MeshComp->CastShadow = false;
|
||||
MeshComp->PostPhysicsComponentTick.bCanEverTick = false;
|
||||
RootComponent = MeshComp;
|
||||
|
||||
DrawFrustum = CreateDefaultSubobject<UDrawFrustumComponent>(TEXT("DrawFrust"));
|
||||
DrawFrustum->bIsEditorOnly = true;
|
||||
DrawFrustum->SetupAttachment(MeshComp);
|
||||
|
||||
CaptureRenderTarget = CreateDefaultSubobject<UTextureRenderTarget2D>(
|
||||
FName(*FString::Printf(TEXT("CaptureRenderTarget_d%d"), SCENE_CAPTURE_COUNTER)));
|
||||
CaptureRenderTarget->CompressionSettings = TextureCompressionSettings::TC_Default;
|
||||
|
@ -70,7 +57,7 @@ ASceneCaptureSensor::ASceneCaptureSensor(const FObjectInitializer &ObjectInitial
|
|||
|
||||
CaptureComponent2D = CreateDefaultSubobject<USceneCaptureComponent2D>(
|
||||
FName(*FString::Printf(TEXT("SceneCaptureComponent2D_%d"), SCENE_CAPTURE_COUNTER)));
|
||||
CaptureComponent2D->SetupAttachment(MeshComp);
|
||||
CaptureComponent2D->SetupAttachment(RootComponent);
|
||||
|
||||
SceneCaptureSensor_local_ns::SetCameraDefaultOverrides(*CaptureComponent2D);
|
||||
|
||||
|
@ -137,34 +124,6 @@ float ASceneCaptureSensor::GetMotionBlurMinObjectScreenSize() const
|
|||
return CaptureComponent2D->PostProcessSettings.MotionBlurPerObjectSize;
|
||||
}
|
||||
|
||||
void ASceneCaptureSensor::PostActorCreated()
|
||||
{
|
||||
Super::PostActorCreated();
|
||||
|
||||
// No need to load the editor mesh when there is no editor.
|
||||
#if WITH_EDITOR
|
||||
if (MeshComp)
|
||||
{
|
||||
if (!IsRunningCommandlet())
|
||||
{
|
||||
if (!MeshComp->GetStaticMesh())
|
||||
{
|
||||
UStaticMesh *CamMesh = LoadObject<UStaticMesh>(
|
||||
NULL,
|
||||
TEXT("/Engine/EditorMeshes/MatineeCam_SM.MatineeCam_SM"),
|
||||
NULL,
|
||||
LOAD_None,
|
||||
NULL);
|
||||
MeshComp->SetStaticMesh(CamMesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // WITH_EDITOR
|
||||
|
||||
// Sync component with CameraActor frustum settings.
|
||||
UpdateDrawFrustum();
|
||||
}
|
||||
|
||||
void ASceneCaptureSensor::BeginPlay()
|
||||
{
|
||||
using namespace SceneCaptureSensor_local_ns;
|
||||
|
@ -221,22 +180,6 @@ void ASceneCaptureSensor::EndPlay(const EEndPlayReason::Type EndPlayReason)
|
|||
SCENE_CAPTURE_COUNTER = 0u;
|
||||
}
|
||||
|
||||
void ASceneCaptureSensor::UpdateDrawFrustum()
|
||||
{
|
||||
if (DrawFrustum && CaptureComponent2D)
|
||||
{
|
||||
DrawFrustum->FrustumStartDist = GNearClippingPlane;
|
||||
|
||||
// 1000 is the default frustum distance, ideally this would be infinite but
|
||||
// that might cause rendering issues.
|
||||
DrawFrustum->FrustumEndDist =
|
||||
(CaptureComponent2D->MaxViewDistanceOverride > DrawFrustum->FrustumStartDist)
|
||||
? CaptureComponent2D->MaxViewDistanceOverride : 1000.0f;
|
||||
|
||||
DrawFrustum->FrustumAngle = CaptureComponent2D->FOVAngle;
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// -- Local static functions implementations -----------------------------------
|
||||
// =============================================================================
|
||||
|
|
|
@ -115,8 +115,6 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
virtual void PostActorCreated() override;
|
||||
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
|
||||
|
@ -125,10 +123,6 @@ protected:
|
|||
|
||||
private:
|
||||
|
||||
/// Used to synchronize the DrawFrustumComponent with the
|
||||
/// SceneCaptureComponent2D settings.
|
||||
void UpdateDrawFrustum();
|
||||
|
||||
/// Image width in pixels.
|
||||
UPROPERTY(EditAnywhere)
|
||||
uint32 ImageWidth = 800u;
|
||||
|
@ -151,12 +145,4 @@ private:
|
|||
/// Scene capture component.
|
||||
UPROPERTY(EditAnywhere)
|
||||
USceneCaptureComponent2D *CaptureComponent2D = nullptr;
|
||||
|
||||
/// To display the 3d camera in the editor.
|
||||
UPROPERTY()
|
||||
UStaticMeshComponent *MeshComp = nullptr;
|
||||
|
||||
/// To allow drawing the camera frustum in the editor.
|
||||
UPROPERTY()
|
||||
UDrawFrustumComponent *DrawFrustum = nullptr;
|
||||
};
|
||||
|
|
|
@ -10,6 +10,17 @@
|
|||
#include "Carla/Actor/ActorDescription.h"
|
||||
#include "Carla/Actor/ActorBlueprintFunctionLibrary.h"
|
||||
|
||||
ASensor::ASensor(const FObjectInitializer &ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
auto *Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CamMesh"));
|
||||
Mesh->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
|
||||
Mesh->bHiddenInGame = true;
|
||||
Mesh->CastShadow = false;
|
||||
Mesh->PostPhysicsComponentTick.bCanEverTick = false;
|
||||
RootComponent = Mesh;
|
||||
}
|
||||
|
||||
void ASensor::Set(const FActorDescription &Description)
|
||||
{
|
||||
// set the tick interval of the sensor
|
||||
|
@ -21,6 +32,25 @@ void ASensor::Set(const FActorDescription &Description)
|
|||
}
|
||||
}
|
||||
|
||||
void ASensor::PostActorCreated()
|
||||
{
|
||||
Super::PostActorCreated();
|
||||
|
||||
#if WITH_EDITOR
|
||||
auto *StaticMeshComponent = Cast<UStaticMeshComponent>(RootComponent);
|
||||
if (StaticMeshComponent && !IsRunningCommandlet() && !StaticMeshComponent->GetStaticMesh())
|
||||
{
|
||||
UStaticMesh *CamMesh = LoadObject<UStaticMesh>(
|
||||
NULL,
|
||||
TEXT("/Engine/EditorMeshes/MatineeCam_SM.MatineeCam_SM"),
|
||||
NULL,
|
||||
LOAD_None,
|
||||
NULL);
|
||||
StaticMeshComponent->SetStaticMesh(CamMesh);
|
||||
}
|
||||
#endif // WITH_EDITOR
|
||||
}
|
||||
|
||||
void ASensor::EndPlay(EEndPlayReason::Type EndPlayReason)
|
||||
{
|
||||
Super::EndPlay(EndPlayReason);
|
||||
|
|
|
@ -23,6 +23,8 @@ class CARLA_API ASensor : public AActor
|
|||
|
||||
public:
|
||||
|
||||
ASensor(const FObjectInitializer &ObjectInitializer);
|
||||
|
||||
void SetEpisode(const UCarlaEpisode &InEpisode)
|
||||
{
|
||||
Episode = &InEpisode;
|
||||
|
@ -46,6 +48,8 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
void PostActorCreated() override;
|
||||
|
||||
void EndPlay(EEndPlayReason::Type EndPlayReason) override;
|
||||
|
||||
const UCarlaEpisode &GetEpisode() const
|
||||
|
|
Loading…
Reference in New Issue