Merge pull request #184 from aws-lumberyard-dev/nvsickle/CherryPickMoreViewportFixes
Cherry-pick viewport fixes to main
This commit is contained in:
@@ -37,6 +37,7 @@ namespace AzFramework
|
||||
|
||||
// ViewportControllerInterface ...
|
||||
bool HandleInputChannelEvent(const ViewportControllerInputEvent& event) override;
|
||||
void ResetInputChannels() override;
|
||||
void UpdateViewport(const ViewportControllerUpdateEvent& event) override;
|
||||
void RegisterViewportContext(ViewportId viewport) override;
|
||||
void UnregisterViewportContext(ViewportId viewport) override;
|
||||
@@ -58,6 +59,7 @@ namespace AzFramework
|
||||
ViewportId GetViewportId() const { return m_viewportId; }
|
||||
|
||||
virtual bool HandleInputChannelEvent([[maybe_unused]]const ViewportControllerInputEvent& event) { return false; }
|
||||
virtual void ResetInputChannels() {}
|
||||
virtual void UpdateViewport([[maybe_unused]]const ViewportControllerUpdateEvent& event) {}
|
||||
|
||||
private:
|
||||
|
||||
@@ -30,6 +30,15 @@ namespace AzFramework
|
||||
return instanceIt->second->HandleInputChannelEvent(event);
|
||||
}
|
||||
|
||||
template <class TViewportControllerInstance, ViewportControllerPriority Priority>
|
||||
void MultiViewportController<TViewportControllerInstance, Priority>::ResetInputChannels()
|
||||
{
|
||||
for (auto instanceIt = m_instances.begin(); instanceIt != m_instances.end(); ++instanceIt)
|
||||
{
|
||||
instanceIt->second->ResetInputChannels();
|
||||
}
|
||||
}
|
||||
|
||||
template <class TViewportControllerInstance, ViewportControllerPriority Priority>
|
||||
void MultiViewportController<TViewportControllerInstance, Priority>::UpdateViewport(const ViewportControllerUpdateEvent& event)
|
||||
{
|
||||
|
||||
@@ -49,6 +49,11 @@ namespace AzFramework
|
||||
|
||||
bool ViewportControllerList::HandleInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event)
|
||||
{
|
||||
if (!IsEnabled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If our event priority is "custom", we should dispatch at all priority levels in order
|
||||
using AzFramework::ViewportControllerPriority;
|
||||
if (event.m_priority == AzFramework::ViewportControllerPriority::DispatchToAllPriorities)
|
||||
@@ -76,6 +81,23 @@ namespace AzFramework
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportControllerList::ResetInputChannels()
|
||||
{
|
||||
// We don't need to send this while we're disabled, we're guaranteed to call ResetInputChannels after being re-enabled.
|
||||
if (!IsEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& controllerList : m_controllers)
|
||||
{
|
||||
for (const auto& controller : controllerList.second)
|
||||
{
|
||||
controller->ResetInputChannels();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ViewportControllerList::DispatchInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event)
|
||||
{
|
||||
if (auto priorityListIt = m_controllers.find(event.m_priority); priorityListIt != m_controllers.end())
|
||||
@@ -106,6 +128,11 @@ namespace AzFramework
|
||||
|
||||
void ViewportControllerList::UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event)
|
||||
{
|
||||
if (!IsEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If our event priority is "custom", we should dispatch at all priority levels in reverse order
|
||||
// Reverse order lets high priority controllers get the last say in viewport update operations
|
||||
using AzFramework::ViewportControllerPriority;
|
||||
@@ -174,4 +201,22 @@ namespace AzFramework
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ViewportControllerList::IsEnabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
void ViewportControllerList::SetEnabled(bool enabled)
|
||||
{
|
||||
if (m_enabled != enabled)
|
||||
{
|
||||
m_enabled = enabled;
|
||||
// If we've been re-enabled, reset our input channels as they may have missed state changes.
|
||||
if (m_enabled)
|
||||
{
|
||||
ResetInputChannels();
|
||||
}
|
||||
}
|
||||
}
|
||||
} //namespace AzFramework
|
||||
|
||||
@@ -37,6 +37,9 @@ namespace AzFramework
|
||||
//! either a controller returns true to consume the event in OnInputChannelEvent or the controller list is exhausted.
|
||||
//! InputChannelEvents are sent to controllers in priority order (from the lowest priority value to the highest).
|
||||
bool HandleInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event) override;
|
||||
//! Dispatches a ResetInputChannels call to all controllers registered to this list.
|
||||
//! Calls to controllers are made in an undefined order.
|
||||
void ResetInputChannels() override;
|
||||
//! Dispatches an update tick to all controllers registered to this list.
|
||||
//! This occurs in *reverse* priority order (i.e. from the highest priority value to the lowest) so that
|
||||
//! controllers with the highest registration priority may override the transforms of the controllers with the
|
||||
@@ -50,6 +53,12 @@ namespace AzFramework
|
||||
//! All ViewportControllerLists have a priority of Custom to ensure
|
||||
//! that they receive events at all priorities from any parent controllers.
|
||||
AzFramework::ViewportControllerPriority GetPriority() const { return ViewportControllerPriority::DispatchToAllPriorities; }
|
||||
//! Returns true if this controller list is enabled, i.e.
|
||||
//! it is accepting and forwarding input and update events to its children.
|
||||
bool IsEnabled() const;
|
||||
//! Set this controller list's enabled state.
|
||||
//! If a controller list is disabled, it will ignore all input and update events rather than dispatching them to its children.
|
||||
void SetEnabled(bool enabled);
|
||||
|
||||
private:
|
||||
void SortControllers();
|
||||
@@ -58,5 +67,6 @@ namespace AzFramework
|
||||
|
||||
AZStd::unordered_map<AzFramework::ViewportControllerPriority, AZStd::vector<ViewportControllerPtr>> m_controllers;
|
||||
AZStd::unordered_set<ViewportId> m_viewports;
|
||||
bool m_enabled = true;
|
||||
};
|
||||
} //namespace AzFramework
|
||||
|
||||
@@ -679,6 +679,11 @@ void EditorViewportWidget::OnEditorNotifyEvent(EEditorNotifyEvent event)
|
||||
}
|
||||
SetCurrentCursor(STD_CURSOR_GAME);
|
||||
}
|
||||
|
||||
if (m_renderViewport)
|
||||
{
|
||||
m_renderViewport->GetControllerList()->SetEnabled(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -697,6 +702,11 @@ void EditorViewportWidget::OnEditorNotifyEvent(EEditorNotifyEvent event)
|
||||
|
||||
RestoreViewportAfterGameMode();
|
||||
}
|
||||
|
||||
if (m_renderViewport)
|
||||
{
|
||||
m_renderViewport->GetControllerList()->SetEnabled(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case eNotify_OnCloseScene:
|
||||
@@ -727,6 +737,8 @@ void EditorViewportWidget::OnEditorNotifyEvent(EEditorNotifyEvent event)
|
||||
// meters above the terrain (default terrain height is 32)
|
||||
viewTM.SetTranslation(Vec3(sx * 0.5f, sy * 0.5f, 34.0f));
|
||||
SetViewTM(viewTM);
|
||||
|
||||
UpdateScene();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -408,6 +408,13 @@ bool LegacyViewportCameraControllerInstance::HandleInputChannelEvent(const AzFra
|
||||
}
|
||||
}
|
||||
|
||||
UpdateCursorCapture(shouldCaptureCursor);
|
||||
|
||||
return shouldConsumeEvent;
|
||||
}
|
||||
|
||||
void LegacyViewportCameraControllerInstance::UpdateCursorCapture(bool shouldCaptureCursor)
|
||||
{
|
||||
if (m_capturingCursor != shouldCaptureCursor)
|
||||
{
|
||||
if (shouldCaptureCursor)
|
||||
@@ -427,8 +434,14 @@ bool LegacyViewportCameraControllerInstance::HandleInputChannelEvent(const AzFra
|
||||
|
||||
m_capturingCursor = shouldCaptureCursor;
|
||||
}
|
||||
}
|
||||
|
||||
return shouldConsumeEvent;
|
||||
void LegacyViewportCameraControllerInstance::ResetInputChannels()
|
||||
{
|
||||
m_modifiers = 0;
|
||||
m_pressedKeys.clear();
|
||||
UpdateCursorCapture(false);
|
||||
m_inRotateMode = m_inMoveMode = m_inOrbitMode = m_inZoomMode = false;
|
||||
}
|
||||
|
||||
void LegacyViewportCameraControllerInstance::UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event)
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace SandboxEditor
|
||||
explicit LegacyViewportCameraControllerInstance(AzFramework::ViewportId viewport);
|
||||
|
||||
bool HandleInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event) override;
|
||||
void ResetInputChannels() override;
|
||||
void UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event) override;
|
||||
|
||||
private:
|
||||
@@ -53,6 +54,7 @@ namespace SandboxEditor
|
||||
bool HandleMouseMove(const AzFramework::ScreenPoint& currentMousePos, const AzFramework::ScreenPoint& previousMousePos);
|
||||
bool HandleMouseWheel(float zDelta);
|
||||
bool IsKeyDown(Qt::Key key) const;
|
||||
void UpdateCursorCapture(bool shouldCaptureCursor);
|
||||
|
||||
bool m_inRotateMode = false;
|
||||
bool m_inMoveMode = false;
|
||||
|
||||
@@ -202,6 +202,12 @@ bool ViewportManipulatorControllerInstance::HandleInputChannelEvent(const AzFram
|
||||
return interactionHandled;
|
||||
}
|
||||
|
||||
void ViewportManipulatorControllerInstance::ResetInputChannels()
|
||||
{
|
||||
m_pendingDoubleClicks.clear();
|
||||
m_state = AzToolsFramework::ViewportInteraction::MouseInteraction();
|
||||
}
|
||||
|
||||
void ViewportManipulatorControllerInstance::UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event)
|
||||
{
|
||||
m_curTime = event.m_time;
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace SandboxEditor
|
||||
explicit ViewportManipulatorControllerInstance(AzFramework::ViewportId viewport);
|
||||
|
||||
bool HandleInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event) override;
|
||||
void ResetInputChannels() override;
|
||||
void UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -77,6 +77,8 @@ namespace AZ
|
||||
void OnRenderPipelineAdded(RenderPipelinePtr pipeline) override;
|
||||
//! Ensures our default view remains set when our scene's render pipelines are modified.
|
||||
void OnRenderPipelineRemoved(RenderPipeline* pipeline) override;
|
||||
//! OnBeginPrepareRender is forwarded to our RenderTick notification to allow subscribers to do rendering.
|
||||
void OnBeginPrepareRender() override;
|
||||
|
||||
//WindowNotificationBus interface
|
||||
//! Used to fire a notification when our window resizes
|
||||
|
||||
@@ -104,12 +104,16 @@ namespace AZ
|
||||
// add the current pipeline to next render tick if it's not already added.
|
||||
if (m_currentPipeline && m_currentPipeline->GetRenderMode() != RenderPipeline::RenderMode::RenderOnce)
|
||||
{
|
||||
ViewportContextNotificationBus::Event(GetName(), &ViewportContextNotificationBus::Events::OnRenderTick);
|
||||
ViewportContextIdNotificationBus::Event(GetId(), &ViewportContextIdNotificationBus::Events::OnRenderTick);
|
||||
m_currentPipeline->AddToRenderTickOnce();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportContext::OnBeginPrepareRender()
|
||||
{
|
||||
ViewportContextNotificationBus::Event(GetName(), &ViewportContextNotificationBus::Events::OnRenderTick);
|
||||
ViewportContextIdNotificationBus::Event(GetId(), &ViewportContextIdNotificationBus::Events::OnRenderTick);
|
||||
}
|
||||
|
||||
AZ::Name ViewportContext::GetName() const
|
||||
{
|
||||
return m_name;
|
||||
|
||||
@@ -57,9 +57,14 @@ namespace AZ
|
||||
return;
|
||||
}
|
||||
viewportData.context = viewportContext;
|
||||
auto onSizeChanged = [contextName, viewportId](AzFramework::WindowSize size)
|
||||
auto onSizeChanged = [this, viewportId](AzFramework::WindowSize size)
|
||||
{
|
||||
ViewportContextNotificationBus::Event(contextName, &ViewportContextNotificationBus::Events::OnViewportSizeChanged, size);
|
||||
// Ensure we emit OnViewportSizeChanged with the correct name.
|
||||
auto viewportContext = this->GetViewportContextById(viewportId);
|
||||
if (viewportContext)
|
||||
{
|
||||
ViewportContextNotificationBus::Event(viewportContext->GetName(), &ViewportContextNotificationBus::Events::OnViewportSizeChanged, size);
|
||||
}
|
||||
ViewportContextIdNotificationBus::Event(viewportId, &ViewportContextIdNotificationBus::Events::OnViewportSizeChanged, size);
|
||||
};
|
||||
viewportContext->m_name = contextName;
|
||||
@@ -174,6 +179,8 @@ namespace AZ
|
||||
GetOrCreateViewStackForContext(newContextName);
|
||||
viewportContext->m_name = newContextName;
|
||||
UpdateViewForContext(newContextName);
|
||||
// Ensure anyone listening on per-name viewport size updates gets notified.
|
||||
ViewportContextNotificationBus::Event(newContextName, &ViewportContextNotificationBus::Events::OnViewportSizeChanged, viewportContext->GetViewportSize());
|
||||
}
|
||||
|
||||
void ViewportContextManager::EnumerateViewportContexts(AZStd::function<void(ViewportContextPtr)> visitorFunction)
|
||||
|
||||
@@ -58,6 +58,15 @@ namespace AZ
|
||||
auto atomViewportRequests = AZ::Interface<AZ::RPI::ViewportContextRequestsInterface>::Get();
|
||||
const AZ::Name contextName = atomViewportRequests->GetDefaultViewportContextName();
|
||||
AZ::RPI::ViewportContextNotificationBus::Handler::BusConnect(contextName);
|
||||
|
||||
#if defined(IMGUI_ENABLED)
|
||||
ImGui::ImGuiManagerListenerBus::Broadcast(&ImGui::IImGuiManagerListener::SetResolutionMode, ImGui::ImGuiResolutionMode::LockToResolution);
|
||||
auto defaultViewportContext = atomViewportRequests->GetDefaultViewportContext();
|
||||
if (defaultViewportContext)
|
||||
{
|
||||
OnViewportSizeChanged(defaultViewportContext->GetViewportSize());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ImguiAtomSystemComponent::Deactivate()
|
||||
@@ -75,6 +84,13 @@ namespace AZ
|
||||
{
|
||||
#if defined(IMGUI_ENABLED)
|
||||
ImGui::ImGuiManagerListenerBus::Broadcast(&ImGui::IImGuiManagerListener::Render);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ImguiAtomSystemComponent::OnViewportSizeChanged(AzFramework::WindowSize size)
|
||||
{
|
||||
#if defined(IMGUI_ENABLED)
|
||||
ImGui::ImGuiManagerListenerBus::Broadcast(&ImGui::IImGuiManagerListener::SetImGuiRenderResolution, ImVec2{aznumeric_cast<float>(size.m_width), aznumeric_cast<float>(size.m_height)});
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace AZ
|
||||
|
||||
// ViewportContextNotificationBus overrides...
|
||||
void OnRenderTick() override;
|
||||
void OnViewportSizeChanged(AzFramework::WindowSize size) override;
|
||||
|
||||
DebugConsole m_debugConsole;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user