Skip to content

Commit

Permalink
Merge branch 'viewport-visibility' of https://github.com/aburgm/AirSim
Browse files Browse the repository at this point in the history
…into aburgm-viewport-visibility
  • Loading branch information
sytelus committed Mar 2, 2018
2 parents d47d421 + 2036103 commit 8f16b93
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion AirLib/include/common/AirSimSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,4 +592,4 @@ struct AirSimSettings {
};

}} //namespace
#endif
#endif
39 changes: 33 additions & 6 deletions Unreal/Plugins/AirSim/Source/CameraDirector.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "CameraDirector.h"
#include "GameFramework/PlayerController.h"
#include "Runtime/Engine/Public/Slate/SceneViewport.h"
#include "AirBlueprintLib.h"

ACameraDirector::ACameraDirector()
Expand Down Expand Up @@ -34,7 +35,7 @@ void ACameraDirector::Tick(float DeltaTime)
else if (mode_ == ECameraDirectorMode::CAMERA_DIRECTOR_MODE_SPRINGARM_CHASE) {
//do nothing, spring arm is pulling the camera with it
}
else if (mode_ == ECameraDirectorMode::CAMREA_DIRECTOR_MODE_NODISPLAY) {
else if (mode_ == ECameraDirectorMode::CAMERA_DIRECTOR_MODE_NODISPLAY) {
//do nothing, we have camera turned off
}
else { //make camera move in desired way
Expand Down Expand Up @@ -92,8 +93,8 @@ void ACameraDirector::setCameras(APIPCamera* external_camera, VehiclePawnWrapper
case ECameraDirectorMode::CAMERA_DIRECTOR_MODE_GROUND_OBSERVER: inputEventGroundView(); break;
case ECameraDirectorMode::CAMERA_DIRECTOR_MODE_MANUAL: inputEventManualView(); break;
case ECameraDirectorMode::CAMERA_DIRECTOR_MODE_SPRINGARM_CHASE: inputEventSpringArmChaseView(); break;
case ECameraDirectorMode::CAMREA_DIRECTOR_MODE_BACKUP: inputEventBackupView(); break;
case ECameraDirectorMode::CAMREA_DIRECTOR_MODE_NODISPLAY: inputEventNoDisplayView(); break;
case ECameraDirectorMode::CAMERA_DIRECTOR_MODE_BACKUP: inputEventBackupView(); break;
case ECameraDirectorMode::CAMERA_DIRECTOR_MODE_NODISPLAY: inputEventNoDisplayView(); break;
default:
throw std::out_of_range("Unsupported view mode specified in CameraDirector::initializeForBeginPlay");
}
Expand Down Expand Up @@ -146,6 +147,32 @@ void ACameraDirector::setMode(ECameraDirectorMode mode)
attachSpringArm(false);
}

// Enable/disable primary viewport rendering flag
if (mode_ != ECameraDirectorMode::CAMERA_DIRECTOR_MODE_NODISPLAY &&
mode == ECameraDirectorMode::CAMERA_DIRECTOR_MODE_NODISPLAY)
{
// This disables rendering of the main viewport in the same way as the
// console command "show rendering" would do.
GetWorld()->GetGameViewport()->EngineShowFlags.SetRendering(false);

// When getting an image through the API, the image is produced after the render
// thread has finished rendering the current and the subsequent frame. This means
// that the frame rate for obtaining images through the API is only half as high as
// it could be, since only every other image is actually captured. We work around
// this by telling the viewport to flush the rendering queue at the end of each
// drawn frame so that it executes our render request at that point already.
// Do this only if the main viewport is not being rendered anyway in case there are
// any adverse performance effects during main rendering.
GetWorld()->GetGameViewport()->GetGameViewport()->IncrementFlushOnDraw();
}
else if(mode_ == ECameraDirectorMode::CAMERA_DIRECTOR_MODE_NODISPLAY &&
mode != ECameraDirectorMode::CAMERA_DIRECTOR_MODE_NODISPLAY)
{
// Re-enable rendering
GetWorld()->GetGameViewport()->EngineShowFlags.SetRendering(true);
GetWorld()->GetGameViewport()->GetGameViewport()->DecrementFlushOnDraw();
}

mode_ = mode;

//if new mode is manual mode then add key bindings
Expand All @@ -171,7 +198,7 @@ void ACameraDirector::setupInputBindings()
UAirBlueprintLib::BindActionToKey("inputEventManualView", EKeys::M, this, &ACameraDirector::inputEventManualView);
UAirBlueprintLib::BindActionToKey("inputEventSpringArmChaseView", EKeys::Slash, this, &ACameraDirector::inputEventSpringArmChaseView);
UAirBlueprintLib::BindActionToKey("inputEventBackupView", EKeys::K, this, &ACameraDirector::inputEventBackupView);
UAirBlueprintLib::BindActionToKey("inputEventNoDispalyView", EKeys::Hyphen, this, &ACameraDirector::inputEventNoDisplayView);
UAirBlueprintLib::BindActionToKey("inputEventNoDisplayView", EKeys::Hyphen, this, &ACameraDirector::inputEventNoDisplayView);
}


Expand Down Expand Up @@ -229,13 +256,13 @@ void ACameraDirector::inputEventManualView()

void ACameraDirector::inputEventNoDisplayView()
{
setMode(ECameraDirectorMode::CAMREA_DIRECTOR_MODE_NODISPLAY);
setMode(ECameraDirectorMode::CAMERA_DIRECTOR_MODE_NODISPLAY);
disableCameras(true, true, true);
}

void ACameraDirector::inputEventBackupView()
{
setMode(ECameraDirectorMode::CAMREA_DIRECTOR_MODE_BACKUP);
setMode(ECameraDirectorMode::CAMERA_DIRECTOR_MODE_BACKUP);
external_camera_->disableMain();
if (fpv_camera_)
fpv_camera_->disableMain();
Expand Down
4 changes: 2 additions & 2 deletions Unreal/Plugins/AirSim/Source/CameraDirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ enum class ECameraDirectorMode : uint8
CAMERA_DIRECTOR_MODE_FLY_WITH_ME = 3 UMETA(DisplayName = "FlyWithMe"),
CAMERA_DIRECTOR_MODE_MANUAL = 4 UMETA(DisplayName = "Manual"),
CAMERA_DIRECTOR_MODE_SPRINGARM_CHASE = 5 UMETA(DisplayName = "SpringArmChase"),
CAMREA_DIRECTOR_MODE_BACKUP = 6 UMETA(DisplayName = "Backup"),
CAMREA_DIRECTOR_MODE_NODISPLAY = 7 UMETA(DisplayName = "No Display")
CAMERA_DIRECTOR_MODE_BACKUP = 6 UMETA(DisplayName = "Backup"),
CAMERA_DIRECTOR_MODE_NODISPLAY = 7 UMETA(DisplayName = "No Display")
};

UCLASS()
Expand Down
15 changes: 9 additions & 6 deletions Unreal/Plugins/AirSim/Source/RenderRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,25 @@ void RenderRequest::getScreenshot(std::shared_ptr<RenderParams> params[], std::v
for (unsigned int i = 0; i < req_size; ++i) {
if (! params[i]->pixels_as_float) {
if (results[i]->width != 0 && results[i]->height != 0) {
results[i]->image_data_uint8.SetNumUninitialized(results[i]->width * results[i]->height * 4, false);
if (params[i]->compress)
FImageUtils::CompressImageArray(results[i]->width, results[i]->height, results[i]->bmp, results[i]->image_data_uint8);
else {
uint8* ptr = results[i]->image_data_uint8.GetData();
for (const auto& item : results[i]->bmp) {
results[i]->image_data_uint8.Add(item.R);
results[i]->image_data_uint8.Add(item.G);
results[i]->image_data_uint8.Add(item.B);
results[i]->image_data_uint8.Add(item.A);
*ptr++ = item.R;
*ptr++ = item.G;
*ptr++ = item.B;
*ptr++ = item.A;
}
}
}
}
else {
results[i]->image_data_float.SetNumUninitialized(results[i]->width * results[i]->height);
float* ptr = results[i]->image_data_float.GetData();
for (const auto& item : results[i]->bmp_float) {
float fval = item.R.GetFloat();
results[i]->image_data_float.Add(fval);
*ptr++ = item.R.GetFloat();
}
}
}
Expand Down
1 change: 0 additions & 1 deletion Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ void ASimHUD::setUnrealEngineSettings()
//we get error that GameThread has timed out after 30 sec waiting on render thread
static const auto render_timeout_var = IConsoleManager::Get().FindConsoleVariable(TEXT("g.TimeoutForBlockOnRenderFence"));
render_timeout_var->Set(300000);

}

void ASimHUD::setupInputBindings()
Expand Down

0 comments on commit 8f16b93

Please sign in to comment.