Răsfoiți Sursa

- changed Setting's blender path to use file dialog from an edit text.
- last blender path chosen by the user is now saved.
- float/double parameters can now be toggled(steps) properly

Signed-off-by: Jason Dela Cruz <[email protected]>

Jason Dela Cruz 2 ani în urmă
părinte
comite
b57d83730a

+ 18 - 17
Gems/O3DE/GeomNodes/Code/Source/Editor/Components/EditorGeomNodesComponent.cpp

@@ -135,8 +135,6 @@ namespace GeomNodes
     {
     {
         if (!path.empty())
         if (!path.empty())
         {
         {
-            //TODO: we can maybe do a blender path check here so we are sure we can use blender.exe properly.
-
             bool bClearParams = (m_instance && !m_instance->IsSamePath(path));
             bool bClearParams = (m_instance && !m_instance->IsSamePath(path));
             if (bClearParams)
             if (bClearParams)
             {
             {
@@ -163,16 +161,14 @@ namespace GeomNodes
                     AZ::IO::FixedMaxPath projectBuildPath;
                     AZ::IO::FixedMaxPath projectBuildPath;
                     if (!registry->Get(projectBuildPath.Native(), AZ::SettingsRegistryMergeUtils::ProjectBuildPath))
                     if (!registry->Get(projectBuildPath.Native(), AZ::SettingsRegistryMergeUtils::ProjectBuildPath))
                     {
                     {
-                        //TODO: error check
-                        //"No project build path setting was found in the user registry folder"
+                        AZ_Error("GeomNodes", false, "No project build path setting was found in the user registry folder");
                         return;
                         return;
                     }
                     }
 
 
                     bridgePath = projectBuildPath / "bin/profile/Bridge.dll"; //TODO: check if there is a way to get "bin/profile" in the registry or somewhere and not hard coded.
                     bridgePath = projectBuildPath / "bin/profile/Bridge.dll"; //TODO: check if there is a way to get "bin/profile" in the registry or somewhere and not hard coded.
                     if (!AZ::IO::SystemFile::Exists(bridgePath.c_str()))
                     if (!AZ::IO::SystemFile::Exists(bridgePath.c_str()))
                     {
                     {
-                        //TODO: bail out
-                        // we can't find the Bridge.dll
+                        AZ_Error("GeomNodes", false, "Can't find Bridge.dll");
                         return;
                         return;
                     }
                     }
 
 
@@ -275,11 +271,8 @@ namespace GeomNodes
             else if (jsonDocument.HasMember(Field::Export) && jsonDocument.HasMember(Field::Error))
             else if (jsonDocument.HasMember(Field::Export) && jsonDocument.HasMember(Field::Error))
             {
             {
                 AZStd::string errorMsg = jsonDocument[Field::Error].GetString();
                 AZStd::string errorMsg = jsonDocument[Field::Error].GetString();
-                if (errorMsg.empty())
+                if (!errorMsg.empty())
                 {
                 {
-                }
-                else {
-                    // TODO: error message
                     AZ_Warning("EditorGeomNodesComponent", false, errorMsg.c_str());
                     AZ_Warning("EditorGeomNodesComponent", false, errorMsg.c_str());
                     SetWorkInProgress(false);
                     SetWorkInProgress(false);
                 }
                 }
@@ -387,9 +380,12 @@ namespace GeomNodes
         // Create the currently selected Object parameters and attributes. Load only the first or saved object.
         // Create the currently selected Object parameters and attributes. Load only the first or saved object.
         CreateParam(m_currentObject, group);
         CreateParam(m_currentObject, group);
 
 
-        EBUS_EVENT(AzToolsFramework::ToolsApplicationEvents::Bus, InvalidatePropertyDisplay, AzToolsFramework::Refresh_EntireTree);
-        AzToolsFramework::ToolsApplicationRequests::Bus::Broadcast(
-            &AzToolsFramework::ToolsApplicationRequests::Bus::Events::AddDirtyEntity, GetEntityId());
+        AZ::SystemTickBus::QueueFunction(
+            [=]() {
+                EBUS_EVENT(AzToolsFramework::ToolsApplicationEvents::Bus, InvalidatePropertyDisplay, AzToolsFramework::Refresh_EntireTree);
+                AzToolsFramework::ToolsApplicationRequests::Bus::Broadcast(
+                    &AzToolsFramework::ToolsApplicationRequests::Bus::Events::AddDirtyEntity, GetEntityId());
+            });
     }
     }
 
 
     void EditorGeomNodesComponent::CreateObjectNames(const AZStd::string& objectName, const StringVector& enumValues, GNPropertyGroup& group)
     void EditorGeomNodesComponent::CreateObjectNames(const AZStd::string& objectName, const StringVector& enumValues, GNPropertyGroup& group)
@@ -514,6 +510,9 @@ namespace GeomNodes
                 double value = ((GNParamValue*)prop)->m_max;
                 double value = ((GNParamValue*)prop)->m_max;
                 ed.m_attributes.push_back(AZ::Edit::AttributePair(AZ::Crc32("max"), aznew AZ::Edit::AttributeData<double>(value)));
                 ed.m_attributes.push_back(AZ::Edit::AttributePair(AZ::Crc32("max"), aznew AZ::Edit::AttributeData<double>(value)));
             }
             }
+
+            ed.m_attributes.push_back(AZ::Edit::AttributePair(AZ::Edit::Attributes::Step, aznew AZ::Edit::AttributeData<double>(0.1f)));
+            
             break;
             break;
         }
         }
     }
     }
@@ -624,13 +623,15 @@ namespace GeomNodes
         // being shown or edited, so a refresh is at best superfluous, and at worst could cause a feedback loop of infinite refreshes.
         // being shown or edited, so a refresh is at best superfluous, and at worst could cause a feedback loop of infinite refreshes.
         if (GetEntity())
         if (GetEntity())
         {
         {
-            AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(
-                &AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_EntireTree);
+            AZ::SystemTickBus::QueueFunction(
+                [=]() {
+                    AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(
+                        &AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_EntireTree);
+                });
         }
         }
     }
     }
 
 
-    const AZ::Edit::ElementData* EditorGeomNodesComponent::GetDataElement(
-        [[maybe_unused]] const void* element, [[maybe_unused]] const AZ::Uuid& typeUuid) const
+    const AZ::Edit::ElementData* EditorGeomNodesComponent::GetDataElement(const void* element, const AZ::Uuid& typeUuid) const
     {
     {
         auto it = m_dataElements.find(element);
         auto it = m_dataElements.find(element);
         if (it != m_dataElements.end())
         if (it != m_dataElements.end())

+ 1 - 1
Gems/O3DE/GeomNodes/Code/Source/Editor/Configuration/GNConfiguration.cpp

@@ -23,7 +23,7 @@ namespace GeomNodes
                 editContext->Class<GNConfiguration>("GeomNodes Configuration", "Default GeomNodes configuration")
                 editContext->Class<GNConfiguration>("GeomNodes Configuration", "Default GeomNodes configuration")
                     ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
                     ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
                     ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
                     ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
-                    ->DataElement(AZ::Edit::UIHandlers::Default/*ExeSelectBrowseEdit*/, &GNConfiguration::m_blenderPath, "Blender Path", "Blender Path")
+                    ->DataElement(AZ::Edit::UIHandlers::ExeSelectBrowseEdit, &GNConfiguration::m_blenderPath, "Blender Path", "Blender Path")
                     ->Attribute(AZ::Edit::Attributes::ChangeNotify, &GNConfiguration::OnBlenderPathChanged)
                     ->Attribute(AZ::Edit::Attributes::ChangeNotify, &GNConfiguration::OnBlenderPathChanged)
                     ;
                     ;
             }
             }

+ 0 - 1
Gems/O3DE/GeomNodes/Code/Source/Editor/Configuration/GNSettingsRegistryManager.cpp

@@ -27,7 +27,6 @@ namespace GeomNodes
             AZ_TracePrintf("GeomNodesSystem", R"(GNConfiguration was read from settings registry at pointer path)"
             AZ_TracePrintf("GeomNodesSystem", R"(GNConfiguration was read from settings registry at pointer path)"
                 R"( "%s)" "\n",
                 R"( "%s)" "\n",
                 m_settingsRegistryPath.c_str());
                 m_settingsRegistryPath.c_str());
-            //TODO: validate if blender path is good.
             return systemConfig;
             return systemConfig;
         }
         }
         return AZStd::nullopt;
         return AZStd::nullopt;

+ 0 - 1
Gems/O3DE/GeomNodes/Code/Source/Editor/Rendering/GNRenderMesh.cpp

@@ -246,7 +246,6 @@ namespace GeomNodes
 
 
     void GNRenderMesh::UpdateTransform(const AZ::Transform& worldFromLocal, const AZ::Vector3& /*scale*/)
     void GNRenderMesh::UpdateTransform(const AZ::Transform& worldFromLocal, const AZ::Vector3& /*scale*/)
     {
     {
-        // TODO: multiply this to worldFromLocal transform
         if (m_meshHandle.IsValid())
         if (m_meshHandle.IsValid())
         {
         {
             m_meshFeatureProcessor->SetTransform(m_meshHandle, worldFromLocal);
             m_meshFeatureProcessor->SetTransform(m_meshHandle, worldFromLocal);

+ 3 - 10
Gems/O3DE/GeomNodes/Code/Source/Editor/Systems/GNInstance.cpp

@@ -18,8 +18,6 @@ namespace GeomNodes
 
 
             m_blenderProcessWatcher = nullptr;
             m_blenderProcessWatcher = nullptr;
         }
         }
-
-        AZ::TickBus::Handler::BusDisconnect();
     }
     }
 
 
     bool GNInstance::IsValid()
     bool GNInstance::IsValid()
@@ -34,15 +32,9 @@ namespace GeomNodes
         m_scriptPath = scriptPath;
         m_scriptPath = scriptPath;
         m_exePath = exePath;
         m_exePath = exePath;
 
 
-        AZ::TickBus::Handler::BusConnect();
         return RestartProcess();
         return RestartProcess();
     }
     }
 
 
-    void GNInstance::OnTick(float /*deltaTime*/, AZ::ScriptTimePoint /*time*/)
-    {
-        
-    }
-
     bool GNInstance::IsSamePath(const AZStd::string& path)
     bool GNInstance::IsSamePath(const AZStd::string& path)
     {
     {
         if (m_path.empty())
         if (m_path.empty())
@@ -63,9 +55,10 @@ namespace GeomNodes
     {
     {
         AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo;
         AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo;
         AZStd::string blenderPath = GetGNSystem()->GetBlenderPath();
         AZStd::string blenderPath = GetGNSystem()->GetBlenderPath();
-        if (blenderPath.empty()) // TODO: do some validation so we are sure the blender.exe path is good if not bail out.
+        if (blenderPath.empty())
         {
         {
-
+			AZ_Error("GNInstance", false, "Blender instance failed to launch! Blender path is not set or valid.");
+			return false;
         }
         }
 
 
         processLaunchInfo.m_commandlineParameters = AZStd::string::format(
         processLaunchInfo.m_commandlineParameters = AZStd::string::format(

+ 0 - 2
Gems/O3DE/GeomNodes/Code/Source/Editor/Systems/GNInstance.h

@@ -8,7 +8,6 @@
 namespace GeomNodes
 namespace GeomNodes
 {
 {
     class GNInstance
     class GNInstance
-        : public AZ::TickBus::Handler
     {
     {
     public:
     public:
         GNInstance() = default;
         GNInstance() = default;
@@ -17,7 +16,6 @@ namespace GeomNodes
         bool Init(const AZStd::string& filePath, const AZStd::string& scriptPath, const AZStd::string& exePath, AZ::EntityId entityId);
         bool Init(const AZStd::string& filePath, const AZStd::string& scriptPath, const AZStd::string& exePath, AZ::EntityId entityId);
         void Cleanup();
         void Cleanup();
         bool IsValid();
         bool IsValid();
-        void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
         bool IsSamePath(const AZStd::string& path);
         bool IsSamePath(const AZStd::string& path);
         void SendIPCMsg(const AZStd::string& content);
         void SendIPCMsg(const AZStd::string& content);
         bool RestartProcess();
         bool RestartProcess();

+ 23 - 0
Gems/O3DE/GeomNodes/Code/Source/Editor/Systems/GeomNodesSystem.cpp

@@ -77,6 +77,29 @@ namespace GeomNodes
 		return m_systemConfig;
 		return m_systemConfig;
 	}
 	}
 
 
+    void GeomNodesSystem::SetLastPath(const AZStd::string& lastPath)
+    {
+        m_systemConfig.m_lastFilePath = lastPath;
+        const GNSettingsRegistryManager& settingsRegManager = GetSettingsRegistryManager();
+		auto saveCallback = [](const GNConfiguration& config, GNSettingsRegistryManager::Result result)
+		{
+			AZ_Warning("GeomNodes", result == GNSettingsRegistryManager::Result::Success, "Unable to save the GeomNodes configuration. Any changes have not been applied.");
+			if (result == GNSettingsRegistryManager::Result::Success)
+			{
+				if (auto* gnSystem = GetGNSystem())
+				{
+					gnSystem->UpdateConfiguration(&config);
+				}
+			}
+		};
+		settingsRegManager.SaveSystemConfiguration(m_systemConfig, saveCallback);
+    }
+
+    AZStd::string GeomNodesSystem::GetLastPath()
+    {
+        return m_systemConfig.m_lastFilePath;
+    }
+
     void GeomNodesSystem::UpdateConfiguration(const GNConfiguration* newConfig)
     void GeomNodesSystem::UpdateConfiguration(const GNConfiguration* newConfig)
     {
     {
 		if(m_systemConfig != *newConfig)
 		if(m_systemConfig != *newConfig)

+ 3 - 0
Gems/O3DE/GeomNodes/Code/Source/Editor/Systems/GeomNodesSystem.h

@@ -40,6 +40,9 @@ namespace GeomNodes
 
 
         const GNConfiguration& GetSystemConfiguration() const;
         const GNConfiguration& GetSystemConfiguration() const;
 
 
+        void SetLastPath(const AZStd::string& lastPath);
+        AZStd::string GetLastPath();
+
     private:
     private:
         // Un/Registers and dis/connect handlers and buses
         // Un/Registers and dis/connect handlers and buses
         void RegisterHandlersAndBuses();
         void RegisterHandlersAndBuses();

+ 4 - 4
Gems/O3DE/GeomNodes/Code/Source/Editor/UI/SettingsWidget.cpp

@@ -49,9 +49,9 @@ namespace GeomNodes
             (void)node;
             (void)node;
         }
         }
 
 
-        void SettingsWidget::AfterPropertyModified(AzToolsFramework::InstanceDataNode* node)
+        void SettingsWidget::AfterPropertyModified(AzToolsFramework::InstanceDataNode* /*node*/)
         {
         {
-            (void)node;
+            emit onValueChanged(m_gnSystemConfiguration);
         }
         }
 
 
         void SettingsWidget::SetPropertyEditingActive(AzToolsFramework::InstanceDataNode* node)
         void SettingsWidget::SetPropertyEditingActive(AzToolsFramework::InstanceDataNode* node)
@@ -59,9 +59,9 @@ namespace GeomNodes
             (void)node;
             (void)node;
         }
         }
 
 
-        void SettingsWidget::SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* /*node*/)
+        void SettingsWidget::SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* node)
         {
         {
-            emit onValueChanged(m_gnSystemConfiguration);
+            (void)node;
         }
         }
 
 
         void SettingsWidget::SealUndoStack()
         void SettingsWidget::SealUndoStack()

+ 16 - 4
Gems/O3DE/GeomNodes/Code/Source/Editor/UI/Utils.cpp

@@ -3,9 +3,12 @@
 #include <AzCore/IO/SystemFile.h>
 #include <AzCore/IO/SystemFile.h>
 #include <AzCore/std/algorithm.h>
 #include <AzCore/std/algorithm.h>
 #include <AzCore/Utils/Utils.h>
 #include <AzCore/Utils/Utils.h>
+#include <AzCore/StringFunc/StringFunc.h>
 
 
 #include <QFileDialog>
 #include <QFileDialog>
 
 
+#include <Editor/Systems/GeomNodesSystem.h>
+
 namespace
 namespace
 {
 {
     template<typename StringType>
     template<typename StringType>
@@ -91,7 +94,14 @@ namespace GeomNodes
     QString SelectBlendFromFileDialog(const QString& currentFile)
     QString SelectBlendFromFileDialog(const QString& currentFile)
     {
     {
         // The selected file must be relative to this path
         // The selected file must be relative to this path
+        auto* gnSystem = GetGNSystem();
+        
         QString defaultPath = GetAbsoluteEngineRoot<QString>();
         QString defaultPath = GetAbsoluteEngineRoot<QString>();
+        if (gnSystem != nullptr && !gnSystem->GetLastPath().empty())
+        {
+            defaultPath = gnSystem->GetLastPath().c_str();
+        }
+        
         QString startPath;
         QString startPath;
 
 
         // Choose the starting path for file dialog
         // Choose the starting path for file dialog
@@ -115,12 +125,14 @@ namespace GeomNodes
             startPath, QObject::tr("Blender File (*.blend)"));
             startPath, QObject::tr("Blender File (*.blend)"));
         ToUnixPath(pickedPath);
         ToUnixPath(pickedPath);
 
 
-        // Remove the default relative path
-        if (pickedPath.contains(defaultPath))
+        if (!pickedPath.isEmpty())
         {
         {
-            pickedPath = pickedPath.mid(defaultPath.length());
+			AZStd::string lastFilePath;
+			AZ::StringFunc::Path::GetFolderPath(pickedPath.toUtf8().data(), lastFilePath);
+            gnSystem->SetLastPath(lastFilePath);
+            AZ_Printf("Utils", "pickedPath = %s", pickedPath.toUtf8().data());
         }
         }
-
+        
         return pickedPath;
         return pickedPath;
     }
     }
 }
 }