3
0

ImageAssetProducer.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <AssetBuilderSDK/AssetBuilderSDK.h>
  10. #include <Atom/RPI.Reflect/Image/ImageMipChainAsset.h>
  11. #include <Atom/RPI.Reflect/Image/StreamingImageAsset.h>
  12. #include <Atom/ImageProcessing/ImageObject.h>
  13. namespace ImageProcessingAtom
  14. {
  15. using namespace AZ;
  16. /**
  17. * The ImageAssetProducer saves an ImageObject to a StreamingImageAsset and several MipChainAsset. And save them to files on disk.
  18. * It also generats a list of AssetBuilderSDK::JobProduct which can be used for Image Builder's ProcessJob's result.
  19. */
  20. class ImageAssetProducer
  21. {
  22. public:
  23. /**
  24. * Constructor with all required initialization parameters.
  25. * @param imageObject is the image object to be processed and saved
  26. * @param saveFolder is the path of the folder where the image asset files be saved
  27. * @param sourceAssetId is the asset id of this image. It's used to generate full asset id for MipChainAssets which will be referenced in StreamingImageAsset.
  28. * @param sourceAssetName is the name of source asset file. It doesn't include path.
  29. * @param subId is the product subId to use for the output product.
  30. * @param tags list of tags to save in the image asset.
  31. */
  32. ImageAssetProducer(
  33. const IImageObjectPtr imageObject,
  34. AZStd::string_view saveFolder,
  35. const Data::AssetId& sourceAssetId,
  36. AZStd::string_view sourceAssetName,
  37. uint8_t numResidentMips,
  38. uint32_t subId,
  39. AZStd::set<AZStd::string> tags = AZStd::set<AZStd::string>{});
  40. /// Build image assets for the image object and save them to asset files. It also generates AssetBuilderSDK jobProducts if it success.
  41. bool BuildImageAssets();
  42. /// Return the list of JobProducts. The list could be empty of the build process failed.
  43. const AZStd::vector<AssetBuilderSDK::JobProduct>& GetJobProducts() const;
  44. protected:
  45. enum class ImageAssetType
  46. {
  47. Image,
  48. MipChain,
  49. };
  50. // Generate one MipChainAsset
  51. bool BuildMipChainAsset(const Data::AssetId& chainAssetId, uint32_t startMip, uint32_t mipLevels,
  52. Data::Asset<RPI::ImageMipChainAsset>& outAsset, bool saveAsProduct);
  53. // Generate all job products which can be used for AssetProcessor job response
  54. void GenerateJobProducts();
  55. // Save all generated assets to files
  56. void SaveAssetsToFile();
  57. // Generate product assets' full path
  58. AZStd::string GenerateAssetFullPath(ImageAssetType assetType, uint32_t assetSubId);
  59. private:
  60. ImageAssetProducer() = default;
  61. // All inputs. They shouldn't be modified.
  62. const IImageObjectPtr m_imageObject;
  63. const AZStd::string m_productFolder;
  64. const Data::AssetId m_sourceAssetId;
  65. const AZStd::string m_fileName;
  66. const uint32_t m_subId = AZ::RPI::StreamingImageAsset::GetImageAssetSubId();
  67. const uint8_t m_numResidentMips = 0u;
  68. AZStd::set<AZStd::string> m_tags;
  69. AZStd::vector<AssetBuilderSDK::JobProduct> m_jobProducts;
  70. };
  71. }