AssetImportRequest.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/EBus/EBus.h>
  10. #include <AzCore/Math/Uuid.h>
  11. #include <AzCore/std/smart_ptr/shared_ptr.h>
  12. #include <AzCore/std/string/string.h>
  13. #include <AzCore/std/containers/unordered_set.h>
  14. #include <SceneAPI/SceneCore/SceneCoreConfiguration.h>
  15. #include <SceneAPI/SceneCore/Events/ProcessingResult.h>
  16. namespace AZ
  17. {
  18. namespace SceneAPI
  19. {
  20. namespace Containers
  21. {
  22. class Scene;
  23. }
  24. namespace Events
  25. {
  26. enum class LoadingResult
  27. {
  28. Ignored,
  29. AssetLoaded,
  30. ManifestLoaded,
  31. AssetFailure,
  32. ManifestFailure
  33. };
  34. class SCENE_CORE_API LoadingResultCombiner
  35. {
  36. public:
  37. LoadingResultCombiner();
  38. void operator= (LoadingResult rhs);
  39. ProcessingResult GetManifestResult() const;
  40. ProcessingResult GetAssetResult() const;
  41. private:
  42. ProcessingResult m_manifestResult;
  43. ProcessingResult m_assetResult;
  44. };
  45. class SCENE_CORE_API AssetImportRequest
  46. : public AZ::EBusTraits
  47. {
  48. public:
  49. enum RequestingApplication
  50. {
  51. Generic,
  52. Editor,
  53. AssetProcessor
  54. };
  55. enum ManifestAction
  56. {
  57. Update,
  58. ConstructDefault
  59. };
  60. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
  61. using MutexType = AZStd::recursive_mutex;
  62. static AZ::Crc32 GetAssetImportRequestComponentTag()
  63. {
  64. return AZ_CRC_CE("AssetImportRequest");
  65. }
  66. virtual ~AssetImportRequest() = 0;
  67. //! Fills the given list with all available file extensions, excluding the extension for the manifest.
  68. virtual void GetSupportedFileExtensions(AZStd::unordered_set<AZStd::string>& extensions);
  69. //! Gets the file extension for the manifest.
  70. virtual void GetManifestExtension(AZStd::string& result);
  71. //! Gets the file extension for the generated manifest.
  72. virtual void GetGeneratedManifestExtension(AZStd::string& result);
  73. //! Before asset loading starts this is called to allow for any required initialization.
  74. virtual ProcessingResult PrepareForAssetLoading(Containers::Scene& scene, RequestingApplication requester);
  75. //! Starts the loading of the asset at the given path in the given scene. Loading optimizations can be applied based on
  76. //! the calling application.
  77. virtual LoadingResult LoadAsset(Containers::Scene& scene, const AZStd::string& path, const Uuid& guid, RequestingApplication requester);
  78. //! FinalizeAssetLoading can be used to do any work to complete loading, such as complete asynchronous loading
  79. //! or adjust the loaded content in the the SceneGraph. While manifest changes can be done here as well, it's
  80. //! recommended to wait for the UpdateManifest call.
  81. virtual void FinalizeAssetLoading(Containers::Scene& scene, RequestingApplication requester);
  82. //! After all loading has completed, this call can be used to make adjustments to the manifest. Based on the given
  83. //! action this can mean constructing a new manifest or updating an existing manifest. This call is intended
  84. //! to deal with any default behavior of the manifest.
  85. virtual ProcessingResult UpdateManifest(Containers::Scene& scene, ManifestAction action,
  86. RequestingApplication requester);
  87. // Get scene processing project setting: UseCustomNormal
  88. virtual void AreCustomNormalsUsed(bool & value);
  89. /*!
  90. Optional method for reporting source file dependencies that may exist in the scene manifest
  91. Paths is a vector of JSON Path strings, relative to the IRule object
  92. For example, the following path: /scriptFilename
  93. Would match with this manifest:
  94. {
  95. "values": [
  96. {
  97. "$type": "Test",
  98. "scriptFilename": "file.py"
  99. }
  100. ]
  101. }
  102. */
  103. virtual void GetManifestDependencyPaths(AZStd::vector<AZStd::string>& paths);
  104. //! Utility function to load an asset and manifest from file by using the EBus functions above.
  105. //! @param assetFilePath The absolute path to the source file (not the manifest).
  106. //! @param sourceGuid The guid assigned to the source file (not the manifest).
  107. //! @param requester The application making the request to load the file. This can be used to optimize the type and amount of data
  108. //! to load.
  109. //! @param loadingComponentUuid The UUID assigned to the loading component.
  110. static AZStd::shared_ptr<Containers::Scene> LoadSceneFromVerifiedPath(const AZStd::string& assetFilePath,
  111. const Uuid& sourceGuid, RequestingApplication requester, const Uuid& loadingComponentUuid);
  112. //! Utility function to determine if a given file path points to a scene manifest file (.assetinfo).
  113. //! @param filePath A relative or absolute path to the file to check.
  114. static bool IsManifestExtension(const char* filePath);
  115. //! Utility function to determine if a given file path points to a scene file (for instance .fbx).
  116. //! @param filePath A relative or absolute path to the file to check.
  117. static bool IsSceneFileExtension(const char* filePath);
  118. };
  119. using AssetImportRequestBus = AZ::EBus<AssetImportRequest>;
  120. inline AssetImportRequest::~AssetImportRequest() = default;
  121. } // namespace Events
  122. } // namespace SceneAPI
  123. } // namespace AZ