فهرست منبع

added Asset Catalog overrides to properly handle when azmaterials are built by the AP to avoid issues when building the meshes.

Signed-off-by: Jason Dela Cruz <[email protected]>
Jason Dela Cruz 2 سال پیش
والد
کامیت
39b167c67a

+ 50 - 1
Gems/O3DE/GeomNodes/Code/Source/Editor/Components/EditorGeomNodesComponent.cpp

@@ -482,6 +482,7 @@ namespace GeomNodes
     {
         AzToolsFramework::Components::EditorComponentBase::Activate();
         EditorGeomNodesComponentRequestBus::Handler::BusConnect(GetEntityId());
+        AzFramework::AssetCatalogEventBus::Handler::BusConnect();
 		AZ::TickBus::Handler::BusConnect();
     }
 
@@ -490,6 +491,7 @@ namespace GeomNodes
         // BUG: this gets called when a component is added so deal with it properly as it destroys any current instance we have.
         Clear();
         AZ::TickBus::Handler::BusDisconnect();
+        AzFramework::AssetCatalogEventBus::Handler::BusDisconnect();
         AzToolsFramework::Components::EditorComponentBase::Deactivate();
 
         if (m_instance)
@@ -513,6 +515,37 @@ namespace GeomNodes
         return m_modelData.GetMeshData(entityId);
     }
 
+    void EditorGeomNodesComponent::OnCatalogAssetAdded(const AZ::Data::AssetId& assetId)
+    {
+		AZ::Data::AssetInfo assetInfo;
+		EBUS_EVENT_RESULT(assetInfo, AZ::Data::AssetCatalogRequestBus, GetAssetInfoById, assetId);
+
+		// note that this will get called twice, once with the real assetId and once with legacy assetId.
+		// we only want to add the real asset to the list, in which the assetId passed in is equal to the final assetId returned
+		// otherwise, you look up assetId (and its a legacy assetId) and the actual asset will be different.
+        if ((assetInfo.m_assetId.IsValid()) && (assetInfo.m_assetId == assetId))
+        {
+			for (auto entityId : m_entityIdList)
+            {
+				AZStd::string materialName;
+				AzFramework::StringFunc::Path::GetFileName(assetInfo.m_relativePath.c_str(), materialName);
+
+                auto meshData = m_modelData.GetMeshData((AZ::u64)entityId);
+                if (meshData.GetMaterial() == materialName)
+                {
+                    AZ_Printf("GeomNodes", "added %s", materialName.c_str());
+					EditorGeomNodesMeshComponentEventBus::Event(entityId, &EditorGeomNodesMeshComponentEvents::OnMeshDataAssigned, meshData);
+                    break;
+                }
+            }
+        }
+    }
+
+    void EditorGeomNodesComponent::OnCatalogAssetChanged(const AZ::Data::AssetId& assetId)
+    {
+        OnCatalogAssetAdded(assetId);
+    }
+
     void EditorGeomNodesComponent::Clear()
     {
         m_enumValues.clear();
@@ -592,7 +625,23 @@ namespace GeomNodes
 		for (auto entityId : m_entityIdList)
 		{
 			m_modelData.AssignMeshData((AZ::u64)entityId);
-			EditorGeomNodesMeshComponentEventBus::Event(entityId, &EditorGeomNodesMeshComponentEvents::OnMeshDataAssigned, m_modelData.GetMeshData((AZ::u64)entityId));
+            auto meshData = m_modelData.GetMeshData((AZ::u64)entityId);
+
+            auto materialPath = meshData.GetMaterialPath();
+            AZ_Printf("GeomNodes", "assigned mesh data %s", materialPath.c_str());
+            
+            if (AZ::IO::FileIOBase::GetInstance()->Exists(materialPath.c_str()))
+            {
+				AZ::Data::AssetId materialAssetId;
+				EBUS_EVENT_RESULT(materialAssetId, AZ::Data::AssetCatalogRequestBus, GetAssetIdByPath, materialPath.c_str(), AZ::Data::s_invalidAssetType, false);
+
+				// If found, notify mesh that the mesh data is assigned and material is ready.
+				if (materialAssetId.IsValid())
+				{
+					AZ_Printf("GeomNodes", "    OnMeshDataAssigned called %s", meshData.GetMaterialPath().c_str());
+					EditorGeomNodesMeshComponentEventBus::Event(entityId, &EditorGeomNodesMeshComponentEvents::OnMeshDataAssigned, meshData);
+				}
+            }
 		}
 
         

+ 7 - 0
Gems/O3DE/GeomNodes/Code/Source/Editor/Components/EditorGeomNodesComponent.h

@@ -9,6 +9,7 @@
 #include <Editor/EBus/EditorGeomNodesComponentBus.h>
 #include <AzCore/Component/TickBus.h>
 #include <AzToolsFramework/Entity/EntityTypes.h>
+#include <AzFramework/Asset/AssetCatalogBus.h>
 
 namespace GeomNodes
 {
@@ -17,6 +18,7 @@ namespace GeomNodes
         , private Ipc::IpcHandlerNotificationBus::Handler
         , private AZ::TickBus::Handler
         , private EditorGeomNodesComponentRequestBus::Handler
+        , private AzFramework::AssetCatalogEventBus::Handler
     {
     public:
         AZ_EDITOR_COMPONENT(EditorGeomNodesComponent, "{E59507EF-9EBB-4F6C-8D89-92DCA57722E5}", EditorComponentBase);
@@ -40,6 +42,11 @@ namespace GeomNodes
 
         // EditorGeomNodesComponentRequestBus overrides ...
         GNMeshData GetMeshData(AZ::u64 entityId) override;
+    
+    private:
+		// AssetCatalogEventBus::Handler ...
+        void OnCatalogAssetAdded(const AZ::Data::AssetId& assetId) override;
+        void OnCatalogAssetChanged(const AZ::Data::AssetId& assetId) override;
 
     protected:
         //got this from ScriptEditorComponent

+ 5 - 2
Gems/O3DE/GeomNodes/Code/Source/Editor/Components/EditorGeomNodesMeshComponent.cpp

@@ -71,7 +71,6 @@ namespace GeomNodes
 	{
 		AzToolsFramework::Components::EditorComponentBase::Activate();
 		AZ::TransformNotificationBus::Handler::BusConnect(m_entityId);
-		AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusConnect(m_entityId);
 		EditorGeomNodesMeshComponentEventBus::Handler::BusConnect(m_entityId);
 
 		AZ::TransformBus::EventResult(m_parentId, m_entityId, &AZ::TransformBus::Events::GetParentId);
@@ -83,8 +82,9 @@ namespace GeomNodes
 
 	void EditorGeomNodesMeshComponent::Deactivate()
 	{
-		EditorGeomNodesMeshComponentEventBus::Handler::BusDisconnect();
 		AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusDisconnect();
+		AzFramework::BoundsRequestBus::Handler::BusDisconnect();
+		EditorGeomNodesMeshComponentEventBus::Handler::BusDisconnect();
 		AZ::TransformNotificationBus::Handler::BusDisconnect();
 		AzToolsFramework::Components::EditorComponentBase::Deactivate();
 		m_renderMesh.reset();
@@ -186,8 +186,11 @@ namespace GeomNodes
 	void EditorGeomNodesMeshComponent::OnMeshDataAssigned(const GNMeshData& meshData)
 	{
 		m_meshData = meshData;
+		AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusDisconnect();
 		AzFramework::BoundsRequestBus::Handler::BusDisconnect();
 		RebuildRenderMesh();
 		AzFramework::BoundsRequestBus::Handler::BusConnect(m_entityId);
+		AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusConnect(m_entityId);
+
 	}
 } // namespace GeomNodes