SourceAssetsStorage.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Asset/AssetCommon.h>
  10. #include <AzCore/Asset/AssetManager.h>
  11. #include <AzCore/Asset/AssetManagerBus.h>
  12. #include <AzCore/IO/FileIO.h>
  13. #include <AzCore/Math/Crc.h>
  14. #include <AzCore/std/containers/unordered_map.h>
  15. #include <AzCore/std/containers/unordered_set.h>
  16. #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
  17. namespace ROS2::Utils
  18. {
  19. //! Structure contains essential information about the source and product assets in O3DE.
  20. //! It is designed to provide necessary information for other classes in URDF converter, eg CollidersMaker or VisualsMaker.
  21. struct AvailableAsset
  22. {
  23. //! Relative path to source asset eg `Assets/foo_robot/meshes/bar_link.dae`.
  24. AZStd::string m_sourceAssetRelativePath;
  25. //! Relative path to source asset eg `/home/user/project/Assets/foo_robot/meshes/bar_link.dae`.
  26. AZStd::string m_sourceAssetGlobalPath;
  27. //! Relative path to source asset eg `foo_robot/meshes/bar_link.azmodel`.
  28. AZStd::string m_productAssetRelativePath;
  29. //! Product asset ID @see AZ::Data::AssetInfo.
  30. AZ::Data::AssetId m_assetId;
  31. };
  32. //! The structure contains a mapping between URDF's path to O3DE asset information.
  33. struct UrdfAsset
  34. {
  35. //! Unresolved URDF path to mesh, eg `package://meshes/bar_link.dae`.
  36. AZStd::string m_urdfPath;
  37. //! Resolved URDF path, points to the valid mesh in the filestystem, eg `/home/user/ros_ws/src/foo_robot/meshes/bar_link.dae'
  38. AZStd::string m_resolvedUrdfPath;
  39. //! Checksum of the file located pointed by `m_resolvedUrdfPath`.
  40. AZ::Crc32 m_urdfFileCRC;
  41. //! Found O3DE asset.
  42. AvailableAsset m_availableAssetInfo;
  43. };
  44. /// Type that hold result of mapping from URDF path to asset info
  45. using UrdfAssetMap = AZStd::unordered_map<AZStd::string, Utils::UrdfAsset>;
  46. //! Function computes CRC32 on first kilobyte of file.
  47. AZ::Crc32 GetFileCRC(const AZStd::string& filename);
  48. //! Compute CRC for every source mesh from the assets catalog.
  49. //! @returns map where key is crc of source file and value is AvailableAsset.
  50. AZStd::unordered_map<AZ::Crc32, AvailableAsset> GetInterestingSourceAssetsCRC();
  51. //! Discover an association between meshes in URDF and O3DE source and product assets.
  52. //! The @param meshesFilenames contains the list of unresolved URDF filenames that are to be found as assets.
  53. //! Steps:
  54. //! - Functions resolves URDF filenames with `ResolveURDFPath`.
  55. //! - Files pointed by resolved URDF patches have their checksum computed `GetFileCRC`.
  56. //! - Function scans all available O3DE assets by calling `GetInterestingSourceAssetsCRC`.
  57. //! - Suitable mapping to the O3DE asset is found by comparing the checksum of the file pointed by the URDF path and source asset.
  58. //! @param meshesFilenames - list of the unresolved path from the URDF file
  59. //! @param urdFilename - filename of URDF file, used for resolvement
  60. //! @returns a URDF Asset map where the key is unresolved URDF path to AvailableAsset
  61. UrdfAssetMap FindAssetsForUrdf(const AZStd::unordered_set<AZStd::string>& meshesFilenames, const AZStd::string& urdFilename);
  62. } // namespace ROS2::Utils