From 63526655a270762f8291b600be0fff741629ff55 Mon Sep 17 00:00:00 2001 From: jjjoness <82226755+jjjoness@users.noreply.github.com> Date: Fri, 30 Apr 2021 14:27:55 +0100 Subject: [PATCH 01/12] Fixed asset source tree layout in AssetProcessor --- .../assetprocessor_gui_files.cmake | 4 ++- .../native/ui/JobTreeViewItemDelegate.cpp | 25 +++++++++++++++ .../native/ui/JobTreeViewItemDelegate.h | 32 +++++++++++++++++++ .../AssetProcessor/native/ui/MainWindow.cpp | 2 ++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.cpp create mode 100644 Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.h diff --git a/Code/Tools/AssetProcessor/assetprocessor_gui_files.cmake b/Code/Tools/AssetProcessor/assetprocessor_gui_files.cmake index 79771a9d37..ab7a1e4a9f 100644 --- a/Code/Tools/AssetProcessor/assetprocessor_gui_files.cmake +++ b/Code/Tools/AssetProcessor/assetprocessor_gui_files.cmake @@ -31,7 +31,9 @@ set(FILES native/ui/GoToButton.h native/ui/GoToButton.cpp native/ui/GoToButton.ui - native/ui/MainWindow.h + native/ui/JobTreeViewItemDelegate.h + native/ui/JobTreeViewItemDelegate.cpp + native/ui/MainWindow.ui native/ui/MainWindow.cpp native/ui/MainWindow.ui native/ui/ProductAssetDetailsPanel.h diff --git a/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.cpp b/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.cpp new file mode 100644 index 0000000000..e0da06ad79 --- /dev/null +++ b/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.cpp @@ -0,0 +1,25 @@ +/* +* 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. +* +*/ + +#include "JobTreeViewItemDelegate.h" + +namespace AssetProcessor +{ + void JobTreeViewItemDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const + { + AzQtComponents::TableViewItemDelegate::initStyleOption(option, index); + + option->features &= ~(QStyleOptionViewItem::WrapText); + } +} + +#include diff --git a/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.h b/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.h new file mode 100644 index 0000000000..f0e74145ee --- /dev/null +++ b/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.h @@ -0,0 +1,32 @@ +#pragma once + +/* +* 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. +* +*/ + +#if !defined(Q_MOC_RUN) +#include +#endif + +namespace AssetProcessor +{ + class JobTreeViewItemDelegate + : public AzQtComponents::TableViewItemDelegate + { + Q_OBJECT + + public: + using AzQtComponents::TableViewItemDelegate::TableViewItemDelegate; + + protected: + void initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const override; + }; +} // namespace AssetProcessor diff --git a/Code/Tools/AssetProcessor/native/ui/MainWindow.cpp b/Code/Tools/AssetProcessor/native/ui/MainWindow.cpp index 3a874a464c..79019ab8fc 100644 --- a/Code/Tools/AssetProcessor/native/ui/MainWindow.cpp +++ b/Code/Tools/AssetProcessor/native/ui/MainWindow.cpp @@ -32,6 +32,7 @@ #include #include "native/ui/ui_MainWindow.h" +#include "native/ui/JobTreeViewItemDelegate.h" #include "../utilities/GUIApplicationManager.h" @@ -221,6 +222,7 @@ void MainWindow::Activate() ui->jobTreeView->setModel(m_jobSortFilterProxy); ui->jobTreeView->setSortingEnabled(true); ui->jobTreeView->header()->setDefaultAlignment(Qt::AlignVCenter | Qt::AlignHCenter); + ui->jobTreeView->setItemDelegate(new AssetProcessor::JobTreeViewItemDelegate(ui->jobTreeView)); ui->jobTreeView->setToolTip(tr("Click to view Job Log")); From a45c348f4fe71044f97982d84da68a18ba8189d8 Mon Sep 17 00:00:00 2001 From: Brian Herrera <19914798+brianherrera@users.noreply.github.com> Date: Fri, 30 Apr 2021 09:53:21 -0700 Subject: [PATCH 02/12] Fix root folder path for canary files This is related to the previous change to move these scripts. Validator will fail to find the canary files when running the script. --- scripts/scrubbing/validator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/scrubbing/validator.py b/scripts/scrubbing/validator.py index e442e443c8..ac7c45554f 100755 --- a/scripts/scrubbing/validator.py +++ b/scripts/scrubbing/validator.py @@ -312,7 +312,7 @@ class Validator(object): # Once we split the repos we will have to worry about multiple root points etc. but that is a problem for future us. # All the packaging safelist stuff goes away once repo is split for platforms this_path = Path(__file__).resolve() - root_folder = this_path.parents[5] + root_folder = this_path.parents[2] relative_folder = os.path.relpath(this_path.parent, root_folder) canary_file = os.path.join(root_folder, 'restricted', platform, relative_folder, platform.lower() + '_canary.txt') try: From 5eeeaf4346904cbb0308ceb206a12c311528e965 Mon Sep 17 00:00:00 2001 From: AMZN-koppersr <82230785+AMZN-koppersr@users.noreply.github.com> Date: Sat, 1 May 2021 13:26:54 -0700 Subject: [PATCH 03/12] Fixed several release build compile errors. --- Code/Framework/AzFramework/AzFramework/Scene/Scene.inl | 2 +- .../AzToolsFramework/Prefab/PrefabSystemComponent.cpp | 2 +- .../ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp | 2 +- Gems/LyShine/Code/Source/LyShineDebug.cpp | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Code/Framework/AzFramework/AzFramework/Scene/Scene.inl b/Code/Framework/AzFramework/AzFramework/Scene/Scene.inl index b0c1a18b08..360ab93436 100644 --- a/Code/Framework/AzFramework/AzFramework/Scene/Scene.inl +++ b/Code/Framework/AzFramework/AzFramework/Scene/Scene.inl @@ -51,7 +51,7 @@ namespace AzFramework } template - bool Scene::UnsetSubsystem(const T& system) + bool Scene::UnsetSubsystem([[maybe_unused]] const T& system) { const AZ::TypeId& targetType = azrtti_typeid(); const size_t systemKeysCount = m_systemKeys.size(); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp index 3f660bb73b..2570367049 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp @@ -770,8 +770,8 @@ namespace AzToolsFramework return false; } - Template& sourceTemplate = sourceTemplateReference->get(); #if defined(AZ_ENABLE_TRACING) + Template& sourceTemplate = sourceTemplateReference->get(); Template& targetTemplate = targetTemplateReference->get(); #endif diff --git a/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp b/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp index 34e7af688c..8493b78171 100644 --- a/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp +++ b/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp @@ -99,7 +99,7 @@ namespace AZ #endif } - void ImguiAtomSystemComponent::OnViewportSizeChanged(AzFramework::WindowSize size) + void ImguiAtomSystemComponent::OnViewportSizeChanged([[maybe_unused]] AzFramework::WindowSize size) { #if defined(IMGUI_ENABLED) ImGui::ImGuiManagerBus::Broadcast([this, size](ImGui::ImGuiManagerBus::Events* imgui) diff --git a/Gems/LyShine/Code/Source/LyShineDebug.cpp b/Gems/LyShine/Code/Source/LyShineDebug.cpp index 5ea01c5c1e..76b4030106 100644 --- a/Gems/LyShine/Code/Source/LyShineDebug.cpp +++ b/Gems/LyShine/Code/Source/LyShineDebug.cpp @@ -115,11 +115,13 @@ static int Create2DTexture(int width, int height, byte* data, ETEX_Format format #endif #endif +#if !defined(_RELEASE) static AZ::Vector2 GetTextureSize(AZ::Data::Instance image) { AZ::RHI::Size size = image->GetDescriptor().m_size; return AZ::Vector2(size.m_width, size.m_height); } +#endif //////////////////////////////////////////////////////////////////////////////////////////////////// #if !defined(_RELEASE) From fae33e92354a93b303976dfc300735e22cb10bcb Mon Sep 17 00:00:00 2001 From: guthadam Date: Sun, 2 May 2021 17:08:21 -0500 Subject: [PATCH 04/12] ATOM-15439 Implement basic local socket and server for IPC in material editor and other tools This replaces grid hub usage in the material editor. It allows material editor and other tools to intercommunicate on the local host. This will allow enforcing that there is only one instance of the material editor running. Opening a second instance will forward command line options to the first instance running a local server. https://jira.agscollab.com/browse/ATOM-15439 https://jira.agscollab.com/browse/ATOM-13742 --- .../AtomToolsFramework/Code/CMakeLists.txt | 1 + .../Communication/LocalServer.h | 56 +++++++++ .../Communication/LocalSocket.h | 45 ++++++++ .../Code/Source/Communication/LocalServer.cpp | 108 ++++++++++++++++++ .../Code/Source/Communication/LocalSocket.cpp | 86 ++++++++++++++ .../Code/atomtoolsframework_files.cmake | 4 + .../Tools/MaterialEditor/Code/CMakeLists.txt | 1 + .../Document/MaterialDocumentModule.cpp | 2 - .../MaterialDocumentSystemComponent.cpp | 16 --- .../MaterialDocumentSystemComponent.h | 7 -- .../Code/Source/MaterialEditorApplication.cpp | 81 ++++++++++--- .../Code/Source/MaterialEditorApplication.h | 19 +-- .../Tools/MaterialEditor/Code/Source/main.cpp | 46 ++++---- .../ShaderManagementConsoleDocumentModule.cpp | 2 - ...nagementConsoleDocumentSystemComponent.cpp | 16 --- ...ManagementConsoleDocumentSystemComponent.h | 7 -- .../EditorMaterialSystemComponent.cpp | 35 +----- .../Material/EditorMaterialSystemComponent.h | 9 -- 18 files changed, 406 insertions(+), 135 deletions(-) create mode 100644 Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalServer.h create mode 100644 Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalSocket.h create mode 100644 Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalServer.cpp create mode 100644 Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalSocket.cpp diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/CMakeLists.txt b/Gems/Atom/Tools/AtomToolsFramework/Code/CMakeLists.txt index fb4750ce93..4cd6ad8182 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/CMakeLists.txt +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/CMakeLists.txt @@ -33,6 +33,7 @@ ly_add_target( AZ::AzQtComponents 3rdParty::Qt::Core 3rdParty::Qt::Gui + 3rdParty::Qt::Network 3rdParty::Qt::Widgets 3rdParty::Python Gem::Atom_RPI.Edit diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalServer.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalServer.h new file mode 100644 index 0000000000..4482566113 --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalServer.h @@ -0,0 +1,56 @@ +/* + * 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 + +#if !defined(Q_MOC_RUN) +#include +#include +#include +#include +#include +#endif + +namespace AtomToolsFramework +{ + //! A named local server that will manage connections and forward recieved data + class LocalServer : public QObject + { + Q_OBJECT + public: + LocalServer(); + ~LocalServer(); + + //! Start a named local server + bool Connect(const QString& serverName); + + //! Stop the server + void Disconnect(); + + //! Get server status + bool IsConnected() const; + + using ReadHandler = AZStd::function; + + //! Set a handler that recieved data will be forwarded to + void SetReadHandler(ReadHandler handler); + + private: + void AddConnection(QLocalSocket* connection); + void ReadFromConnection(QLocalSocket* connection); + void DeleteConnection(QLocalSocket* connection); + + QString m_serverName; + QLocalServer m_server; + ReadHandler m_readHandler; + }; +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalSocket.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalSocket.h new file mode 100644 index 0000000000..4eb4d533ed --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalSocket.h @@ -0,0 +1,45 @@ +/* + * 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 + +#if !defined(Q_MOC_RUN) +#include +#endif + +namespace AtomToolsFramework +{ + //! LocalSocket enables interprocess communication by establ;ishing a connection and sending data to a LocalServer + class LocalSocket : public QObject + { + Q_OBJECT + public: + LocalSocket(); + ~LocalSocket(); + + //! Attempt to connect to a named local server + bool Connect(const QString& serverName); + + //! Sever connection from server + void Disconnect(); + + //! Get the sockets connection status + bool IsConnected() const; + + //! Send a stream of data to the connected local server + bool Send(const QByteArray& buffer); + + private: + QString m_serverName; + QLocalSocket m_socket; + }; +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalServer.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalServer.cpp new file mode 100644 index 0000000000..6f26b00c4f --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalServer.cpp @@ -0,0 +1,108 @@ +/* + * 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. + * + */ + +#include +#include +#include + +namespace AtomToolsFramework +{ + LocalServer::LocalServer() + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Creating local server\n"); + m_server.setSocketOptions(QLocalServer::WorldAccessOption); + + QObject::connect(&m_server, &QLocalServer::newConnection, this, [this]() { AddConnection(m_server.nextPendingConnection()); }); + } + + LocalServer::~LocalServer() + { + Disconnect(); + } + + bool LocalServer::Connect(const QString& serverName) + { + Disconnect(); + + m_serverName = serverName; + + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Starting: %s\n", m_serverName.toUtf8().constData()); + if (m_server.listen(m_serverName)) + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Started: %s\n", m_serverName.toUtf8().constData()); + return true; + } + + if (m_server.serverError() == QAbstractSocket::AddressInUseError) + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Restarting: %s\n", m_serverName.toUtf8().constData()); + Disconnect(); + + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Starting: %s\n", m_serverName.toUtf8().constData()); + if (m_server.listen(m_serverName)) + { + return true; + } + } + + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Starting failed: %s\n", m_serverName.toUtf8().constData()); + Disconnect(); + return false; + } + + void LocalServer::Disconnect() + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Disconnecting: %s\n", m_serverName.toUtf8().constData()); + QLocalServer::removeServer(m_serverName); + } + + bool LocalServer::IsConnected() const + { + return m_server.isListening(); + } + + void LocalServer::SetReadHandler(LocalServer::ReadHandler handler) + { + m_readHandler = handler; + } + + void LocalServer::AddConnection(QLocalSocket* connection) + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Connection added: %s\n", m_serverName.toUtf8().constData()); + QObject::connect(connection, &QLocalSocket::readyRead, this, [this, connection]() { ReadFromConnection(connection); }); + QObject::connect(connection, &QLocalSocket::disconnected, this, [this, connection]() { DeleteConnection(connection); }); + } + + void LocalServer::ReadFromConnection(QLocalSocket* connection) + { + if (connection) + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Data received: %s\n", m_serverName.toUtf8().constData()); + QByteArray buffer = connection->readAll(); + if (m_readHandler) + { + m_readHandler(buffer); + } + } + } + + void LocalServer::DeleteConnection(QLocalSocket* connection) + { + if (connection) + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Deleting connection: %s\n", m_serverName.toUtf8().constData()); + connection->deleteLater(); + } + } +} // namespace AtomToolsFramework + +#include diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalSocket.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalSocket.cpp new file mode 100644 index 0000000000..020998bf1a --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalSocket.cpp @@ -0,0 +1,86 @@ +/* + * 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. + * + */ + +#include +#include +#include +#include + +namespace AtomToolsFramework +{ + LocalSocket::LocalSocket() + { + } + + LocalSocket::~LocalSocket() + { + Disconnect(); + } + + bool LocalSocket::Connect(const QString& serverName) + { + Disconnect(); + + m_serverName = serverName; + + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Connecting to: %s\n", m_serverName.toUtf8().constData()); + m_socket.connectToServer(m_serverName); + + if (IsConnected()) + { + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Waiting for connection to: %s\n", m_serverName.toUtf8().constData()); + if (m_socket.waitForConnected()) + { + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Connected to: %s\n", m_serverName.toUtf8().constData()); + return true; + } + } + + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Connecting failed: %s\n", m_serverName.toUtf8().constData()); + Disconnect(); + return false; + } + + void LocalSocket::Disconnect() + { + if (IsConnected()) + { + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Disconnecting from: %s\n", m_serverName.toUtf8().constData()); + m_socket.disconnectFromServer(); + m_socket.waitForDisconnected(); + + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Closing socket\n"); + m_socket.close(); + } + } + + bool LocalSocket::IsConnected() const + { + return m_socket.isOpen(); + } + + bool LocalSocket::Send(const QByteArray& buffer) + { + if (IsConnected()) + { + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Sending data to: %s\n", m_serverName.toUtf8().constData()); + m_socket.write(buffer); + + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Waiting for write to: %s\n", m_serverName.toUtf8().constData()); + m_socket.waitForBytesWritten(); + return true; + } + return false; + } +} // namespace AtomToolsFramework + +#include diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake index e8539711f7..d8ceccc724 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake @@ -10,6 +10,8 @@ # set(FILES + Include/AtomToolsFramework/Communication/LocalServer.h + Include/AtomToolsFramework/Communication/LocalSocket.h Include/AtomToolsFramework/Debug/TraceRecorder.h Include/AtomToolsFramework/DynamicProperty/DynamicProperty.h Include/AtomToolsFramework/DynamicProperty/DynamicPropertyGroup.h @@ -22,6 +24,8 @@ set(FILES Include/AtomToolsFramework/Util/MaterialPropertyUtil.h Include/AtomToolsFramework/Util/Util.h Include/AtomToolsFramework/Viewport/RenderViewportWidget.h + Source/Communication/LocalServer.cpp + Source/Communication/LocalSocket.cpp Source/Debug/TraceRecorder.cpp Source/DynamicProperty/DynamicProperty.cpp Source/DynamicProperty/DynamicPropertyGroup.cpp diff --git a/Gems/Atom/Tools/MaterialEditor/Code/CMakeLists.txt b/Gems/Atom/Tools/MaterialEditor/Code/CMakeLists.txt index 40d6a8f30a..134f605200 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/CMakeLists.txt +++ b/Gems/Atom/Tools/MaterialEditor/Code/CMakeLists.txt @@ -93,6 +93,7 @@ ly_add_target( ly_add_target( NAME MaterialEditor EXECUTABLE NAMESPACE Gem + AUTOMOC FILES_CMAKE materialeditor_files.cmake Source/Platform/${PAL_PLATFORM_NAME}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentModule.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentModule.cpp index a7aecf0b1f..b1a795b9f9 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentModule.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentModule.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -32,7 +31,6 @@ namespace MaterialEditor return AZ::ComponentTypeList{ azrtti_typeid(), azrtti_typeid(), - azrtti_typeid(), }; } } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp index 2fd1aac211..dbb1d18e49 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp @@ -109,7 +109,6 @@ namespace MaterialEditor void MaterialDocumentSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { - required.push_back(AZ_CRC("TargetManagerService", 0x6d5708bc)); required.push_back(AZ_CRC("AssetProcessorToolsConnection", 0x734669bc)); required.push_back(AZ_CRC("AssetDatabaseService", 0x3abf5601)); required.push_back(AZ_CRC("PropertyManagerService", 0x63a3d7ad)); @@ -135,31 +134,16 @@ namespace MaterialEditor m_documentMap.clear(); MaterialDocumentSystemRequestBus::Handler::BusConnect(); MaterialDocumentNotificationBus::Handler::BusConnect(); - AzFramework::TmMsgBus::Handler::BusConnect(AZ_CRC("OpenInMaterialEditor", 0x9f92aac8)); } void MaterialDocumentSystemComponent::Deactivate() { AZ::TickBus::Handler::BusDisconnect(); - AzFramework::TmMsgBus::Handler::BusDisconnect(); MaterialDocumentNotificationBus::Handler::BusDisconnect(); MaterialDocumentSystemRequestBus::Handler::BusDisconnect(); m_documentMap.clear(); } - void MaterialDocumentSystemComponent::OnReceivedMsg(AzFramework::TmMsgPtr msg) - { - if (msg->GetId() == AZ_CRC("OpenInMaterialEditor", 0x9f92aac8)) - { - const char* documentPath = reinterpret_cast(msg->GetCustomBlob()); - MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::OpenDocument, documentPath); - } - else - { - AZ_Assert(false, "We received a message of an unrecognized class type!"); - } - } - AZ::Uuid MaterialDocumentSystemComponent::CreateDocument() { auto document = AZStd::make_unique(); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h index b6c541421d..4b0ee424a7 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -35,7 +34,6 @@ namespace MaterialEditor class MaterialDocumentSystemComponent : public AZ::Component , private AZ::TickBus::Handler - , private AzFramework::TmMsgBus::Handler , private MaterialDocumentNotificationBus::Handler , private MaterialDocumentSystemRequestBus::Handler { @@ -72,11 +70,6 @@ namespace MaterialEditor void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; //////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // AzFramework::TmMsgBus::Handler overrides... - void OnReceivedMsg(AzFramework::TmMsgPtr msg) override; - ////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////// // MaterialDocumentSystemRequestBus::Handler overrides... AZ::Uuid CreateDocument() override; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp index 66be1c23bb..ea82210814 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp @@ -90,6 +90,14 @@ namespace MaterialEditor }); } + MaterialEditorApplication::~MaterialEditorApplication() + { + AzToolsFramework::EditorPythonConsoleNotificationBus::Handler::BusDisconnect(); + AzToolsFramework::AssetDatabase::AssetDatabaseRequestsBus::Handler::BusDisconnect(); + MaterialEditorWindowNotificationBus::Handler::BusDisconnect(); + AZ::Debug::TraceMessageBus::Handler::BusDisconnect(); + } + void MaterialEditorApplication::CreateReflectionManager() { Application::CreateReflectionManager(); @@ -299,12 +307,12 @@ namespace MaterialEditor return false; } - void MaterialEditorApplication::ProcessCommandLine() + void MaterialEditorApplication::ProcessCommandLine(const AZ::CommandLine& commandLine) { const AZStd::string timeoputSwitchName = "timeout"; - if (m_commandLine.HasSwitch(timeoputSwitchName)) + if (commandLine.HasSwitch(timeoputSwitchName)) { - const AZStd::string& timeoutValue = m_commandLine.GetSwitchValue(timeoputSwitchName, 0); + const AZStd::string& timeoutValue = commandLine.GetSwitchValue(timeoputSwitchName, 0); const uint32_t timeoutInMs = atoi(timeoutValue.c_str()); AZ_Printf("MaterialEditor", "Timeout scheduled, shutting down in %u ms", timeoutInMs); QTimer::singleShot(timeoutInMs, [this] { @@ -315,10 +323,10 @@ namespace MaterialEditor // Process command line options for running one or more python scripts on startup const AZStd::string runPythonScriptSwitchName = "runpython"; - size_t runPythonScriptCount = m_commandLine.GetNumSwitchValues(runPythonScriptSwitchName); + size_t runPythonScriptCount = commandLine.GetNumSwitchValues(runPythonScriptSwitchName); for (size_t runPythonScriptIndex = 0; runPythonScriptIndex < runPythonScriptCount; ++runPythonScriptIndex) { - const AZStd::string runPythonScriptPath = m_commandLine.GetSwitchValue(runPythonScriptSwitchName, runPythonScriptIndex); + const AZStd::string runPythonScriptPath = commandLine.GetSwitchValue(runPythonScriptSwitchName, runPythonScriptIndex); AZStd::vector runPythonArgs; AZ_Printf("MaterialEditor", "Launching script: %s", runPythonScriptPath.c_str()); @@ -329,17 +337,17 @@ namespace MaterialEditor } // Process command line options for opening one or more material documents on startup - size_t openDocumentCount = m_commandLine.GetNumMiscValues(); + size_t openDocumentCount = commandLine.GetNumMiscValues(); for (size_t openDocumentIndex = 0; openDocumentIndex < openDocumentCount; ++openDocumentIndex) { - const AZStd::string openDocumentPath = m_commandLine.GetMiscValue(openDocumentIndex); + const AZStd::string openDocumentPath = commandLine.GetMiscValue(openDocumentIndex); AZ_Printf("MaterialEditor", "Opening document: %s", openDocumentPath.c_str()); MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::OpenDocument, openDocumentPath); } const AZStd::string exitAfterCommandsSwitchName = "exitaftercommands"; - if (m_commandLine.HasSwitch(exitAfterCommandsSwitchName)) + if (commandLine.HasSwitch(exitAfterCommandsSwitchName)) { ExitMainLoop(); } @@ -409,9 +417,50 @@ namespace MaterialEditor bool MaterialEditorApplication::LaunchDiscoveryService() { - const QStringList arguments = { "-fail_silently" }; + // Determine if this is the first launch of the tool by attempting to connect to a running server + if (m_socket.Connect(QApplication::applicationName())) + { + // If the server was located, the application is already running. + // Forward commandline options to other application instance. + QByteArray buffer; + buffer.append("ProcessCommandLine:"); + for (int argi = 1; argi < m_argC; ++argi) + { + buffer.append(QString(m_argV[argi]).append("\n").toUtf8()); + } + m_socket.Send(buffer); + m_socket.Disconnect(); + return false; + } - return AtomToolsFramework::LaunchTool("GridHub", AZ_TRAIT_MATERIALEDITOR_EXT, arguments); + // Setup server to handle basic commands + m_server.SetReadHandler([this](const QByteArray& buffer) { + // Handle commmand line params from connected socket + if (buffer.startsWith("ProcessCommandLine:")) + { + // Remove header and parse commands + AZStd::string params(buffer.data(), buffer.size()); + params = params.substr(strlen("ProcessCommandLine:")); + + AZStd::vector tokens; + AZ::StringFunc::Tokenize(params, tokens, "\n"); + + if (!tokens.empty()) + { + AZ::CommandLine commandLine; + commandLine.Parse(tokens); + ProcessCommandLine(commandLine); + } + } + }); + + // Launch local server + if (!m_server.Connect(QApplication::applicationName())) + { + return false; + } + + return true; } void MaterialEditorApplication::StartInternal() @@ -421,10 +470,14 @@ namespace MaterialEditor return; } - //[GFX TODO][ATOM-415] Try to factor out some of this stuff with AtomSampleViewerApplication - WriteStartupLog(); + if (!LaunchDiscoveryService()) + { + ExitMainLoop(); + return; + } + AzToolsFramework::AssetDatabase::AssetDatabaseRequestsBus::Handler::BusConnect(); AzToolsFramework::AssetBrowser::AssetDatabaseLocationNotificationBus::Broadcast(&AzToolsFramework::AssetBrowser::AssetDatabaseLocationNotifications::OnDatabaseInitialized); @@ -434,8 +487,6 @@ namespace MaterialEditor LoadSettings(); - LaunchDiscoveryService(); - MaterialEditorWindowNotificationBus::Handler::BusConnect(); MaterialEditor::MaterialEditorWindowFactoryRequestBus::Broadcast( @@ -450,7 +501,7 @@ namespace MaterialEditor } // Delay execution of commands and scripts post initialization - QTimer::singleShot(0, [this]() { ProcessCommandLine(); }); + QTimer::singleShot(0, [this]() { ProcessCommandLine(m_commandLine); }); } bool MaterialEditorApplication::GetAssetDatabaseLocation(AZStd::string& result) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h index 63ccbf3cec..2c66fd7c16 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h @@ -12,22 +12,20 @@ #pragma once - +#include +#include +#include +#include #include #include -#include #include - +#include #include #include #include - #include #include -#include -#include - #include #include @@ -51,7 +49,7 @@ namespace MaterialEditor using Base = AzFramework::Application; MaterialEditorApplication(int* argc, char*** argv); - virtual ~MaterialEditorApplication() = default; + virtual ~MaterialEditorApplication(); ////////////////////////////////////////////////////////////////////////// // AzFramework::Application @@ -110,7 +108,7 @@ namespace MaterialEditor void CompileCriticalAssets(); - void ProcessCommandLine(); + void ProcessCommandLine(const AZ::CommandLine& commandLine); void WriteStartupLog(); void LoadSettings(); @@ -138,5 +136,8 @@ namespace MaterialEditor bool m_activatedLocalUserSettings = false; QTimer m_timer; + + AtomToolsFramework::LocalSocket m_socket; + AtomToolsFramework::LocalServer m_server; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp index 92d76c4373..1d420a35d3 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp @@ -1,30 +1,31 @@ /* -* 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. -* -*/ + * 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. + * + */ + +#if !defined(Q_MOC_RUN) +#include #include #include -#include -#include #include -#include #include -#include -#include +#include +#include #include +#include +#include -#include #include - -#include +#include +#endif int main(int argc, char** argv) { @@ -45,15 +46,16 @@ int main(int argc, char** argv) AzQtComponents::Utilities::HandleDpiAwareness(AzQtComponents::Utilities::SystemDpiAware); MaterialEditor::MaterialEditorApplication app(&argc, &argv); + + auto globalEventFilter = new AzQtComponents::GlobalEventFilter(&app); + app.installEventFilter(globalEventFilter); + AZ::IO::FixedMaxPath engineRootPath; if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr) { settingsRegistry->Get(engineRootPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder); } - auto globalEventFilter = new AzQtComponents::GlobalEventFilter(&app); - app.installEventFilter(globalEventFilter); - AzQtComponents::StyleManager styleManager(&app); styleManager.initialize(&app, engineRootPath); @@ -62,3 +64,5 @@ int main(int argc, char** argv) app.Stop(); return 0; } + +#include "main.moc" diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentModule.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentModule.cpp index f2fd70c0e6..50b2cbb53a 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentModule.cpp +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentModule.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -32,7 +31,6 @@ namespace ShaderManagementConsole return AZ::ComponentTypeList{ azrtti_typeid(), azrtti_typeid(), - azrtti_typeid(), }; } } diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.cpp index f0d72c61c3..31dabe2bac 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.cpp +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.cpp @@ -105,7 +105,6 @@ namespace ShaderManagementConsole void ShaderManagementConsoleDocumentSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { - required.push_back(AZ_CRC("TargetManagerService", 0x6d5708bc)); required.push_back(AZ_CRC("AssetProcessorToolsConnection", 0x734669bc)); required.push_back(AZ_CRC("AssetDatabaseService", 0x3abf5601)); required.push_back(AZ_CRC("PropertyManagerService", 0x63a3d7ad)); @@ -130,13 +129,11 @@ namespace ShaderManagementConsole { m_documentMap.clear(); ShaderManagementConsoleDocumentSystemRequestBus::Handler::BusConnect(); - AzFramework::TmMsgBus::Handler::BusConnect(AZ_CRC("OpenInShaderManagementConsole", 0x9f92aac8)); } void ShaderManagementConsoleDocumentSystemComponent::Deactivate() { ShaderManagementConsoleDocumentSystemRequestBus::Handler::BusDisconnect(); - AzFramework::TmMsgBus::Handler::BusDisconnect(); m_documentMap.clear(); } @@ -159,19 +156,6 @@ namespace ShaderManagementConsole return m_documentMap.erase(documentId) != 0; } - void ShaderManagementConsoleDocumentSystemComponent::OnReceivedMsg(AzFramework::TmMsgPtr msg) - { - if (msg->GetId() == AZ_CRC("OpenInShaderManagementConsole", 0x9f92aac8)) - { - const char* documentPath = reinterpret_cast(msg->GetCustomBlob()); - ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::OpenDocument, documentPath); - } - else - { - AZ_Assert(false, "We received a message of an unrecognized class type!"); - } - } - AZ::Uuid ShaderManagementConsoleDocumentSystemComponent::OpenDocument(AZStd::string_view path) { return OpenDocumentImpl(path, true); diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.h b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.h index 60c205aa72..2bd7306b8b 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.h +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.h @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -30,7 +29,6 @@ namespace ShaderManagementConsole //! ShaderManagementConsoleDocumentSystemComponent is the central component of the Shader Management Console Core gem class ShaderManagementConsoleDocumentSystemComponent : public AZ::Component - , private AzFramework::TmMsgBus::Handler , private ShaderManagementConsoleDocumentSystemRequestBus::Handler { public: @@ -55,11 +53,6 @@ namespace ShaderManagementConsole void Deactivate() override; //////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // TmMsgBus::Handler overrides... - void OnReceivedMsg(AzFramework::TmMsgPtr msg) override; - ////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////// // ShaderManagementConsoleDocumentSystemRequestBus::Handler overrides... AZ::Uuid CreateDocument() override; diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp index 94dfb39419..c32f124456 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp @@ -93,7 +93,6 @@ namespace AZ void EditorMaterialSystemComponent::Activate() { - AzFramework::TargetManagerClient::Bus::Handler::BusConnect(); EditorMaterialSystemComponentRequestBus::Handler::BusConnect(); AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusConnect(); AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusConnect(); @@ -105,7 +104,6 @@ namespace AZ void EditorMaterialSystemComponent::Deactivate() { - AzFramework::TargetManagerClient::Bus::Handler::BusDisconnect(); EditorMaterialSystemComponentRequestBus::Handler::BusDisconnect(); AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusDisconnect(); AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusDisconnect(); @@ -123,36 +121,11 @@ namespace AZ void EditorMaterialSystemComponent::OpenInMaterialEditor(const AZStd::string& sourcePath) { - if (m_materialEditorTarget.IsValid()) - { - AzFramework::TmMsg openDocumentMsg(AZ_CRC("OpenInMaterialEditor", 0x9f92aac8)); - openDocumentMsg.AddCustomBlob(sourcePath.c_str(), sourcePath.size() + 1); - AzFramework::TargetManager::Bus::Broadcast(&AzFramework::TargetManager::SendTmMessage, m_materialEditorTarget, openDocumentMsg); - } - else - { - AZ_TracePrintf("MaterialComponent", "Launching Material Editor"); + AZ_TracePrintf("MaterialComponent", "Launching Material Editor"); - QStringList arguments; - arguments.append(sourcePath.c_str()); - AtomToolsFramework::LaunchTool("MaterialEditor", ".exe", arguments); - } - } - - void EditorMaterialSystemComponent::TargetJoinedNetwork(AzFramework::TargetInfo info) - { - if (AZ::StringFunc::Equal(info.GetDisplayName(), "MaterialEditor")) - { - m_materialEditorTarget = info; - } - } - - void EditorMaterialSystemComponent::TargetLeftNetwork(AzFramework::TargetInfo info) - { - if (AZ::StringFunc::Equal(info.GetDisplayName(), "MaterialEditor")) - { - m_materialEditorTarget = {}; - } + QStringList arguments; + arguments.append(sourcePath.c_str()); + AtomToolsFramework::LaunchTool("MaterialEditor", ".exe", arguments); } void EditorMaterialSystemComponent::OnApplicationAboutToStop() diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.h index 09ad1c1b9c..cb1aac9163 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.h @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -32,7 +31,6 @@ namespace AZ class EditorMaterialSystemComponent : public AZ::Component , private EditorMaterialSystemComponentRequestBus::Handler - , private AzFramework::TargetManagerClient::Bus::Handler , private AzFramework::ApplicationLifecycleEvents::Bus::Handler , public AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler , public AzToolsFramework::EditorMenuNotificationBus::Handler @@ -57,10 +55,6 @@ namespace AZ //! EditorMaterialSystemComponentRequestBus::Handler overrides... void OpenInMaterialEditor(const AZStd::string& sourcePath) override; - //! AzFramework::TargetManagerClient::Bus::Handler overrides... - void TargetJoinedNetwork(AzFramework::TargetInfo info) override; - void TargetLeftNetwork(AzFramework::TargetInfo info) override; - // AzFramework::ApplicationLifecycleEvents overrides... void OnApplicationAboutToStop() override; @@ -74,9 +68,6 @@ namespace AZ void SetupThumbnails(); void TeardownThumbnails(); - // Material Editor target for interprocess communication with MaterialEditor - AzFramework::TargetInfo m_materialEditorTarget; - QAction* m_openMaterialEditorAction = nullptr; AZStd::unique_ptr m_materialBrowserInteractions; From f58f8805be0b4a233e94c1be05926e05d5176fc1 Mon Sep 17 00:00:00 2001 From: guthadam Date: Sun, 2 May 2021 17:16:07 -0500 Subject: [PATCH 05/12] Removed bad test code --- Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp index 1d420a35d3..8c55adba46 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp @@ -64,5 +64,3 @@ int main(int argc, char** argv) app.Stop(); return 0; } - -#include "main.moc" From 9d0f9e9e3aab5ff58e696b9581f0ab14eb8b8f15 Mon Sep 17 00:00:00 2001 From: guthadam Date: Mon, 3 May 2021 00:13:45 -0500 Subject: [PATCH 06/12] ATOM-14065 fix problems with material editor details group property descriptions Moved the code that automatically appended a script variable name to a property description out of the dynamic property class and into the material property conversion utility functions. Added proper descriptions for the material type and parent material placeholder properties https://jira.agscollab.com/browse/ATOM-14065 --- .../Code/Source/DynamicProperty/DynamicProperty.cpp | 5 +---- .../Code/Source/Util/MaterialPropertyUtil.cpp | 7 +++++++ .../Code/Source/Document/MaterialDocument.cpp | 8 ++++++-- .../Source/Material/EditorMaterialComponentInspector.cpp | 5 ++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/DynamicProperty/DynamicProperty.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/DynamicProperty/DynamicProperty.cpp index 5784355498..8afd1dc8d5 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/DynamicProperty/DynamicProperty.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/DynamicProperty/DynamicProperty.cpp @@ -211,10 +211,7 @@ namespace AtomToolsFramework AZStd::string DynamicProperty::GetDescription() const { - return AZStd::string::format("%s%s(Script Name = '%s')", - m_config.m_description.c_str(), - m_config.m_description.empty() ? "" : "\n", - m_config.m_id.GetCStr()); + return m_config.m_description; } AZ::Crc32 DynamicProperty::GetVisibility() const diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/MaterialPropertyUtil.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/MaterialPropertyUtil.cpp index 952e241143..41a627bef7 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/MaterialPropertyUtil.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/MaterialPropertyUtil.cpp @@ -91,6 +91,13 @@ namespace AtomToolsFramework propertyConfig.m_vectorLabels = propertyDefinition.m_vectorLabels; propertyConfig.m_visible = propertyDefinition.m_visibility != AZ::RPI::MaterialPropertyVisibility::Hidden; propertyConfig.m_readOnly = propertyDefinition.m_visibility == AZ::RPI::MaterialPropertyVisibility::Disabled; + + // Update the description for material properties to include script name assuming id is set beforehand + propertyConfig.m_description = AZStd::string::format( + "%s%s(Script Name = '%s')", + propertyConfig.m_description.c_str(), + propertyConfig.m_description.empty() ? "" : "\n", + propertyConfig.m_id.GetCStr()); } void ConvertToPropertyConfig(AtomToolsFramework::DynamicPropertyConfig& propertyConfig, const AZ::RPI::MaterialPropertyDynamicMetadata& propertyMetaData) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp index 3919684864..288530a4e4 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp @@ -762,6 +762,8 @@ namespace MaterialEditor // in the hierarchy are applied m_materialTypeSourceData.EnumerateProperties([this, &parentPropertyValues](const AZStd::string& groupNameId, const AZStd::string& propertyNameId, const auto& propertyDefinition) { AtomToolsFramework::DynamicPropertyConfig propertyConfig; + + // Assign id before conversion so it can be used in dynamic description propertyConfig.m_id = MaterialPropertyId(groupNameId, propertyNameId).GetCStr(); const auto& propertyIndex = m_materialAsset->GetMaterialPropertiesLayout()->FindPropertyIndex(propertyConfig.m_id); @@ -792,7 +794,8 @@ namespace MaterialEditor propertyConfig.m_nameId = "materialType"; propertyConfig.m_displayName = "Material Type"; propertyConfig.m_groupName = "Details"; - propertyConfig.m_description = propertyConfig.m_displayName; + propertyConfig.m_description = "The material type defines the layout, properties, default values, shader connections, and other " + "data needed to create and edit a derived material."; propertyConfig.m_defaultValue = AZStd::any(materialTypeAsset); propertyConfig.m_originalValue = propertyConfig.m_defaultValue; propertyConfig.m_parentValue = propertyConfig.m_defaultValue; @@ -806,7 +809,8 @@ namespace MaterialEditor propertyConfig.m_nameId = "parentMaterial"; propertyConfig.m_displayName = "Parent Material"; propertyConfig.m_groupName = "Details"; - propertyConfig.m_description = propertyConfig.m_displayName; + propertyConfig.m_description = + "The parent material provides an initial configuration whose properties are inherited and overriden by a derived material."; propertyConfig.m_defaultValue = AZStd::any(parentMaterialAsset); propertyConfig.m_originalValue = propertyConfig.m_defaultValue; propertyConfig.m_parentValue = propertyConfig.m_defaultValue; diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp index f7915bbff4..03533e142f 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp @@ -245,9 +245,12 @@ namespace AZ for (const auto& propertyDefinition : propertyListItr->second) { AtomToolsFramework::DynamicPropertyConfig propertyConfig; + + // Assign id before conversion so it can be used in dynamic description + propertyConfig.m_id = AZ::RPI::MaterialPropertyId(groupNameId, propertyDefinition.m_nameId).GetFullName(); + AtomToolsFramework::ConvertToPropertyConfig(propertyConfig, propertyDefinition); - propertyConfig.m_id = AZ::RPI::MaterialPropertyId(groupNameId, propertyDefinition.m_nameId).GetFullName(); propertyConfig.m_groupName = groupDisplayName; const auto& propertyIndex = m_editData.m_materialAsset->GetMaterialPropertiesLayout()->FindPropertyIndex(propertyConfig.m_id); propertyConfig.m_showThumbnail = true; From fe88ae12b05b4676bda91811011826e7c1f70326 Mon Sep 17 00:00:00 2001 From: jackalbe <23512001+jackalbe@users.noreply.github.com> Date: Mon, 3 May 2021 10:02:04 -0500 Subject: [PATCH 07/12] {LYN-3365} GraphObjectProxy is now hidden from Script Canvas (#478) * GraphObjectProxy is now hidden from Script Canvas * the IGraphObject has been added to the BC Jira: https://jira.agscollab.com/browse/LYN-3365 Tests: manual testing the node type is not in the SC editor --- Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.cpp b/Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.cpp index 4de42eb944..f2fda63ec4 100644 --- a/Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.cpp +++ b/Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.cpp @@ -25,9 +25,12 @@ namespace AZ AZ::BehaviorContext* behaviorContext = azrtti_cast(context); if (behaviorContext) { + behaviorContext->Class(); + behaviorContext->Class() ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) ->Attribute(AZ::Script::Attributes::Module, "scene.graph") + ->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All) ->Method("CastWithTypeName", &GraphObjectProxy::CastWithTypeName) ->Method("Invoke", &GraphObjectProxy::Invoke) ; From b5cf0f59fc0ab9bf411e26b229f1dddd90356655 Mon Sep 17 00:00:00 2001 From: jjjoness <82226755+jjjoness@users.noreply.github.com> Date: Mon, 3 May 2021 16:57:58 +0100 Subject: [PATCH 08/12] Moved the pragma below the copyright message. --- Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.h b/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.h index f0e74145ee..fbe45a3f75 100644 --- a/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.h +++ b/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.h @@ -1,5 +1,3 @@ -#pragma once - /* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. @@ -12,6 +10,8 @@ * */ +#pragma once + #if !defined(Q_MOC_RUN) #include #endif From 3c7ca7269310959112c27da90a0af6ff698e15e7 Mon Sep 17 00:00:00 2001 From: Benjamin Jillich <43751992+amzn-jillich@users.noreply.github.com> Date: Mon, 3 May 2021 18:45:35 +0200 Subject: [PATCH 09/12] [LYN-3269] EMotionFX Editor save changed files prompts users to save files to the cache (#469) * The asset source filename is now displayed instead of the product filename. * Fixed a stylesheet issue with screen scaling on 4K monitors for the saved changed files window. * Cleaned up surrounding code. --- .../Source/SaveChangedFilesManager.cpp | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/SaveChangedFilesManager.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/SaveChangedFilesManager.cpp index 4824821a61..28a4fb9c92 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/SaveChangedFilesManager.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/SaveChangedFilesManager.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -398,33 +399,49 @@ namespace EMStudio const size_t numDirtyFiles = dirtyFileNames.size(); mTableWidget->setRowCount(static_cast(numDirtyFiles)); - AZStd::string extension, typeString, filenameText, path, filenameOnly; for (size_t i = 0; i < numDirtyFiles; ++i) { SaveDirtyFilesCallback::ObjectPointer object = mObjects[i]; + QString labelText; if (dirtyFileNames[i].empty()) { - filenameText = ""; + labelText = ""; } else { - AzFramework::StringFunc::Path::GetFullPath(dirtyFileNames[i].c_str(), path); - AzFramework::StringFunc::Path::GetFullFileName(dirtyFileNames[i].c_str(), filenameOnly); + const AZStd::string& productFilename = dirtyFileNames[i]; - filenameText = AZStd::string::format("%s%s", path.c_str(), filenameOnly.c_str()); + // Get the asset source name from the product filename. + bool sourceAssetFound = false; + AZStd::string sourceAssetFilename; + AzToolsFramework::AssetSystemRequestBus::BroadcastResult(sourceAssetFound, + &AzToolsFramework::AssetSystemRequestBus::Events::GetFullSourcePathFromRelativeProductPath, + productFilename, + sourceAssetFilename); + + const AZStd::string usedFilename = sourceAssetFound ? sourceAssetFilename : dirtyFileNames[i]; + + // Separate the path from the filename, so that we can display the filename in bold. + AZStd::string fullPath; + AzFramework::StringFunc::Path::GetFullPath(usedFilename.c_str(), fullPath); + AzFramework::StringFunc::RelativePath::Normalize(fullPath); // Add trailing slash in case it is missing + AZStd::string fullFilename; + AzFramework::StringFunc::Path::GetFullFileName(usedFilename.c_str(), fullFilename); + labelText = QString("%1%2").arg(fullPath.c_str(), fullFilename.c_str()); } // create the checkbox QCheckBox* checkbox = new QCheckBox(""); - checkbox->setStyleSheet("background: transparent; padding-left: 3px; max-width: 13px;"); + checkbox->setStyleSheet("background: transparent;"); checkbox->setChecked(true); // create the filename table item QLabel* filenameLabel = new QLabel(); - filenameLabel->setToolTip(filenameText.c_str()); - filenameLabel->setText(filenameText.c_str()); + filenameLabel->setToolTip(labelText); + filenameLabel->setText(labelText); + QString typeString; if (object.mMotion) { typeString = "Motion"; @@ -445,12 +462,8 @@ namespace EMStudio { typeString = "Workspace"; } - else - { - typeString = ""; - } - QTableWidgetItem* itemType = new QTableWidgetItem(typeString.c_str()); + QTableWidgetItem* itemType = new QTableWidgetItem(typeString); const int row = static_cast(i); itemType->setData(Qt::UserRole, row); From 893d4208c0ef1f529f71c64794c85e98841e759b Mon Sep 17 00:00:00 2001 From: Benjamin Jillich <43751992+amzn-jillich@users.noreply.github.com> Date: Mon, 3 May 2021 18:48:30 +0200 Subject: [PATCH 10/12] [LYN-3312] EMotionFX: Multi-threading dual quaternion software skinning / Moving the mouse while having many characters on screen makes the editor unusably slow (#506) Multi-threaded software skinning by splitting the mesh up into batches of 10,000 vertices, which results in 27 jobs being spawned and executed using a character asset from a customer having 262,676 vertices and a speed improvement of 12x on a 32-core machine. Single-threaded: 11,61 ms Multi-threaded (27 jobs): 0,96 ms * Created a SkinRange() function that can skin a part of the vertices. * The actual skinning is now using the job system to split up the skinning into several pieces and executes them in parallel. * Ported the bone info array to AzCore. * Fixed some issues with the mesh based bounds update in the actor instance. --- .../Code/EMotionFX/Source/ActorInstance.cpp | 8 +- .../EMotionFX/Source/DualQuatSkinDeformer.cpp | 306 +++++++----------- .../EMotionFX/Source/DualQuatSkinDeformer.h | 42 ++- .../Components/EditorActorComponent.cpp | 6 +- 4 files changed, 153 insertions(+), 209 deletions(-) diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/ActorInstance.cpp b/Gems/EMotionFX/Code/EMotionFX/Source/ActorInstance.cpp index cfacdf9f09..ec1b00bda4 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/ActorInstance.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Source/ActorInstance.cpp @@ -360,7 +360,7 @@ namespace EMotionFX ApplyMorphSetup(); UpdateSkinningMatrices(); UpdateAttachments(); - } + } // update the bounds when needed if (GetBoundsUpdateEnabled() && mBoundsUpdateType != BOUNDS_MESH_BASED) @@ -418,7 +418,8 @@ namespace EMotionFX } // Update the bounds when we are set to use mesh based bounds. - if (GetBoundsUpdateEnabled() == BOUNDS_MESH_BASED) + if (GetBoundsUpdateEnabled() && + GetBoundsUpdateType() == BOUNDS_MESH_BASED) { mBoundsUpdatePassedTime += timePassedInSeconds; if (mBoundsUpdatePassedTime >= mBoundsUpdateFrequency) @@ -449,7 +450,8 @@ namespace EMotionFX } // Update the bounds when we are set to use mesh based bounds. - if (GetBoundsUpdateEnabled() == BOUNDS_MESH_BASED) + if (GetBoundsUpdateEnabled() && + GetBoundsUpdateType() == BOUNDS_MESH_BASED) { mBoundsUpdatePassedTime += timePassedInSeconds; if (mBoundsUpdatePassedTime >= mBoundsUpdateFrequency) diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.cpp b/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.cpp index 73cbad195a..27cf34961f 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.cpp @@ -10,7 +10,8 @@ * */ -// include the required headers +#include +#include #include "EMotionFXConfig.h" #include "DualQuatSkinDeformer.h" #include "Mesh.h" @@ -23,138 +24,143 @@ #include #include - namespace EMotionFX { AZ_CLASS_ALLOCATOR_IMPL(DualQuatSkinDeformer, DeformerAllocator, 0) - // constructor DualQuatSkinDeformer::DualQuatSkinDeformer(Mesh* mesh) : MeshDeformer(mesh) { - mBones.SetMemoryCategory(EMFX_MEMCATEGORY_GEOMETRY_DEFORMERS); } - - // destructor DualQuatSkinDeformer::~DualQuatSkinDeformer() { - mBones.Clear(); } + AZ::Outcome DualQuatSkinDeformer::FindLocalBoneIndex(uint32 nodeIndex) const + { + const size_t numBones = m_bones.size(); + for (size_t i = 0; i < numBones; ++i) + { + if (m_bones[i].mNodeNr == nodeIndex) + { + return AZ::Success(i); + } + } + + return AZ::Failure(); + } - // creation DualQuatSkinDeformer* DualQuatSkinDeformer::Create(Mesh* mesh) { return aznew DualQuatSkinDeformer(mesh); } - - // get the type id uint32 DualQuatSkinDeformer::GetType() const { return TYPE_ID; } - - // get the subtype id uint32 DualQuatSkinDeformer::GetSubType() const { return SUBTYPE_ID; } - - // clone this class MeshDeformer* DualQuatSkinDeformer::Clone(Mesh* mesh) { // create the new cloned deformer DualQuatSkinDeformer* result = aznew DualQuatSkinDeformer(mesh); // copy the bone info (for precalc/optimization reasons) - result->mBones = mBones; + result->m_bones = m_bones; // return the result return result; } - // the main method where all calculations are done - void DualQuatSkinDeformer::Update(ActorInstance* actorInstance, Node* node, float timeDelta) + void DualQuatSkinDeformer::Update(ActorInstance* actorInstance, [[maybe_unused]] Node* node, [[maybe_unused]] float timeDelta) { - AZ_UNUSED(node); - MCORE_UNUSED(timeDelta); - const Actor* actor = actorInstance->GetActor(); const Pose* pose = actorInstance->GetTransformData()->GetCurrentPose(); + const uint32 numVertices = mMesh->GetNumVertices(); - AZ::Vector3 newPos, newNormal, newTangent, newBitangent; - AZ::Vector3 vtxPos, normal, tangent, bitangent; - AZ::Vector3* positions = static_cast(mMesh->FindVertexData(Mesh::ATTRIB_POSITIONS)); - AZ::Vector3* normals = static_cast(mMesh->FindVertexData(Mesh::ATTRIB_NORMALS)); - AZ::Vector4* tangents = static_cast(mMesh->FindVertexData(Mesh::ATTRIB_TANGENTS)); - AZ::Vector3* bitangents = static_cast(mMesh->FindVertexData(Mesh::ATTRIB_BITANGENTS)); - AZ::u32* orgVerts = static_cast(mMesh->FindVertexData(Mesh::ATTRIB_ORGVTXNUMBERS)); - - // precalc the skinning matrices - const uint32 numBones = mBones.GetLength(); - for (uint32 i = 0; i < numBones; i++) + // pre-calculate the skinning matrices + for (BoneInfo& boneInfo : m_bones) { - const uint32 nodeIndex = mBones[i].mNodeNr; - Transform skinTransform = actor->GetInverseBindPoseTransform(nodeIndex); - skinTransform.Multiply(pose->GetModelSpaceTransform(nodeIndex)); - mBones[i].mDualQuat.FromRotationTranslation(skinTransform.mRotation, skinTransform.mPosition); + const uint32 nodeIndex = boneInfo.mNodeNr; + const Transform skinTransform = actor->GetInverseBindPoseTransform(nodeIndex) * pose->GetModelSpaceTransform(nodeIndex); + boneInfo.mDualQuat.FromRotationTranslation(skinTransform.mRotation, skinTransform.mPosition); } - // find the skinning layer - SkinningInfoVertexAttributeLayer* layer = (SkinningInfoVertexAttributeLayer*)mMesh->FindSharedVertexAttributeLayer(SkinningInfoVertexAttributeLayer::TYPE_ID); - MCORE_ASSERT(layer); + AZ::JobCompletion jobCompletion; + + // Split up the skinned vertices into batches. + const AZ::u32 numBatches = aznumeric_caster(ceilf(aznumeric_cast(numVertices) / aznumeric_cast(s_numVerticesPerBatch))); + for (AZ::u32 batchIndex = 0; batchIndex < numBatches; ++batchIndex) + { + const AZ::u32 startVertex = batchIndex * s_numVerticesPerBatch; + const AZ::u32 endVertex = AZStd::min(startVertex + s_numVerticesPerBatch, numVertices); + + // Create a job for every batch and skin them simultaneously. + AZ::JobContext* jobContext = nullptr; + AZ::Job* job = AZ::CreateJobFunction([this, startVertex, endVertex]() + { + SkinRange(mMesh, startVertex, endVertex, m_bones); + }, /*isAutoDelete=*/true, jobContext); + + job->SetDependent(&jobCompletion); + job->Start(); + } + + jobCompletion.StartAndWaitForCompletion(); + } + + void DualQuatSkinDeformer::SkinRange(Mesh* mesh, AZ::u32 startVertex, AZ::u32 endVertex, const AZStd::vector& boneInfos) + { + SkinningInfoVertexAttributeLayer* layer = (SkinningInfoVertexAttributeLayer*)mesh->FindSharedVertexAttributeLayer(SkinningInfoVertexAttributeLayer::TYPE_ID); + AZ_Assert(layer, "Cannot find skinning layer."); + + AZ::Vector3 newTangent; + AZ::Vector3 vtxPos, normal, tangent, bitangent; + AZ::u32 orgVertex; + float weight; + + AZ::Vector3* positions = static_cast(mesh->FindVertexData(Mesh::ATTRIB_POSITIONS)); + AZ::Vector3* normals = static_cast(mesh->FindVertexData(Mesh::ATTRIB_NORMALS)); + AZ::Vector4* tangents = static_cast(mesh->FindVertexData(Mesh::ATTRIB_TANGENTS)); + AZ::Vector3* bitangents = static_cast(mesh->FindVertexData(Mesh::ATTRIB_BITANGENTS)); + AZ::u32* orgVerts = static_cast(mesh->FindVertexData(Mesh::ATTRIB_ORGVTXNUMBERS)); // if there are tangents and bitangents to skin if (tangents && bitangents) { - const uint32 numVertices = mMesh->GetNumVertices(); - uint32 v = 0; - uint32 orgVertex; - - SkinInfluence* influence; - BoneInfo* boneInfo; - float weight; - for (v = 0; v < numVertices; ++v) + for (AZ::u32 v = startVertex; v < endVertex; ++v) { - // get the original vertex number - orgVertex = *(orgVerts++); - - // reset the skinned position - newPos = AZ::Vector3::CreateZero(); - newNormal = AZ::Vector3::CreateZero(); - newTangent = AZ::Vector3::CreateZero(); - newBitangent = AZ::Vector3::CreateZero(); - - const float tangentW = tangents->GetW(); - vtxPos.Set (positions->GetX(), positions->GetY(), positions->GetZ()); - normal.Set (normals->GetX(), normals->GetY(), normals->GetZ()); - tangent.Set (tangents->GetX(), tangents->GetY(), tangents->GetZ()); - bitangent.Set(bitangents->GetX(), bitangents->GetY(), bitangents->GetZ()); + orgVertex = orgVerts[v]; + vtxPos = positions[v]; + normal = normals[v]; + const float tangentW = tangents[v].GetW(); + tangent.Set(tangents[v].GetX(), tangents[v].GetY(), tangents[v].GetZ()); + bitangent = bitangents[v]; // process the skin influences for this vertex const size_t numInfluences = layer->GetNumInfluences(orgVertex); if (numInfluences > 0) { // get the pivot quat, used for the dot product check - const MCore::DualQuaternion& pivotQuat = mBones[ layer->GetInfluence(orgVertex, 0)->GetBoneNr() ].mDualQuat; + const MCore::DualQuaternion& pivotQuat = boneInfos[ layer->GetInfluence(orgVertex, 0)->GetBoneNr() ].mDualQuat; // our skinning dual quaternion MCore::DualQuaternion skinQuat(AZ::Quaternion(0, 0, 0, 0), AZ::Quaternion(0, 0, 0, 0)); for (size_t i = 0; i < numInfluences; ++i) { - // get the influence - influence = layer->GetInfluence(orgVertex, i); - boneInfo = &mBones[ influence->GetBoneNr() ]; - weight = influence->GetWeight(); + SkinInfluence* influence = layer->GetInfluence(orgVertex, i); + weight = influence->GetWeight(); // check if we need to invert the dual quat - MCore::DualQuaternion& influenceQuat = mBones[ influence->GetBoneNr() ].mDualQuat; + MCore::DualQuaternion influenceQuat = boneInfos[ influence->GetBoneNr() ].mDualQuat; if (influenceQuat.mReal.Dot(pivotQuat.mReal) < 0.0f) { influenceQuat *= -1.0f; @@ -168,74 +174,50 @@ namespace EMotionFX skinQuat.Normalize(); // perform skinning - newPos = skinQuat.TransformPoint(vtxPos); - newNormal = skinQuat.TransformVector(normal); - newTangent = skinQuat.TransformVector(tangent); - newBitangent = skinQuat.TransformVector(bitangent); + positions[v] = skinQuat.TransformPoint(vtxPos); + normals[v] = skinQuat.TransformVector(normal); + newTangent = skinQuat.TransformVector(tangent); + tangents[v].Set(newTangent.GetX(), newTangent.GetY(), newTangent.GetZ(), tangentW); + bitangents[v] = skinQuat.TransformVector(bitangent); } else { - // perform the skinning - newPos = vtxPos; - newNormal = normal; - newTangent = tangent; - newBitangent = bitangent; + // no skinning influences, just copy the values + positions[v] = vtxPos; + normals[v] = normal; + newTangent = tangent; + tangents[v].Set(newTangent.GetX(), newTangent.GetY(), newTangent.GetZ(), tangentW); + bitangents[v] = bitangent; } - - // output the skinned values - positions->Set (newPos.GetX(), newPos.GetY(), newPos.GetZ()); - positions++; - normals->Set (newNormal.GetX(), newNormal.GetY(), newNormal.GetZ()); - normals++; - tangents->Set (newTangent.GetX(), newTangent.GetY(), newTangent.GetZ(), tangentW); - tangents++; - bitangents->Set (newBitangent.GetX(), newBitangent.GetY(), newBitangent.GetZ()); - bitangents++; } } else if (tangents && !bitangents) // tangents but no bitangents { - const uint32 numVertices = mMesh->GetNumVertices(); - uint32 v = 0; - uint32 orgVertex; - - SkinInfluence* influence; - BoneInfo* boneInfo; - float weight; - for (v = 0; v < numVertices; ++v) + for (AZ::u32 v = startVertex; v < endVertex; ++v) { - // get the original vertex number - orgVertex = *(orgVerts++); - - // reset the skinned position - newPos = AZ::Vector3::CreateZero(); - newNormal = AZ::Vector3::CreateZero(); - newTangent = AZ::Vector3::CreateZero(); - - const float tangentW = tangents->GetW(); - vtxPos.Set (positions->GetX(), positions->GetY(), positions->GetZ()); - normal.Set (normals->GetX(), normals->GetY(), normals->GetZ()); - tangent.Set (tangents->GetX(), tangents->GetY(), tangents->GetZ()); + orgVertex = orgVerts[v]; + vtxPos = positions[v]; + normal = normals[v]; + const float tangentW = tangents[v].GetW(); + tangent.Set(tangents[v].GetX(), tangents[v].GetY(), tangents[v].GetZ()); // process the skin influences for this vertex const size_t numInfluences = layer->GetNumInfluences(orgVertex); if (numInfluences > 0) { // get the pivot quat, used for the dot product check - const MCore::DualQuaternion& pivotQuat = mBones[ layer->GetInfluence(orgVertex, 0)->GetBoneNr() ].mDualQuat; + const MCore::DualQuaternion& pivotQuat = boneInfos[ layer->GetInfluence(orgVertex, 0)->GetBoneNr() ].mDualQuat; // our skinning dual quaternion MCore::DualQuaternion skinQuat(AZ::Quaternion(0, 0, 0, 0), AZ::Quaternion(0, 0, 0, 0)); for (size_t i = 0; i < numInfluences; ++i) { - // get the influence - influence = layer->GetInfluence(orgVertex, i); - boneInfo = &mBones[ influence->GetBoneNr() ]; - weight = influence->GetWeight(); + SkinInfluence* influence = layer->GetInfluence(orgVertex, i); + weight = influence->GetWeight(); // check if we need to invert the dual quat - MCore::DualQuaternion& influenceQuat = mBones[ influence->GetBoneNr() ].mDualQuat; + MCore::DualQuaternion influenceQuat = boneInfos[ influence->GetBoneNr() ].mDualQuat; if (influenceQuat.mReal.Dot(pivotQuat.mReal) < 0.0f) { influenceQuat *= -1.0f; @@ -249,68 +231,46 @@ namespace EMotionFX skinQuat.Normalize(); // perform skinning - newPos = skinQuat.TransformPoint(vtxPos); - newNormal = skinQuat.TransformVector(normal); - newTangent = skinQuat.TransformVector(tangent); + positions[v] = skinQuat.TransformPoint(vtxPos); + normals[v] = skinQuat.TransformVector(normal); + newTangent = skinQuat.TransformVector(tangent); + tangents[v].Set(newTangent.GetX(), newTangent.GetY(), newTangent.GetZ(), tangentW); } else { - // perform the skinning - newPos = vtxPos; - newNormal = normal; - newTangent = tangent; + // no skinning influences, just copy the values + positions[v] = vtxPos; + normals[v] = normal; + newTangent = tangent; + tangents[v].Set(newTangent.GetX(), newTangent.GetY(), newTangent.GetZ(), tangentW); } - - // output the skinned values - positions->Set (newPos.GetX(), newPos.GetY(), newPos.GetZ()); - positions++; - normals->Set (newNormal.GetX(), newNormal.GetY(), newNormal.GetZ()); - normals++; - tangents->Set (newTangent.GetX(), newTangent.GetY(), newTangent.GetZ(), tangentW); - tangents++; } } else // there are no tangents and bitangents to skin { - const uint32 numVertices = mMesh->GetNumVertices(); - uint32 v = 0; - uint32 orgVertex; - - SkinInfluence* influence; - BoneInfo* boneInfo; - float weight; - - for (v = 0; v < numVertices; ++v) + for (AZ::u32 v = startVertex; v < endVertex; ++v) { - // get the original vertex number - orgVertex = *(orgVerts++); - - // reset the skinned position - newPos = AZ::Vector3::CreateZero(); - newNormal = AZ::Vector3::CreateZero(); - - vtxPos.Set(positions->GetX(), positions->GetY(), positions->GetZ()); - normal.Set(normals->GetX(), normals->GetY(), normals->GetZ()); + orgVertex = orgVerts[v]; + vtxPos = positions[v]; + normal = normals[v]; // process the skin influences for this vertex const size_t numInfluences = layer->GetNumInfluences(orgVertex); if (numInfluences > 0) { // get the pivot quat, used for the dot product check - const MCore::DualQuaternion& pivotQuat = mBones[ layer->GetInfluence(orgVertex, 0)->GetBoneNr() ].mDualQuat; + const MCore::DualQuaternion& pivotQuat = boneInfos[ layer->GetInfluence(orgVertex, 0)->GetBoneNr() ].mDualQuat; // our skinning dual quaternion MCore::DualQuaternion skinQuat(AZ::Quaternion(0, 0, 0, 0), AZ::Quaternion(0, 0, 0, 0)); for (size_t i = 0; i < numInfluences; ++i) { - // get the influence - influence = layer->GetInfluence(orgVertex, i); - boneInfo = &mBones[ influence->GetBoneNr() ]; - weight = influence->GetWeight(); + SkinInfluence* influence = layer->GetInfluence(orgVertex, i); + weight = influence->GetWeight(); // check if we need to invert the dual quat - MCore::DualQuaternion& influenceQuat = mBones[ influence->GetBoneNr() ].mDualQuat; + MCore::DualQuaternion influenceQuat = boneInfos[ influence->GetBoneNr() ].mDualQuat; if (influenceQuat.mReal.Dot(pivotQuat.mReal) < 0.0f) { influenceQuat *= -1.0f; @@ -324,26 +284,19 @@ namespace EMotionFX skinQuat.Normalize(); // perform skinning - newPos = skinQuat.TransformPoint(vtxPos); - newNormal = skinQuat.TransformVector(normal); + positions[v] = skinQuat.TransformPoint(vtxPos); + normals[v] = skinQuat.TransformVector(normal); } else { - // perform the skinning - newPos = vtxPos; - newNormal = normal; + // no skinning influences, just copy the values + positions[v] = vtxPos; + normals[v] = normal; } - - // output the skinned values - positions->Set(newPos.GetX(), newPos.GetY(), newPos.GetZ()); - positions++; - normals->Set(newNormal.GetX(), newNormal.GetY(), newNormal.GetZ()); - normals++; } } } - // initialize the mesh deformer void DualQuatSkinDeformer::Reinitialize(Actor* actor, Node* node, uint32 lodLevel) { @@ -352,7 +305,7 @@ namespace EMotionFX MCORE_UNUSED(lodLevel); // clear the bone information array, but don't free the currently allocated/reserved memory - mBones.Clear(false); + m_bones.clear(); // if there is no mesh if (mMesh == nullptr) @@ -360,13 +313,9 @@ namespace EMotionFX return; } - // get the attribute number SkinningInfoVertexAttributeLayer* skinningLayer = (SkinningInfoVertexAttributeLayer*)mMesh->FindSharedVertexAttributeLayer(SkinningInfoVertexAttributeLayer::TYPE_ID); MCORE_ASSERT(skinningLayer); - // reserve space for the bone array - //mBones.Reserve( actor->GetNumNodes() ); - // find out what bones this mesh uses const uint32 numOrgVerts = mMesh->GetNumOrgVertices(); for (uint32 i = 0; i < numOrgVerts; i++) @@ -379,26 +328,21 @@ namespace EMotionFX { SkinInfluence* influence = skinningLayer->GetInfluence(i, a); - // get the bone index in the array - uint32 boneIndex = FindLocalBoneIndex(influence->GetNodeNr()); - - // if the bone is not found in our array - if (boneIndex == MCORE_INVALIDINDEX32) + AZ::Outcome boneIndexOutcome = FindLocalBoneIndex(influence->GetNodeNr()); + if (boneIndexOutcome.IsSuccess()) + { + influence->SetBoneNr(boneIndexOutcome.GetValue()); + } + else { // add the bone to the array of bones in this deformer - mBones.AddEmptyExact(); - BoneInfo& lastBone = mBones.GetLast(); + BoneInfo lastBone; lastBone.mNodeNr = influence->GetNodeNr(); lastBone.mDualQuat.Identity(); - boneIndex = mBones.GetLength() - 1; + m_bones.emplace_back(lastBone); + influence->SetBoneNr(static_cast(m_bones.size() - 1)); } - - // set the bone number in the influence - influence->SetBoneNr(static_cast(boneIndex)); } } - - // get rid of all items in the used bones array - // mBones.Shrink(); } } // namespace EMotionFX diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.h b/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.h index fc80256524..ec00f1186f 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.h +++ b/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.h @@ -12,13 +12,13 @@ #pragma once -// include the required headers +#include +#include #include "EMotionFXConfig.h" #include #include "Mesh.h" #include "MeshDeformer.h" - namespace EMotionFX { // forward declarations @@ -101,37 +101,47 @@ namespace EMotionFX * This is the number of different bones that the skinning information of the mesh where this deformer works on uses. * @result The number of bones. */ - MCORE_INLINE uint32 GetNumLocalBones() const { return mBones.GetLength(); } + MCORE_INLINE uint32 GetNumLocalBones() const { return static_cast(m_bones.size()); } /** * Get the node number of a given local bone. * @param index The local bone number, which must be in range of [0..GetNumLocalBones()-1]. * @result The node number, which is in range of [0..Actor::GetNumNodes()-1], depending on the actor where this deformer works on. */ - MCORE_INLINE uint32 GetLocalBone(uint32 index) const { return mBones[index].mNodeNr; } + MCORE_INLINE uint32 GetLocalBone(uint32 index) const { return m_bones[index].mNodeNr; } /** * Pre-allocate space for a given number of local bones. * This does not alter the value returned by GetNumLocalBones(). * @param numBones The number of bones to pre-allocate space for. */ - MCORE_INLINE void ReserveLocalBones(uint32 numBones) { mBones.Reserve(numBones); } - + MCORE_INLINE void ReserveLocalBones(uint32 numBones) { m_bones.reserve(numBones); } protected: /** - * Structure used for precalculating the skinning matrices. + * Structure used for pre-calculating the skinning matrices. */ struct EMFX_API BoneInfo { uint32 mNodeNr; /**< The node number. */ - MCore::DualQuaternion mDualQuat; /**< The dual quat of the precalculated matrix that contains the "globalMatrix * inverse(bindPoseMatrix)". */ + MCore::DualQuaternion mDualQuat; /**< The dual quat of the pre-calculated matrix that contains the "globalMatrix * inverse(bindPoseMatrix)". */ MCORE_INLINE BoneInfo() : mNodeNr(MCORE_INVALIDINDEX32) {} }; + AZStd::vector m_bones; /**< The array of bone information used for pre-calculation. */ - MCore::Array mBones; /**< The array of bone information used for precalculation. */ + /** + * Skin a part of the mesh. + * @param mesh The mesh to be skinned. + * @param startVertex The start vertex index to start skinning. + * @param endVertex The end vertex index for the range to be skinned. + * @param boneInfos The pre-calculated skinning matrices shared across the skinning process. + */ + static void SkinRange(Mesh* mesh, AZ::u32 startVertex, AZ::u32 endVertex, const AZStd::vector& boneInfos); + + //! Number of vertices per batch/job used for multi-threaded software skinning. + static constexpr AZ::u32 s_numVerticesPerBatch = 10000; /** * Default constructor. @@ -149,18 +159,6 @@ namespace EMotionFX * @param nodeIndex The node number to search for. * @result The index inside the mBones member array, which uses the given node. */ - MCORE_INLINE uint32 FindLocalBoneIndex(uint32 nodeIndex) const - { - const uint32 numBones = mBones.GetLength(); - for (uint32 i = 0; i < numBones; ++i) - { - if (mBones[i].mNodeNr == nodeIndex) - { - return i; - } - } - - return MCORE_INVALIDINDEX32; - } + AZ::Outcome FindLocalBoneIndex(uint32 nodeIndex) const; }; } // namespace EMotionFX diff --git a/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.cpp b/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.cpp index 3aa281c4c2..bcb1e3f300 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.cpp @@ -650,7 +650,6 @@ namespace EMotionFX } distance = std::numeric_limits::max(); - bool isHit = false; // Get the MCore::Ray used by Mesh::Intersects // Convert the input source position and direction to a line segment by using the frustum depth as line length. @@ -659,12 +658,13 @@ namespace EMotionFX const AZ::Vector3 dest = src + dir * frustumDepth; const MCore::Ray ray(src, dest); - // Update the mesh deformers so the intersection test will hit the actor if it is being - // animated by a motion component that is previewing the animation in the editor + // Update the mesh deformers (apply software skinning and morphing) so the intersection test will hit the actor + // if it is being animated by a motion component that is previewing the animation in the editor. m_actorInstance->UpdateMeshDeformers(0.0f, true); const TransformData* transformData = m_actorInstance->GetTransformData(); const Pose* currentPose = transformData->GetCurrentPose(); + bool isHit = false; // Iterate through the meshes in the actor, looking for the closest hit const AZ::u32 lodLevel = m_actorInstance->GetLODLevel(); From 2e4545d2890e1fa14600842ecdb1cd6ee2d67422 Mon Sep 17 00:00:00 2001 From: amzn-sj Date: Mon, 3 May 2021 10:01:20 -0700 Subject: [PATCH 11/12] Fix iOS Crash --- .../ImguiAtom/Code/Source/DebugConsole.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Gems/AtomLyIntegration/ImguiAtom/Code/Source/DebugConsole.cpp b/Gems/AtomLyIntegration/ImguiAtom/Code/Source/DebugConsole.cpp index 49ed813ed8..8ae7c30c6a 100644 --- a/Gems/AtomLyIntegration/ImguiAtom/Code/Source/DebugConsole.cpp +++ b/Gems/AtomLyIntegration/ImguiAtom/Code/Source/DebugConsole.cpp @@ -126,7 +126,12 @@ namespace AZ SetFilter(inputFilter); // Bind our custom log handler. - AZ::Interface::Get()->BindLogHandler(m_logHandler); + AZ::ILogger* loggerInstance = AZ::Interface::Get(); + AZ_Assert(loggerInstance, "Failed to get ILogger instance. Log handler not bound.") + if (loggerInstance) + { + loggerInstance->BindLogHandler(m_logHandler); + } // Connect to receive render tick events. auto atomViewportRequests = AZ::Interface::Get(); From 9292d2e63f4121c9986d7c01481257d67e3177cb Mon Sep 17 00:00:00 2001 From: guthadam Date: Mon, 3 May 2021 13:43:34 -0500 Subject: [PATCH 12/12] LYN-3133 Adding material editor asset path dependencies to Automated Testing project Some of these changes may not be necessary but comparing against the Atom Test project https://jira.agscollab.com/browse/LYN-3133 --- AutomatedTesting/Registry/assets_scan_folders.setreg | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/AutomatedTesting/Registry/assets_scan_folders.setreg b/AutomatedTesting/Registry/assets_scan_folders.setreg index 5394d381a3..91061f3337 100644 --- a/AutomatedTesting/Registry/assets_scan_folders.setreg +++ b/AutomatedTesting/Registry/assets_scan_folders.setreg @@ -38,6 +38,13 @@ "Gems/PrimitiveAssets" ] }, + "MaterialEditor": + { + "SourcePaths": + [ + "Gems/Atom/Tools/MaterialEditor" + ] + }, "UiBasics": { "SourcePaths":