EditorMaterialComponentExporter.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/AssetManagerBus.h>
  11. #include <AzCore/std/containers/vector.h>
  12. #include <AzCore/std/smart_ptr/unique_ptr.h>
  13. #include <AzCore/std/string/string.h>
  14. AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
  15. #include <QProgressDialog>
  16. AZ_POP_DISABLE_WARNING
  17. namespace AZ
  18. {
  19. namespace Render
  20. {
  21. namespace EditorMaterialComponentExporter
  22. {
  23. //! Generates a destination file path for exporting material source data
  24. AZStd::string GetExportPathByAssetId(const AZ::Data::AssetId& assetId, const AZStd::string& materialSlotName);
  25. class ExportItem
  26. {
  27. public:
  28. //! @param originalAssetId AssetId of the original built-in material, which will be exported.
  29. //! @param materialSlotName The name of the material slot will be used as part of the exported file name.
  30. ExportItem(AZ::Data::AssetId originalAssetId, const AZStd::string& materialSlotName, const AZStd::string& exportPath = {})
  31. : m_originalAssetId(originalAssetId)
  32. , m_materialSlotName(materialSlotName)
  33. , m_exportPath(!exportPath.empty() ? exportPath : GetExportPathByAssetId(originalAssetId, materialSlotName))
  34. {
  35. }
  36. void SetEnabled(bool enabled) { m_enabled = enabled; }
  37. void SetExists(bool exists) { m_exists = exists; }
  38. void SetOverwrite(bool overwrite) { m_overwrite = overwrite; }
  39. void SetExportPath(const AZStd::string& exportPath) { m_exportPath = exportPath; }
  40. bool GetEnabled() const { return m_enabled; }
  41. bool GetExists() const { return m_exists; }
  42. bool GetOverwrite() const { return m_overwrite; }
  43. const AZStd::string& GetExportPath() const { return m_exportPath; }
  44. AZ::Data::AssetId GetOriginalAssetId() const { return m_originalAssetId; }
  45. const AZStd::string& GetMaterialSlotName() const { return m_materialSlotName; }
  46. private:
  47. bool m_enabled = true;
  48. bool m_exists = false;
  49. bool m_overwrite = false;
  50. AZStd::string m_exportPath;
  51. AZ::Data::AssetId m_originalAssetId; //!< AssetId of the original built-in material, which will be exported.
  52. AZStd::string m_materialSlotName;
  53. };
  54. using ExportItemsContainer = AZStd::vector<ExportItem>;
  55. //! Generates and opens a dialog for configuring material data export paths and actions.
  56. //! Note this will not modify the m_originalAssetId field in each ExportItem.
  57. bool OpenExportDialog(ExportItemsContainer& exportItems);
  58. //! Attemts to construct and save material source data from a product asset
  59. bool ExportMaterialSourceData(const ExportItem& exportItem);
  60. //! Create a progress dialog for displaying the status of generated material assets.
  61. class ProgressDialog
  62. {
  63. public:
  64. ProgressDialog(const AZStd::string& title, const AZStd::string& label, const int itemCount);
  65. ~ProgressDialog() = default;
  66. //! Blocking call that polls for asset info until valid or the user cancels the operation.
  67. AZ::Data::AssetInfo ProcessItem(const ExportItem& exportItem);
  68. //! Increment the progress bar in the dialog.
  69. void CompleteItem();
  70. private:
  71. AZStd::unique_ptr<QProgressDialog> m_progressDialog;
  72. };
  73. } // namespace EditorMaterialComponentExporter
  74. } // namespace Render
  75. } // namespace AZ