فهرست منبع

FlushIO after copying files in Robot Importer (#616)

* Add flushIO to robot importer
---------

Signed-off-by: Artur Kamieniecki <[email protected]>
Co-authored-by: Michał Pełka <[email protected]>
Artur Kamieniecki 1 سال پیش
والد
کامیت
03a0abc301

+ 27 - 12
Gems/ROS2/Code/Source/RobotImporter/Utils/SourceAssetsStorage.cpp

@@ -371,8 +371,19 @@ namespace ROS2::Utils
                     resolvedPath.c_str(),
                     targetPathAssetTmp.c_str(),
                     outcomeCopyTmp.GetResultCode());
+
                 if (outcomeCopyTmp)
                 {
+                    // An I/O flush is required here because we need to load the Scene file into memory from the temporary directory
+                    // to generate a proper manifest for it in the final directory before the Scene file itself is moved into the final
+                    // directory and processed. This ensures that when the Scene file is detected by the Asset Processor in the final
+                    // location, it will already have the desired export settings in the manifest to cause it to be exported correctly.
+                    // If we didn't flush the I/O here, the Scene file load can fail because the load contains a call to 
+                    // AssetSystemComponent::GetSourceInfoBySourcePath that will fail if the Asset Processor hasn't detected the
+                    // existence of the file yet. With the flush, everything works correctly.
+
+                    FlushIOOfAsset(targetPathAssetTmp);
+
                     const bool needsVisual = (assetReferenceType & ReferencedAssetType::VisualMesh) == ReferencedAssetType::VisualMesh;
                     const bool needsCollider = (assetReferenceType & ReferencedAssetType::ColliderMesh) == ReferencedAssetType::ColliderMesh;
                     const bool isMeshFile = (needsVisual || needsCollider);
@@ -420,18 +431,8 @@ namespace ROS2::Utils
                             targetPathAssetDst.c_str(),
                             outcomeMoveDst.GetResultCode());
 
-                        // call GetAssetStatus_FlushIO to ensure the asset processor is aware of the new file
-                        AzFramework::AssetSystem::AssetStatus copiedAssetStatus =
-                            AzFramework::AssetSystem::AssetStatus::AssetStatus_Unknown;
-                        AzFramework::AssetSystemRequestBus::BroadcastResult(
-                            copiedAssetStatus,
-                            &AzFramework::AssetSystem::AssetSystemRequests::GetAssetStatus_FlushIO,
-                            targetPathAssetDst.c_str());
-                        AZ_Warning(
-                            "CopyAssetForURDF",
-                            copiedAssetStatus != AzFramework::AssetSystem::AssetStatus::AssetStatus_Unknown,
-                            "Asset processor did not recognize the new file %s.",
-                            targetPathAssetDst.c_str());
+                        // call FlushIOOfAsset to ensure the asset processor is aware of the move operation.
+                        FlushIOOfAsset(targetPathAssetDst);
 
                         if (outcomeMoveDst)
                         {
@@ -661,4 +662,18 @@ namespace ROS2::Utils
         }
         return assetsFilepaths;
     }
+
+    AzFramework::AssetSystem::AssetStatus FlushIOOfAsset(const AZ::IO::Path& path)
+    {
+        AzFramework::AssetSystem::AssetStatus assetStatus = AzFramework::AssetSystem::AssetStatus::AssetStatus_Unknown;
+        AzFramework::AssetSystemRequestBus::BroadcastResult(
+            assetStatus, &AzFramework::AssetSystem::AssetSystemRequests::GetAssetStatus_FlushIO, path.c_str());
+        AZ_Warning(
+            "CopyAssetForURDF",
+            assetStatus != AzFramework::AssetSystem::AssetStatus::AssetStatus_Unknown,
+            "Asset processor did not recognize the new file %s.",
+            path.c_str());
+
+        return assetStatus;
+    }
 } // namespace ROS2::Utils

+ 6 - 0
Gems/ROS2/Code/Source/RobotImporter/Utils/SourceAssetsStorage.h

@@ -17,6 +17,7 @@
 #include <AzCore/Math/Crc.h>
 #include <AzCore/std/containers/unordered_map.h>
 #include <AzCore/std/containers/unordered_set.h>
+#include <AzFramework/Asset/AssetSystemBus.h>
 #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
 
 namespace ROS2
@@ -162,4 +163,9 @@ namespace ROS2::Utils
     //! @returns list of file paths referenced in the scene
     AZStd::unordered_set<AZ::IO::Path> GetMeshTextureAssets(const AZ::IO::Path& sourceMeshAssetPath);
 
+    //! Flushes the IO of an asset to disk
+    //! @param path - path to asset to flush
+    //! @returns status of the asset after flushing
+    AzFramework::AssetSystem::AssetStatus FlushIOOfAsset(const AZ::IO::Path& path);
+
 } // namespace ROS2::Utils