Add 'Goto entity' support for the new Editor camera (#743)

* add find entity in viewport functionality to new camera

* fix AZ_CVAR usage

* updates following review feedback

- updated comment styles from /// to //!
- retrieve fov of camera (add test for fov access)

* update namespace naming, fix AZ_CVAR usage

* update missed namespace and use AZ::Transform::CreateLookAt

* add missing include

* move EditorViewportSettings to EditorLib

* update DLL import/export API and rename namespace usage
This commit is contained in:
Tom Hulton-Harrop
2021-05-17 18:21:38 +01:00
committed by GitHub
parent 1c1b34cf76
commit f4106fe73f
14 changed files with 233 additions and 104 deletions
@@ -16,7 +16,7 @@
#include <AzCore/Settings/SettingsRegistry.h>
#include <AzCore/std/string/string_view.h>
namespace Editor
namespace SandboxEditor
{
constexpr AZStd::string_view GridSnappingSetting = "/Amazon/Preferences/Editor/GridSnapping";
constexpr AZStd::string_view GridSizeSetting = "/Amazon/Preferences/Editor/GridSize";
@@ -113,4 +113,4 @@ namespace Editor
registry->Set(ShowGridSetting, showing);
}
}
} // namespace Editor
} // namespace SandboxEditor
+17 -13
View File
@@ -12,27 +12,31 @@
#pragma once
#include <EditorCoreAPI.h>
#include <SandboxAPI.h>
namespace Editor
namespace SandboxEditor
{
EDITOR_CORE_API bool GridSnappingEnabled();
SANDBOX_API bool GridSnappingEnabled();
EDITOR_CORE_API float GridSnappingSize();
SANDBOX_API float GridSnappingSize();
EDITOR_CORE_API bool AngleSnappingEnabled();
SANDBOX_API bool AngleSnappingEnabled();
EDITOR_CORE_API float AngleSnappingSize();
SANDBOX_API float AngleSnappingSize();
EDITOR_CORE_API bool ShowingGrid();
SANDBOX_API bool ShowingGrid();
EDITOR_CORE_API void SetGridSnapping(bool enabled);
SANDBOX_API void SetGridSnapping(bool enabled);
EDITOR_CORE_API void SetGridSnappingSize(float size);
SANDBOX_API void SetGridSnappingSize(float size);
EDITOR_CORE_API void SetAngleSnapping(bool enabled);
SANDBOX_API void SetAngleSnapping(bool enabled);
EDITOR_CORE_API void SetAngleSnappingSize(float size);
SANDBOX_API void SetAngleSnappingSize(float size);
EDITOR_CORE_API void SetShowingGrid(bool showing);
} // namespace Editor
SANDBOX_API void SetShowingGrid(bool showing);
//! Return if the new editor camera system is enabled or not.
//! @note This is implemented in EditorViewportWidget.cpp
SANDBOX_API bool UsingNewCameraSystem();
} // namespace SandboxEditor
+16 -12
View File
@@ -102,8 +102,16 @@
#include <IStatObj.h>
AZ_CVAR(
bool, ed_visibility_logTiming, false, nullptr, AZ::ConsoleFunctorFlags::Null,
"Output the timing of the new IVisibilitySystem query");
bool, ed_visibility_logTiming, false, nullptr, AZ::ConsoleFunctorFlags::Null, "Output the timing of the new IVisibilitySystem query");
AZ_CVAR(bool, ed_useNewCameraSystem, false, nullptr, AZ::ConsoleFunctorFlags::Null, "Use the new Editor camera system");
namespace SandboxEditor
{
bool UsingNewCameraSystem()
{
return ed_useNewCameraSystem;
}
} // namespace SandboxEditor
EditorViewportWidget* EditorViewportWidget::m_pPrimaryViewport = nullptr;
@@ -114,7 +122,7 @@ namespace AzFramework
extern InputChannelId CameraOrbitLookButton;
extern InputChannelId CameraOrbitDollyButton;
extern InputChannelId CameraOrbitPanButton;
}
} // namespace AzFramework
#if AZ_TRAIT_OS_PLATFORM_APPLE
void StopFixedCursorMode();
@@ -124,10 +132,6 @@ void StartFixedCursorMode(QObject *viewport);
#define RENDER_MESH_TEST_DISTANCE (0.2f)
#define CURSOR_FONT_HEIGHT 8.0f
AZ_CVAR(
bool, ed_useNewCameraSystem, false, nullptr, AZ::ConsoleFunctorFlags::Null,
"Use the new Editor camera system (the Atom-native Editor viewport (experimental) must also be enabled)");
//! Viewport settings for the EditorViewportWidget
struct EditorViewportSettings : public AzToolsFramework::ViewportInteraction::ViewportSettings
{
@@ -2885,27 +2889,27 @@ void EditorViewportWidget::SetAsActiveViewport()
bool EditorViewportSettings::GridSnappingEnabled() const
{
return Editor::GridSnappingEnabled();
return SandboxEditor::GridSnappingEnabled();
}
float EditorViewportSettings::GridSize() const
{
return Editor::GridSnappingSize();
return SandboxEditor::GridSnappingSize();
}
bool EditorViewportSettings::ShowGrid() const
{
return Editor::ShowingGrid();
return SandboxEditor::ShowingGrid();
}
bool EditorViewportSettings::AngleSnappingEnabled() const
{
return Editor::AngleSnappingEnabled();
return SandboxEditor::AngleSnappingEnabled();
}
float EditorViewportSettings::AngleStep() const
{
return Editor::AngleSnappingSize();
return SandboxEditor::AngleSnappingSize();
}
#include <moc_EditorViewportWidget.cpp>
+8 -8
View File
@@ -874,9 +874,9 @@ void MainWindow::InitActions()
.SetCheckable(true)
.RegisterUpdateCallback([](QAction* action) {
Q_ASSERT(action->isCheckable());
action->setChecked(Editor::GridSnappingEnabled());
action->setChecked(SandboxEditor::GridSnappingEnabled());
})
.Connect(&QAction::triggered, []() { Editor::SetGridSnapping(!Editor::GridSnappingEnabled()); });
.Connect(&QAction::triggered, []() { SandboxEditor::SetGridSnapping(!SandboxEditor::GridSnappingEnabled()); });
am->AddAction(ID_SNAPANGLE, tr("Snap angle"))
.SetIcon(Style::icon("Angle"))
@@ -885,9 +885,9 @@ void MainWindow::InitActions()
.SetCheckable(true)
.RegisterUpdateCallback([](QAction* action) {
Q_ASSERT(action->isCheckable());
action->setChecked(Editor::AngleSnappingEnabled());
action->setChecked(SandboxEditor::AngleSnappingEnabled());
})
.Connect(&QAction::triggered, []() { Editor::SetAngleSnapping(!Editor::AngleSnappingEnabled()); });
.Connect(&QAction::triggered, []() { SandboxEditor::SetAngleSnapping(!SandboxEditor::AngleSnappingEnabled()); });
// Display actions
am->AddAction(ID_WIREFRAME, tr("&Wireframe"))
@@ -1275,12 +1275,12 @@ QWidget* MainWindow::CreateSnapToGridWidget()
{
SnapToWidget::SetValueCallback setCallback = [](double snapStep)
{
Editor::SetGridSnappingSize(snapStep);
SandboxEditor::SetGridSnappingSize(snapStep);
};
SnapToWidget::GetValueCallback getCallback = []()
{
return Editor::GridSnappingSize();
return SandboxEditor::GridSnappingSize();
};
return new SnapToWidget(m_actionManager->GetAction(ID_SNAP_TO_GRID), setCallback, getCallback);
@@ -1290,12 +1290,12 @@ QWidget* MainWindow::CreateSnapToAngleWidget()
{
SnapToWidget::SetValueCallback setCallback = [](double snapAngle)
{
Editor::SetAngleSnappingSize(snapAngle);
SandboxEditor::SetAngleSnappingSize(snapAngle);
};
SnapToWidget::GetValueCallback getCallback = []()
{
return Editor::AngleSnappingSize();
return SandboxEditor::AngleSnappingSize();
};
return new SnapToWidget(m_actionManager->GetAction(ID_SNAPANGLE), setCallback, getCallback);
@@ -25,7 +25,8 @@
namespace SandboxEditor
{
static void DrawPreviewAxis(AzFramework::DebugDisplayRequests& display, const AZ::Transform& transform, const float axisLength)
// debug
void DrawPreviewAxis(AzFramework::DebugDisplayRequests& display, const AZ::Transform& transform, const float axisLength)
{
display.SetColor(AZ::Colors::Red);
display.DrawLine(transform.GetTranslation(), transform.GetTranslation() + transform.GetBasisX().GetNormalizedSafe() * axisLength);
@@ -87,10 +88,12 @@ namespace SandboxEditor
}
AzFramework::ViewportDebugDisplayEventBus::Handler::BusConnect(AzToolsFramework::GetEntityContextId());
ModernViewportCameraControllerRequestBus::Handler::BusConnect(viewportId);
}
ModernViewportCameraControllerInstance::~ModernViewportCameraControllerInstance()
{
ModernViewportCameraControllerRequestBus::Handler::BusDisconnect();
AzFramework::ViewportDebugDisplayEventBus::Handler::BusDisconnect();
}
@@ -100,27 +103,6 @@ namespace SandboxEditor
AzFramework::WindowRequestBus::EventResult(
windowSize, event.m_windowHandle, &AzFramework::WindowRequestBus::Events::GetClientAreaSize);
if (m_cameraMode == CameraMode::Control)
{
if (AzFramework::InputDeviceKeyboard::IsKeyboardDevice(event.m_inputChannel.GetInputDevice().GetInputDeviceId()))
{
if (event.m_inputChannel.GetInputChannelId() == AzFramework::InputDeviceKeyboard::Key::AlphanumericR)
{
m_transformEnd = m_camera.Transform();
return true;
}
else if (event.m_inputChannel.GetInputChannelId() == AzFramework::InputDeviceKeyboard::Key::AlphanumericP)
{
m_animationT = 0.0f;
m_cameraMode = CameraMode::Animation;
m_transformStart = m_camera.Transform();
return true;
}
}
}
return m_cameraSystem.HandleEvents(AzFramework::BuildInputEvent(event.m_inputChannel, windowSize));
}
@@ -174,7 +156,13 @@ namespace SandboxEditor
debugDisplay.SetColor(1.0f, 1.0f, 1.0f, alpha);
debugDisplay.DrawWireSphere(m_camera.m_lookAt, 0.5f);
}
}
DrawPreviewAxis(debugDisplay, m_transformEnd, 2.0f);
void ModernViewportCameraControllerInstance::InterpolateToTransform(const AZ::Transform& worldFromLocal)
{
m_animationT = 0.0f;
m_cameraMode = CameraMode::Animation;
m_transformStart = m_camera.Transform();
m_transformEnd = worldFromLocal;
}
} // namespace SandboxEditor
@@ -12,6 +12,8 @@
#pragma once
#include <ModernViewportCameraControllerRequestBus.h>
#include <Atom/RPI.Public/ViewportContext.h>
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
#include <AzFramework/Viewport/CameraInput.h>
@@ -36,6 +38,7 @@ namespace SandboxEditor
class ModernViewportCameraControllerInstance final
: public AzFramework::MultiViewportControllerInstanceInterface<ModernViewportCameraController>,
public ModernViewportCameraControllerRequestBus::Handler,
private AzFramework::ViewportDebugDisplayEventBus::Handler
{
public:
@@ -46,10 +49,13 @@ namespace SandboxEditor
bool HandleInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event) override;
void UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event) override;
// ModernViewportCameraControllerRequestBus overrides ...
void InterpolateToTransform(const AZ::Transform& worldFromLocal) override;
private:
// AzFramework::ViewportDebugDisplayEventBus overrides ...
void DisplayViewport(const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay) override;
private:
enum class CameraMode
{
Control,
@@ -0,0 +1,42 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#include <AzFramework/Viewport/ViewportId.h>
namespace AZ
{
class Transform;
}
namespace SandboxEditor
{
//! Provides an interface to control the modern viewport camera controller from the Editor.
//! @note The bus is addressed by viewport id.
class ModernViewportCameraControllerRequests : public AZ::EBusTraits
{
public:
using BusIdType = AzFramework::ViewportId;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
//! Begin a smooth transition of the camera to the requested transform.
virtual void InterpolateToTransform(const AZ::Transform& worldFromLocal) = 0;
protected:
~ModernViewportCameraControllerRequests() = default;
};
using ModernViewportCameraControllerRequestBus = AZ::EBus<ModernViewportCameraControllerRequests>;
} // namespace SandboxEditor
@@ -22,8 +22,6 @@ set(FILES
Include/IEditorMaterial.h
Include/IEditorMaterialManager.h
Include/IImageUtil.h
EditorViewportSettings.cpp
EditorViewportSettings.h
Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.qrc
Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp
Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.h
@@ -824,12 +824,15 @@ set(FILES
LayoutWnd.h
EditorViewportWidget.cpp
EditorViewportWidget.h
EditorViewportSettings.cpp
EditorViewportSettings.h
ViewportManipulatorController.cpp
ViewportManipulatorController.h
LegacyViewportCameraController.cpp
LegacyViewportCameraController.h
ModernViewportCameraController.cpp
ModernViewportCameraController.h
ModernViewportCameraControllerRequestBus.h
RenderViewport.cpp
RenderViewport.h
TopRendererWnd.cpp