Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterJansen committed Jun 14, 2024
1 parent d0cb2eb commit 10984be
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 84 deletions.
2 changes: 1 addition & 1 deletion Unreal/Environments/Blocks/Blocks.uproject
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"FileVersion": 3,
"EngineAssociation": "5.2",
"EngineAssociation": "5.3",
"Category": "",
"Description": "",
"Modules": [
Expand Down
2 changes: 1 addition & 1 deletion Unreal/Environments/Blocks/Source/Blocks.Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public BlocksTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
ExtraModuleNames.AddRange(new string[] { "Blocks" });

DefaultBuildSettings = BuildSettingsVersion.V4;
//bUseUnityBuild = false;
if (Target.Platform == UnrealTargetPlatform.Linux)
bUsePCHFiles = false;
Expand Down
2 changes: 1 addition & 1 deletion Unreal/Environments/Blocks/Source/BlocksEditor.Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public BlocksEditorTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;
ExtraModuleNames.AddRange(new string[] { "Blocks" });
DefaultBuildSettings = BuildSettingsVersion.V2;
DefaultBuildSettings = BuildSettingsVersion.V4;
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_2;
//bUseUnityBuild = false;
//bUsePCHFiles = false;
Expand Down
2 changes: 1 addition & 1 deletion Unreal/Environments/Blocks/package.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set OutPath=%1
set ToolPath=%2
set UEVer=%3

if "%UEVer%"=="" set "UEVer=5.2.1"
if "%UEVer%"=="" set "UEVer=5.3.2"

set "_ToolPath=%PROGRAMFILES%\Epic Games\UE_%UEVer%\Engine\Build\BatchFiles"
if "%ToolPath%"=="" set ToolPath=%_ToolPath%
Expand Down
20 changes: 11 additions & 9 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ EAppReturnType::Type UAirBlueprintLib::ShowMessage(EAppMsgType::Type message_typ

return FMessageDialog::Open(message_type,
FText::FromString(message.c_str()),
&title_text);
title_text);
}

ULineBatchComponent* GetLineBatcher(const UWorld* InWorld, bool bPersistentLines, float LifeTime, bool bDepthIsForeground)
Expand Down Expand Up @@ -732,9 +732,9 @@ std::vector<msr::airlib::MeshPositionVertexBuffersResponse> UAirBlueprintLib::Ge
ENQUEUE_RENDER_COMMAND(GetVertexBuffer)
(
[vertex_buffer, data](FRHICommandListImmediate& RHICmdList) {
FVector* indices = (FVector*)RHILockBuffer(vertex_buffer->VertexBufferRHI, 0, vertex_buffer->VertexBufferRHI->GetSize(), RLM_ReadOnly);
FVector* indices = (FVector*)RHICmdList.LockBuffer(vertex_buffer->VertexBufferRHI, 0, vertex_buffer->VertexBufferRHI->GetSize(), RLM_ReadOnly);
memcpy(data, indices, vertex_buffer->VertexBufferRHI->GetSize());
RHIUnlockBuffer(vertex_buffer->VertexBufferRHI);
RHICmdList.UnlockBuffer(vertex_buffer->VertexBufferRHI);
});

#if ((ENGINE_MAJOR_VERSION > 4) || (ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION >= 27))
Expand All @@ -754,9 +754,9 @@ std::vector<msr::airlib::MeshPositionVertexBuffersResponse> UAirBlueprintLib::Ge
ENQUEUE_RENDER_COMMAND(GetIndexBuffer)
(
[IndexBuffer, data_ptr](FRHICommandListImmediate& RHICmdList) {
uint16_t* indices = (uint16_t*)RHILockBuffer(IndexBuffer->IndexBufferRHI, 0, IndexBuffer->IndexBufferRHI->GetSize(), RLM_ReadOnly);
uint16_t* indices = (uint16_t*)RHICmdList.LockBuffer(IndexBuffer->IndexBufferRHI, 0, IndexBuffer->IndexBufferRHI->GetSize(), RLM_ReadOnly);
memcpy(data_ptr, indices, IndexBuffer->IndexBufferRHI->GetSize());
RHIUnlockBuffer(IndexBuffer->IndexBufferRHI);
RHICmdList.UnlockBuffer(IndexBuffer->IndexBufferRHI);
});

//Need to force the render command to go through cause on the next iteration the buffer no longer exists
Expand All @@ -777,9 +777,9 @@ std::vector<msr::airlib::MeshPositionVertexBuffersResponse> UAirBlueprintLib::Ge
ENQUEUE_RENDER_COMMAND(GetIndexBuffer)
(
[IndexBuffer, data_ptr](FRHICommandListImmediate& RHICmdList) {
uint32_t* indices = (uint32_t*)RHILockBuffer(IndexBuffer->IndexBufferRHI, 0, IndexBuffer->IndexBufferRHI->GetSize(), RLM_ReadOnly);
uint32_t* indices = (uint32_t*)RHICmdList.LockBuffer(IndexBuffer->IndexBufferRHI, 0, IndexBuffer->IndexBufferRHI->GetSize(), RLM_ReadOnly);
memcpy(data_ptr, indices, IndexBuffer->IndexBufferRHI->GetSize());
RHIUnlockBuffer(IndexBuffer->IndexBufferRHI);
RHICmdList.UnlockBuffer(IndexBuffer->IndexBufferRHI);
});

FlushRenderingCommands();
Expand Down Expand Up @@ -814,7 +814,8 @@ std::vector<msr::airlib::MeshPositionVertexBuffersResponse> UAirBlueprintLib::Ge
TArray<FName> UAirBlueprintLib::ListWorldsInRegistry()
{
FARFilter Filter;
Filter.ClassNames.Add(UWorld::StaticClass()->GetFName());
FTopLevelAssetPath UPath(UWorld::StaticClass()->GetPathName());
Filter.ClassPaths.Add(UPath);
Filter.bRecursivePaths = true;

TArray<FAssetData> AssetData;
Expand All @@ -830,7 +831,8 @@ TArray<FName> UAirBlueprintLib::ListWorldsInRegistry()
UObject* UAirBlueprintLib::GetMeshFromRegistry(const std::string& load_object)
{
FARFilter Filter;
Filter.ClassNames.Add(UStaticMesh::StaticClass()->GetFName());
FTopLevelAssetPath MPath(UStaticMesh::StaticClass()->GetPathName());
Filter.ClassPaths.Add(MPath);
Filter.bRecursivePaths = true;

TArray<FAssetData> AssetData;
Expand Down
2 changes: 1 addition & 1 deletion Unreal/Plugins/AirSim/Source/AirBlueprintLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class UAirBlueprintLib : public UBlueprintFunctionLibrary
FName name_n = FName(*name);
for (TActorIterator<AActor> It(context->GetWorld(), T::StaticClass()); It; ++It) {
AActor* Actor = *It;
if (!Actor->IsPendingKill() && (Actor->ActorHasTag(name_n) || Actor->GetName().Compare(name) == 0)) {
if (IsValid(Actor) && (Actor->ActorHasTag(name_n) || Actor->GetName().Compare(name) == 0)) {
return static_cast<T*>(Actor);
}
}
Expand Down
24 changes: 14 additions & 10 deletions Unreal/Plugins/AirSim/Source/AirSim.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ private string AirSimPluginPath
}
private string ProjectBinariesPath
{
get { return Path.Combine(
get
{
return Path.Combine(
Directory.GetParent(AirSimPluginPath).Parent.FullName, "Binaries");
}
}
Expand Down Expand Up @@ -91,7 +93,7 @@ public AirSim(ReadOnlyTargetRules Target) : base(Target)
PublicIncludePaths.Add(Path.Combine(AirLibPath, "deps", "eigen3"));
AddOSLibDependencies(Target);

SetupCompileMode(CompileMode.HeaderOnlyWithRpc, Target);
SetupCompileMode(CompileMode.CppCompileWithRpc, Target);
}

private void AddOSLibDependencies(ReadOnlyTargetRules Target)
Expand All @@ -106,12 +108,12 @@ private void AddOSLibDependencies(ReadOnlyTargetRules Target)
PublicAdditionalLibraries.Add("dxguid.lib");
}

if (Target.Platform == UnrealTargetPlatform.Linux)
{
// needed when packaging
PublicAdditionalLibraries.Add("stdc++");
PublicAdditionalLibraries.Add("supc++");
}
if (Target.Platform == UnrealTargetPlatform.Linux)
{
// needed when packaging
PublicAdditionalLibraries.Add("stdc++");
PublicAdditionalLibraries.Add("supc++");
}
}

static void CopyFileIfNewer(string srcFilePath, string destFolder)
Expand Down Expand Up @@ -143,7 +145,9 @@ private bool AddLibDependency(string LibName, string LibPath, string LibFileName
isLibrarySupported = true;

PublicAdditionalLibraries.Add(Path.Combine(LibPath, PlatformString, ConfigurationString, LibFileName + ".lib"));
} else if (Target.Platform == UnrealTargetPlatform.Linux || Target.Platform == UnrealTargetPlatform.Mac) {
}
else if (Target.Platform == UnrealTargetPlatform.Linux || Target.Platform == UnrealTargetPlatform.Mac)
{
isLibrarySupported = true;
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "lib" + LibFileName + ".a"));
}
Expand All @@ -157,4 +161,4 @@ private bool AddLibDependency(string LibName, string LibPath, string LibFileName

return isLibrarySupported;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "CameraDirector.h"
#include "AirSimCameraDirector.h"
#include "GameFramework/PlayerController.h"
#include "AirBlueprintLib.h"

Expand Down Expand Up @@ -321,7 +321,7 @@ void ACameraDirector::inputEventFpvView()
if (fpv_camera_) {
setMode(ECameraDirectorMode::CAMERA_DIRECTOR_MODE_FPV);
fpv_camera_->showToScreen();
disableCameras(false, true, true);
disableCameras(false, true, true, true);
}
else
UAirBlueprintLib::LogMessageString("Camera is not available: ", "fpv_camera", LogDebugLevel::Failure);
Expand All @@ -346,4 +346,4 @@ void ACameraDirector::notifyViewModeChanged()
UWorld* world = GetWorld();
UGameViewportClient* gameViewport = world->GetGameViewport();
gameViewport->bDisableWorldRendering = nodisplay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "ManualPoseController.h"
#include "common/common_utils/Utils.hpp"
#include "GameFramework/SpringArmComponent.h"
#include "CameraDirector.generated.h"
#include "AirSimCameraDirector.generated.h"

UENUM(BlueprintType)
enum class ECameraDirectorMode : uint8
Expand All @@ -30,10 +30,10 @@ class AIRSIM_API ACameraDirector : public AActor
public:
/** Spring arm that will offset the camera */
UPROPERTY(Category = Camera, VisibleDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
USpringArmComponent* SpringArm;
USpringArmComponent *SpringArm;

UPROPERTY(Category = Camera, VisibleDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
APIPCamera* ExternalCamera;
APIPCamera *ExternalCamera;

public:
void inputEventFpvView();
Expand All @@ -57,11 +57,11 @@ class AIRSIM_API ACameraDirector : public AActor
void setMode(ECameraDirectorMode mode);

void initializeForBeginPlay(ECameraDirectorMode view_mode,
AActor* follow_actor, APIPCamera* fpv_camera, APIPCamera* front_camera, APIPCamera* back_camera);
AActor *follow_actor, APIPCamera *fpv_camera, APIPCamera *front_camera, APIPCamera *back_camera);

APIPCamera* getFpvCamera() const;
APIPCamera* getExternalCamera() const;
APIPCamera* getBackupCamera() const;
APIPCamera *getFpvCamera() const;
APIPCamera *getExternalCamera() const;
APIPCamera *getBackupCamera() const;
void setFollowDistance(const int follow_distance) { this->follow_distance_ = follow_distance; }
void setCameraRotationLagEnabled(const bool lag_enabled) { this->camera_rotation_lag_enabled_ = lag_enabled; }

Expand All @@ -74,16 +74,16 @@ class AIRSIM_API ACameraDirector : public AActor
private:
typedef common_utils::Utils Utils;

APIPCamera* fpv_camera_;
APIPCamera* backup_camera_;
APIPCamera* front_camera_;
AActor* follow_actor_;
APIPCamera *fpv_camera_;
APIPCamera *backup_camera_;
APIPCamera *front_camera_;
AActor *follow_actor_;

USceneComponent* last_parent_ = nullptr;
USceneComponent *last_parent_ = nullptr;

ECameraDirectorMode mode_;
UPROPERTY()
UManualPoseController* manual_pose_controller_;
UManualPoseController *manual_pose_controller_;

FVector camera_start_location_;
FVector initial_ground_obs_offset_;
Expand Down
69 changes: 45 additions & 24 deletions Unreal/Plugins/AirSim/Source/DetectionComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,34 @@ UDetectionComponent::UDetectionComponent()
void UDetectionComponent::BeginPlay()
{
Super::BeginPlay();
scene_capture_component_2D_ = CastChecked<USceneCaptureComponent2D>(GetAttachParent());
scene_capture_component_2D_ = Cast<USceneCaptureComponent2D>(GetAttachParent());
if (!scene_capture_component_2D_)
{
// we get re-parented to USceneComponent when saving Take Recorder videos
this->Deactivate();
}
object_filter_ = FObjectFilter();
}

void UDetectionComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
void UDetectionComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}

const TArray<FDetectionInfo>& UDetectionComponent::getDetections()
const TArray<FDetectionInfo> &UDetectionComponent::getDetections()
{
cached_detections_.Empty();

for (TActorIterator<AActor> actor_itr(GetWorld()); actor_itr; ++actor_itr) {
AActor* actor = *actor_itr;
if (object_filter_.matchesActor(actor)) {
if (FVector::Distance(actor->GetActorLocation(), GetComponentLocation()) <= max_distance_to_camera_) {
for (TActorIterator<AActor> actor_itr(GetWorld()); actor_itr; ++actor_itr)
{
AActor *actor = *actor_itr;
if (object_filter_.matchesActor(actor))
{
if (FVector::Distance(actor->GetActorLocation(), GetComponentLocation()) <= max_distance_to_camera_)
{
FBox2D box_2D_out;
if (texture_target_ && calcBoundingFromViewInfo(actor, box_2D_out)) {
if (texture_target_ && calcBoundingFromViewInfo(actor, box_2D_out))
{
FDetectionInfo detection;
detection.Actor = actor;
detection.Box2D = box_2D_out;
Expand All @@ -63,7 +72,7 @@ const TArray<FDetectionInfo>& UDetectionComponent::getDetections()
return cached_detections_;
}

bool UDetectionComponent::calcBoundingFromViewInfo(AActor* actor, FBox2D& box_out)
bool UDetectionComponent::calcBoundingFromViewInfo(AActor *actor, FBox2D &box_out)
{
FVector origin;
FVector extend;
Expand All @@ -74,7 +83,7 @@ bool UDetectionComponent::calcBoundingFromViewInfo(AActor* actor, FBox2D& box_ou
bool is_in_camera_view = false;

// get render target for texture size
FRenderTarget* render_target = texture_target_->GameThread_GetRenderTargetResource();
FRenderTarget *render_target = texture_target_->GameThread_GetRenderTargetResource();

// initialize viewinfo for projection matrix
FMinimalViewInfo info;
Expand Down Expand Up @@ -113,16 +122,19 @@ bool UDetectionComponent::calcBoundingFromViewInfo(AActor* actor, FBox2D& box_ou
FPlane(0, 1, 0, 0),
FPlane(0, 0, 0, 1));

if (scene_capture_component_2D_->bUseCustomProjectionMatrix) {
if (scene_capture_component_2D_->bUseCustomProjectionMatrix)
{
projection_data.ProjectionMatrix = scene_capture_component_2D_->CustomProjectionMatrix;
}
else {
else
{
projection_data.ProjectionMatrix = info.CalculateProjectionMatrix();
}
projection_data.SetConstrainedViewRectangle(screen_rect);

// Project Points to pixels and get the corner pixels
for (FVector& point : points) {
for (FVector &point : points)
{
FVector2D Pixel(0, 0);
FSceneView::ProjectWorldToScreen((point), screen_rect, projection_data.ComputeViewProjectionMatrix(), Pixel);
is_in_camera_view |= (Pixel != screen_rect.Min) && (Pixel != screen_rect.Max) && screen_rect.Contains(FIntPoint(Pixel.X, Pixel.Y));
Expand All @@ -136,13 +148,17 @@ bool UDetectionComponent::calcBoundingFromViewInfo(AActor* actor, FBox2D& box_ou
// If actor in camera view - check if it's actually visible or hidden
// Check against 8 extend points
bool is_visible = false;
if (is_in_camera_view) {
if (is_in_camera_view)
{
FHitResult result;
bool is_world_hit;
for (FVector& point : points) {
for (FVector &point : points)
{
is_world_hit = GetWorld()->LineTraceSingleByChannel(result, GetComponentLocation(), point, ECC_WorldStatic);
if (is_world_hit) {
if (result.GetActor() == actor) {
if (is_world_hit)
{
if (result.GetActor() == actor)
{
is_visible = true;
break;
}
Expand All @@ -151,12 +167,16 @@ bool UDetectionComponent::calcBoundingFromViewInfo(AActor* actor, FBox2D& box_ou

// If actor in camera view but didn't hit any point out of 8 extend points,
// check against 10 random points
if (!is_visible) {
for (int i = 0; i < 10; i++) {
if (!is_visible)
{
for (int i = 0; i < 10; i++)
{
FVector point = UKismetMathLibrary::RandomPointInBoundingBox(origin, extend);
is_world_hit = GetWorld()->LineTraceSingleByChannel(result, GetComponentLocation(), point, ECC_WorldStatic);
if (is_world_hit) {
if (result.GetActor() == actor) {
if (is_world_hit)
{
if (result.GetActor() == actor)
{
is_visible = true;
break;
}
Expand Down Expand Up @@ -187,11 +207,12 @@ FRotator UDetectionComponent::getRelativeRotation(FVector in_location, FRotator
return relative_object_transform.Rotator();
}

void UDetectionComponent::addMeshName(const std::string& mesh_name)
void UDetectionComponent::addMeshName(const std::string &mesh_name)
{
FString name(mesh_name.c_str());

if (!object_filter_.wildcard_mesh_names_.Contains(name)) {
if (!object_filter_.wildcard_mesh_names_.Contains(name))
{
object_filter_.wildcard_mesh_names_.Add(name);
}
}
Expand All @@ -204,4 +225,4 @@ void UDetectionComponent::setFilterRadius(const float radius_cm)
void UDetectionComponent::clearMeshNames()
{
object_filter_.wildcard_mesh_names_.Empty();
}
}
Loading

0 comments on commit 10984be

Please sign in to comment.