diff --git a/Unreal/Plugins/AirSim/Source/CameraDirector.cpp b/Unreal/Plugins/AirSim/Source/CameraDirector.cpp index cee6965358..43f0a3f2ad 100644 --- a/Unreal/Plugins/AirSim/Source/CameraDirector.cpp +++ b/Unreal/Plugins/AirSim/Source/CameraDirector.cpp @@ -344,21 +344,7 @@ void ACameraDirector::notifyViewModeChanged() { bool nodisplay = ECameraDirectorMode::CAMERA_DIRECTOR_MODE_NODISPLAY == mode_; - if (fpv_camera_) - fpv_camera_->onViewModeChanged(nodisplay); - if (backup_camera_) - backup_camera_->onViewModeChanged(nodisplay); - if (ExternalCamera) - ExternalCamera->onViewModeChanged(nodisplay); - if (front_camera_) - front_camera_->onViewModeChanged(nodisplay); - UWorld* world = GetWorld(); UGameViewportClient* gameViewport = world->GetGameViewport(); - if (mode_ == ECameraDirectorMode::CAMERA_DIRECTOR_MODE_NODISPLAY) { - gameViewport->bDisableWorldRendering = 1; - } - else { - gameViewport->bDisableWorldRendering = 0; - } + gameViewport->bDisableWorldRendering = nodisplay; } diff --git a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp index 05cbdcf25b..f9853a5371 100644 --- a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp +++ b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp @@ -98,7 +98,9 @@ void APIPCamera::BeginPlay() render_targets_[image_type] = NewObject(); } - onViewModeChanged(false); + //We set all cameras to start as nodisplay + //This improves performance because the capture components are no longer updating every frame and only update while requesting an image + onViewModeChanged(true); gimbal_stabilization_ = 0; gimbald_rotator_ = this->GetActorRotation(); @@ -270,6 +272,20 @@ void APIPCamera::setCameraTypeEnabled(ImageType type, bool enabled) enableCaptureComponent(type, enabled); } +void APIPCamera::setCaptureUpdate(USceneCaptureComponent2D* capture, bool nodisplay) +{ + capture->bCaptureEveryFrame = !nodisplay; + capture->bCaptureOnMovement = !nodisplay; + capture->bAlwaysPersistRenderingState = true; +} + +void APIPCamera::setCameraTypeUpdate(ImageType type, bool nodisplay) +{ + USceneCaptureComponent2D* capture = getCaptureComponent(type, false); + if (capture != nullptr) + setCaptureUpdate(capture, nodisplay); +} + void APIPCamera::setCameraPose(const msr::airlib::Pose& relative_pose) { FTransform pose = ned_transform_->fromRelativeNed(relative_pose); @@ -579,14 +595,7 @@ void APIPCamera::onViewModeChanged(bool nodisplay) for (unsigned int image_type = 0; image_type < imageTypeCount(); ++image_type) { USceneCaptureComponent2D* capture = getCaptureComponent(static_cast(image_type), false); if (capture) { - if (nodisplay) { - capture->bCaptureEveryFrame = false; - capture->bCaptureOnMovement = false; - } - else { - capture->bCaptureEveryFrame = true; - capture->bCaptureOnMovement = true; - } + setCaptureUpdate(capture, nodisplay); } } } diff --git a/Unreal/Plugins/AirSim/Source/PIPCamera.h b/Unreal/Plugins/AirSim/Source/PIPCamera.h index 17780bcdb2..fd4baad6ee 100644 --- a/Unreal/Plugins/AirSim/Source/PIPCamera.h +++ b/Unreal/Plugins/AirSim/Source/PIPCamera.h @@ -41,6 +41,9 @@ class AIRSIM_API APIPCamera : public ACameraActor void setCameraTypeEnabled(ImageType type, bool enabled); bool getCameraTypeEnabled(ImageType type) const; + void setCaptureUpdate(USceneCaptureComponent2D* capture, bool nodisplay); + void setCameraTypeUpdate(ImageType type, bool nodisplay); + void setupCameraFromSettings(const CameraSetting& camera_setting, const NedTransform& ned_transform); void setCameraPose(const msr::airlib::Pose& relative_pose); void setCameraFoV(float fov_degrees); diff --git a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp index 71000329c0..bffda000ff 100644 --- a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp +++ b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp @@ -133,8 +133,11 @@ void ASimHUD::updateWidgetSubwindowVisibility() bool is_visible = getSubWindowSettings().at(window_index).visible && camera != nullptr; - if (camera != nullptr) + if (camera != nullptr) { camera->setCameraTypeEnabled(camera_type, is_visible); + //sub-window captures don’t count as a request, set bCaptureEveryFrame and bCaptureOnMovement to display so we can show correctly the subwindow + camera->setCameraTypeUpdate(camera_type, false); + } widget_->setSubwindowVisibility(window_index, is_visible,