浏览代码

Logic for making Edit Parameters Read Only when exporting.

Signed-off-by: Jason Dela Cruz <[email protected]>
Jason Dela Cruz 2 年之前
父节点
当前提交
7b3f14a0d3

+ 32 - 15
Gems/O3DE/GeomNodes/Code/Source/Editor/Components/EditorGeomNodesComponent.cpp

@@ -62,16 +62,19 @@ namespace GeomNodes
                         &EditorGeomNodesComponent::m_blenderFile,
                         "Blender File",
                         "Blender file with Geometry Nodes")
-                    ->Attribute(Attributes::FuncValidator, ConvertFunctorToVoid(&Validators::ValidBlenderOrEmpty))
-                    ->Attribute(Attributes::SelectFunction, blendFunctor)
-                    ->Attribute(Attributes::ValidationChange, &EditorGeomNodesComponent::OnPathChange)
+                        ->Attribute(Attributes::FuncValidator, ConvertFunctorToVoid(&Validators::ValidBlenderOrEmpty))
+                        ->Attribute(Attributes::SelectFunction, blendFunctor)
+                        ->Attribute(Attributes::ValidationChange, &EditorGeomNodesComponent::OnPathChange)
+                        ->Attribute(AZ::Edit::Attributes::ReadOnly, &EditorGeomNodesComponent::ExportInProgress)
 					->DataElement(nullptr, &EditorGeomNodesComponent::m_paramContext, "Geom Nodes Parameters", "Parameter template")
                     ->SetDynamicEditDataProvider(&EditorGeomNodesComponent::GetParamsEditData)
                         ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
 					->UIElement(AZ::Edit::UIHandlers::Button, "", "Export to static mesh")
 					->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorGeomNodesComponent::ExportToStaticMesh)
-					->Attribute(AZ::Edit::Attributes::ButtonText, "Export")
+					->Attribute(AZ::Edit::Attributes::ButtonText, &EditorGeomNodesComponent::ExportButtonText)
                     ->Attribute(AZ::Edit::Attributes::Visibility, &EditorGeomNodesComponent::IsBlenderFileLoaded)
+                    ->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ::Edit::PropertyRefreshLevels::EntireTree)
+                    ->Attribute(AZ::Edit::Attributes::ReadOnly, &EditorGeomNodesComponent::ExportInProgress)
                     ;
 
                 ec->Class<GNParamContext>("Geom Nodes Parameter Context", "Adding exposed Geometry Nodes parameters to the entity!")
@@ -95,28 +98,32 @@ namespace GeomNodes
                 ec->Class<GNParamBoolean>("Geom Nodes Property (bool)", "A Geom Nodes boolean property")
                     ->ClassElement(AZ::Edit::ClassElements::EditorData, "GNPropertyGroup's class attributes.")
                         ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
-                    ->DataElement(nullptr, &GNParamBoolean::m_value, "m_value", "A boolean")
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &GNParamBoolean::m_value, "m_value", "A boolean")
+                    ->Attribute(AZ::Edit::Attributes::ReadOnly, &GNProperty::IsReadOnly)
                     ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorGeomNodesComponent::OnParamChange)
                     ->Attribute(AZ::Edit::Attributes::NameLabelOverride, &GNParamBoolean::m_name);
 
                 ec->Class<GNParamInt>("Geom Nodes Property (int)", "A Geom Nodes int property")
                     ->ClassElement(AZ::Edit::ClassElements::EditorData, "GNPropertyGroup's class attributes.")
                         ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
-                    ->DataElement(nullptr, &GNParamInt::m_value, "m_value", "An int")
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &GNParamInt::m_value, "m_value", "An int")
+                    ->Attribute(AZ::Edit::Attributes::ReadOnly, &GNProperty::IsReadOnly)
                     ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorGeomNodesComponent::OnParamChange)
                     ->Attribute(AZ::Edit::Attributes::NameLabelOverride, &GNParamInt::m_name);
 
                 ec->Class<GNParamValue>("Geom Nodes Property (double)", "A Geom Nodes double property")
                     ->ClassElement(AZ::Edit::ClassElements::EditorData, "GNPropertyGroup's class attributes.")
                         ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
-                    ->DataElement(nullptr, &GNParamValue::m_value, "m_value", "A double/value")
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &GNParamValue::m_value, "m_value", "A double/value")
+                    ->Attribute(AZ::Edit::Attributes::ReadOnly, &GNProperty::IsReadOnly)
                         ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorGeomNodesComponent::OnParamChange)
                         ->Attribute(AZ::Edit::Attributes::NameLabelOverride, &GNParamValue::m_name);
 
                 ec->Class<GNParamString>("Geom Nodes Property (string)", "A Geom Nodes string property")
                     ->ClassElement(AZ::Edit::ClassElements::EditorData, "GNPropertyGroup's class attributes.")
                         ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
-                    ->DataElement(nullptr, &GNParamString::m_value, "m_value", "A string")
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &GNParamString::m_value, "m_value", "A string")
+                    ->Attribute(AZ::Edit::Attributes::ReadOnly, &GNProperty::IsReadOnly)
                         ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorGeomNodesComponent::OnParamChange)
                         ->Attribute(AZ::Edit::Attributes::NameLabelOverride, &GNParamString::m_name);
             }
@@ -275,7 +282,7 @@ namespace GeomNodes
                 }
                 else {
                     // TODO: error message
-                    m_exportRequested = false;
+                    m_exportInProgress = false;
                 }
             }
         }
@@ -287,7 +294,7 @@ namespace GeomNodes
 
     void EditorGeomNodesComponent::ExportToStaticMesh()
     {
-        if (!m_exportRequested)
+        if (!m_exportInProgress)
         {
             auto msg = AZStd::string::format(
 				R"JSON(
@@ -303,7 +310,7 @@ namespace GeomNodes
                 Field::FBXPath,
                 GenerateFBXPath().c_str());
 			m_instance->SendIPCMsg(msg);
-            m_exportRequested = true;
+            m_exportInProgress = true;
         }
     }
 
@@ -312,6 +319,16 @@ namespace GeomNodes
         return m_initialized;
     }
 
+    bool EditorGeomNodesComponent::ExportInProgress()
+    {
+        return m_exportInProgress;
+    }
+
+    AZStd::string EditorGeomNodesComponent::ExportButtonText()
+    {
+        return m_exportInProgress ? "Exporting" : "Export";
+    }
+
     void EditorGeomNodesComponent::LoadObjects(const rapidjson::Value& objectNameArray, const rapidjson::Value& objectArray)
     {
         
@@ -376,7 +393,7 @@ namespace GeomNodes
         ei.m_editData.m_elementId = AZ::Edit::UIHandlers::ComboBox;
         ei.m_sortOrder = FLT_MAX;
 
-        auto gnParam = aznew GNParamString(Field::Objects, "");
+        auto gnParam = aznew GNParamString(Field::Objects, "", &m_exportInProgress);
         gnParam->m_value = m_currentObject;
         
         ei.m_editData.m_attributes.push_back(
@@ -416,7 +433,7 @@ namespace GeomNodes
             //set this up so the context can do it's own parsing of the current GN param JSON object.
             GNParamDataContext gndc;
             gndc.SetParamObject(itr);
-
+            gndc.SetReadOnlyPointer(&m_exportInProgress);
             auto propertyName = gndc.GetParamName();
             auto paramType = gndc.GetParamType();
                 
@@ -584,7 +601,7 @@ namespace GeomNodes
 			AZStd::string assetName;
 			AzFramework::StringFunc::Path::GetFileName(assetInfo.m_relativePath.c_str(), assetName);
 
-            if (m_exportRequested && (assetName == GenerateModelAssetName()))
+            if (m_exportInProgress && (assetName == GenerateModelAssetName()))
             {
                 auto transformComponent = GetEntity()->FindComponent<AzToolsFramework::Components::TransformComponent>();
 				AZ::EntityId parentId = transformComponent->GetParentId();
@@ -610,7 +627,7 @@ namespace GeomNodes
                     //TODO: delete this entity
 				}
 
-                m_exportRequested = false;
+                m_exportInProgress = false;
             }
             else
             {

+ 3 - 1
Gems/O3DE/GeomNodes/Code/Source/Editor/Components/EditorGeomNodesComponent.h

@@ -77,6 +77,8 @@ namespace GeomNodes
 
         void ExportToStaticMesh();
         bool IsBlenderFileLoaded();
+        bool ExportInProgress();
+        AZStd::string ExportButtonText();
 
         void LoadObjects(const rapidjson::Value& objectNameArray, const rapidjson::Value& objectArray);
         void LoadObjectNames(const rapidjson::Value& objectNames);
@@ -121,6 +123,6 @@ namespace GeomNodes
         AzToolsFramework::EntityIdList m_entityIdList;
 
         bool m_initialized = false;
-        bool m_exportRequested = false;
+        bool m_exportInProgress = false;
     };
 }

+ 11 - 0
Gems/O3DE/GeomNodes/Code/Source/Editor/Systems/GNParamContext.h

@@ -143,11 +143,22 @@ namespace GeomNodes
             m_curParamObj = nullptr;
         }
 
+        void SetReadOnlyPointer(bool* pReadOnly)
+        {
+            m_pReadOnly = pReadOnly;
+        }
+
+        bool* GetReadOnlyPointer()
+        {
+            return m_pReadOnly;
+        }
+
         const char* GetParamName();
         ParamType GetParamType();
 
     protected:
         const rapidjson::Value* m_curParamObj;
+        bool* m_pReadOnly;
     };
 
     template<class T>

+ 6 - 118
Gems/O3DE/GeomNodes/Code/Source/Editor/Systems/GNProperty.cpp

@@ -82,7 +82,7 @@ namespace GeomNodes
         GNProperty* retVal = nullptr;
         if (context.IsNil(valueIndex))
         {
-            retVal = aznew GNParamNil(name);
+            retVal = aznew GNParamNil(name, context.GetReadOnlyPointer());
         }
 
         return retVal;
@@ -103,27 +103,6 @@ namespace GeomNodes
         return AZStd::string();
     }
 
-    GNParamNil* GNParamNil::Clone(const char* name) const
-    {
-        return aznew GNParamNil(name ? name : m_name.c_str());
-    }
-
-    /*bool GNParamNil::Write(AZ::ScriptContext& context)
-    {
-        lua_pushnil(context.NativeContext());
-        return true;
-    }
-
-    bool GNParamNil::TryRead(GNParamDataContext& context, int valueIndex)
-    {
-        if (context.IsNil(valueIndex))
-        {
-            return true;
-        }
-
-        return false;
-    }*/
-
     void GNParamNil::CloneDataFrom(const GNProperty* gnProperty)
     {
         (void)gnProperty;
@@ -151,7 +130,7 @@ namespace GeomNodes
             bool value;
             if (context.ReadValue(value, Field::DefaultValue))
             {
-                retVal = aznew GNParamBoolean(name, value);
+                retVal = aznew GNParamBoolean(name, value, context.GetReadOnlyPointer());
                 retVal->ReadSetGNId(context);
             }
         }
@@ -165,27 +144,6 @@ namespace GeomNodes
         return context.IsBoolean(valueIndex);
     }
 
-    GNParamBoolean* GNParamBoolean::Clone(const char* name) const
-    {
-        return aznew GNParamBoolean(name ? name : m_name.c_str(), m_value);
-    }
-
-    /*bool GNParamBoolean::Write(AZ::ScriptContext& context)
-    {
-        AZ::ScriptValue<bool>::StackPush(context.NativeContext(), m_value);
-        return true;
-    }
-
-    bool GNParamBoolean::TryRead(GNParamDataContext& context, int valueIndex)
-    {
-        if (context.IsBoolean(valueIndex))
-        {
-            context.ReadValue(m_value);
-        }
-
-        return false;
-    }*/
-
     AZStd::string GNParamBoolean::ToJSONString() const
     {
         auto jsonString = AZStd::string::format(
@@ -244,7 +202,7 @@ namespace GeomNodes
             int value;
             if (context.ReadValue(value, Field::DefaultValue))
             {
-                auto paramInt = aznew GNParamInt(name, value);
+                auto paramInt = aznew GNParamInt(name, value, context.GetReadOnlyPointer());
 
                 int min, max;
                 if (context.ReadValue(min, Field::MinValue))
@@ -270,27 +228,7 @@ namespace GeomNodes
         return context.IsInt(valueIndex);
     }
 
-    GNParamInt* GNParamInt::Clone(const char* name) const
-    {
-        return aznew GNParamInt(name ? name : m_name.c_str(), m_value);
-    }
-
-    /*bool GNParamInt::Write(AZ::ScriptContext& context)
-    {
-        AZ::ScriptValue<double>::StackPush(context.NativeContext(), m_value);
-        return true;
-    }
-
-    bool GNParamInt::TryRead(GNParamDataContext& sdc, int index)
-    {
-        if (sdc.IsNumber(index))
-        {
-            sdc.ReadValue(m_value);
-            return true;
-        }
-
-        return false;
-    }*/
+ 
 
     AZ::TypeId GNParamInt::GetDataTypeUuid() const
     {
@@ -351,7 +289,7 @@ namespace GeomNodes
             double value;
             if (context.ReadValue(value, Field::DefaultValue))
             {
-                auto paramValue = aznew GNParamValue(name, value);
+                auto paramValue = aznew GNParamValue(name, value, context.GetReadOnlyPointer());
                 double min, max;
                 if (context.ReadValue(min, Field::MinValue))
                 {
@@ -376,28 +314,6 @@ namespace GeomNodes
         return context.IsValue(valueIndex);
     }
 
-    GNParamValue* GNParamValue::Clone(const char* name) const
-    {
-        return aznew GNParamValue(name ? name : m_name.c_str(), m_value);
-    }
-
-    /*bool GNParamValue::Write(AZ::ScriptContext& context)
-    {
-        AZ::ScriptValue<double>::StackPush(context.NativeContext(), m_value);
-        return true;
-    }
-
-    bool GNParamValue::TryRead(GNParamDataContext& sdc, int index)
-    {
-        if (sdc.IsNumber(index))
-        {
-            sdc.ReadValue(m_value);
-            return true;
-        }
-
-        return false;
-    }*/
-
     AZ::TypeId GNParamValue::GetDataTypeUuid() const
     {
         return AZ::SerializeTypeInfo<double>::GetUuid();
@@ -456,7 +372,7 @@ namespace GeomNodes
             const char* value = nullptr;
             if (context.ReadValue(value, Field::DefaultValue))
             {
-                retVal = aznew GNParamString(name, value);
+                retVal = aznew GNParamString(name, value, context.GetReadOnlyPointer());
                 retVal->ReadSetGNId(context);
             }
         }
@@ -469,34 +385,6 @@ namespace GeomNodes
         return context.IsString(valueIndex);
     }
 
-    GNParamString* GNParamString::Clone(const char* name) const
-    {
-        return aznew GNParamString(name ? name : m_name.c_str(), m_value.c_str());
-    }
-
-    /*bool GNParamString::Write(AZ::ScriptContext& context)
-    {
-        AZ::ScriptValue<const char*>::StackPush(context.NativeContext(), m_value.c_str());
-        return true;
-    }
-
-    bool GNParamString::TryRead(GNParamDataContext& context, int valueIndex)
-    {
-        bool readValue = false;
-
-        if (context.IsString(valueIndex))
-        {
-            const char* value = nullptr;
-            if (context.ReadValue(value))
-            {
-                readValue = true;
-                m_value = value;
-            }
-        }
-
-        return readValue;
-    }*/
-
     AZ::TypeId GNParamString::GetDataTypeUuid() const
     {
         return AZ::SerializeGenericTypeInfo<AZStd::string>::GetClassTypeId();

+ 21 - 26
Gems/O3DE/GeomNodes/Code/Source/Editor/Systems/GNProperty.h

@@ -40,9 +40,10 @@ namespace GeomNodes
         GNProperty()
         {
         }
-        GNProperty(const char* name)
+        GNProperty(const char* name, bool* pReadOnly)
             : m_id(AZ::Crc32(name))
             , m_name(name)
+            , m_pReadOnly(pReadOnly)
         {
         }
 
@@ -58,8 +59,7 @@ namespace GeomNodes
         }
 
         virtual void ReadSetGNId(GNParamDataContext& context);
-        virtual GNProperty* Clone(const char* name = nullptr) const = 0;
-
+        
         /*virtual bool Write(AZ::ScriptContext& context) = 0;
         virtual bool TryRead(GNParamDataContext& context, int valueIndex)
         {
@@ -79,13 +79,18 @@ namespace GeomNodes
             return allowUpdate;
         }
 
+        virtual bool IsReadOnly()
+        {
+            return *m_pReadOnly;
+        }
+
         AZ::u64         m_id;
         AZStd::string   m_gnId;                     // Geometry Node Param Id
         AZStd::string   m_name;                     // Geometry Node Param Name
         AZStd::string   m_type = "UNKNOWN";         // Geometry Node Param Type
-
-        bool m_isMaxSet = false;
-        bool m_isMinSet = false;
+        bool*           m_pReadOnly;
+        bool            m_isMaxSet = false;
+        bool            m_isMinSet = false;
     protected:
         virtual void CloneDataFrom(const GNProperty* gnProperty) = 0;
     };
@@ -102,8 +107,8 @@ namespace GeomNodes
         GNParamNil()
         {
         }
-        GNParamNil(const char* name)
-            : GNProperty(name)
+		GNParamNil(const char* name, bool* pReadOnly)
+			: GNProperty(name, pReadOnly)
         {
         }
 
@@ -111,8 +116,6 @@ namespace GeomNodes
         AZ::TypeId GetDataTypeUuid() const override;
         AZStd::string ToJSONString() const override;
 
-        GNParamNil* Clone(const char* name) const override;
-
         /*bool Write(AZ::ScriptContext& context) override;
         bool TryRead(GNParamDataContext& context, int valueIndex) override;*/
 
@@ -134,8 +137,8 @@ namespace GeomNodes
         {
             m_type = GetEnumString(ParamType::Bool);
         }
-        GNParamBoolean(const char* name, bool value)
-            : GNProperty(name)
+        GNParamBoolean(const char* name, bool value, bool* pReadOnly)
+            : GNProperty(name, pReadOnly)
             , m_value(value)
         {
             m_type = GetEnumString(ParamType::Bool);
@@ -152,8 +155,6 @@ namespace GeomNodes
 
         bool DoesTypeMatch(GNParamDataContext& context, int valueIndex) const override;
 
-        GNParamBoolean* Clone(const char* name) const override;
-
         /*bool Write(AZ::ScriptContext& context) override;
         bool TryRead(GNParamDataContext& context, int valueIndex) override;*/
 
@@ -177,8 +178,8 @@ namespace GeomNodes
         {
             m_type = GetEnumString(ParamType::Int);
         }
-        GNParamInt(const char* name, int value)
-            : GNProperty(name)
+		GNParamInt(const char* name, int value, bool* pReadOnly)
+			: GNProperty(name, pReadOnly)
             , m_value(value)
         {
             m_type = GetEnumString(ParamType::Int);
@@ -193,8 +194,6 @@ namespace GeomNodes
 
         bool DoesTypeMatch(GNParamDataContext& context, int valueIndex) const override;
 
-        GNParamInt* Clone(const char* name) const override;
-
         /*bool Write(AZ::ScriptContext& context) override;
         bool TryRead(GNParamDataContext& context, int valueIndex) override;*/
 
@@ -232,8 +231,8 @@ namespace GeomNodes
         {
             m_type = GetEnumString(ParamType::Value);
         }
-        GNParamValue(const char* name, double value)
-            : GNProperty(name)
+		GNParamValue(const char* name, double value, bool* pReadOnly)
+			: GNProperty(name, pReadOnly)
             , m_value(value)
         {
             m_type = GetEnumString(ParamType::Value);
@@ -248,8 +247,6 @@ namespace GeomNodes
 
         bool DoesTypeMatch(GNParamDataContext& context, int valueIndex) const override;
 
-        GNParamValue* Clone(const char* name) const override;
-
         /*bool Write(AZ::ScriptContext& context) override;
         bool TryRead(GNParamDataContext& context, int valueIndex) override;*/
 
@@ -286,8 +283,8 @@ namespace GeomNodes
         {
             m_type = GetEnumString(ParamType::String);
         }
-        GNParamString(const char* name, const char* value)
-            : GNProperty(name)
+		GNParamString(const char* name, const char* value, bool* pReadOnly)
+			: GNProperty(name, pReadOnly)
             , m_value(value)
         {
             m_type = GetEnumString(ParamType::String);
@@ -302,8 +299,6 @@ namespace GeomNodes
 
         bool DoesTypeMatch(GNParamDataContext& context, int valueIndex) const override;
 
-        GNParamString* Clone(const char* name = nullptr) const override;
-
         /*bool Write(AZ::ScriptContext& context) override;
         bool TryRead(GNParamDataContext& context, int valueIndex) override;*/
 

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

@@ -9,9 +9,9 @@ namespace GeomNodes
 {
     long IpcHandlerCB(AZ::u64 id, const char* data, AZ::u64 length)
     {
-        AZStd::string msg;
+        /*AZStd::string msg;
         msg.assign(data, length);
-        AZ_Printf("GeomNodesSystem", "id: %llu data: %s length: %llu", id, msg.c_str(), length);
+        AZ_Printf("GeomNodesSystem", "id: %llu data: %s length: %llu", id, msg.c_str(), length);*/
         Ipc::IpcHandlerNotificationBus::Event(
             AZ::EntityId(id), &Ipc::IpcHandlerNotificationBus::Events::OnMessageReceived, reinterpret_cast<const AZ::u8*>(data), length);
 

+ 1 - 1
Gems/O3DE/GeomNodes/External/Scripts/messages.py

@@ -97,7 +97,7 @@ def poll_for_messages():
                     from lib_loader import GNLibs
                     GNLibs.ClearSHM(map_id)
                 elif 'Export' in msg_dict:
-                    fbx_exporter.fbx_file_exporter(msg_dict['Object'], msg_dict['FBXPath'], True)
+                    fbx_exporter.fbx_file_exporter(msg_dict['Object'], msg_dict['FBXPath'], False)
                     #TODO: do some error checks. Inform the gem if there's an error.
                     MessageWriter().from_buffer(bytes(json.dumps({'Export' : True, 'Error' : "" }), "UTF-8"))
                 elif 'Alive' in msg_dict: