ModelReloader.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/RTTI/TypeInfo.h>
  11. #include <Atom/Feature/Mesh/ModelReloaderSystemInterface.h>
  12. #include <Mesh/ModelReloaderSystem.h>
  13. namespace AZ
  14. {
  15. namespace RPI
  16. {
  17. class ModelAsset;
  18. }
  19. namespace Render
  20. {
  21. //! ModelReloader takes care of reloading Buffer, ModelLod, and Model assets in the correct order
  22. //! The ModelReloaderSystem should be used to reload a model, rather than using a ModelReloader directly
  23. class ModelReloader
  24. : private Data::AssetBus::MultiHandler
  25. {
  26. using DependencyList = AZStd::vector<Data::Asset<Data::AssetData>>;
  27. public:
  28. AZ_RTTI(AZ::Render::ModelReloader, "{99B75A6A-62B6-490A-9953-029BE7D69452}");
  29. ModelReloader() = default;
  30. //! Reload a model asset
  31. //! @param modelAsset - the asset to be reloaded
  32. ModelReloader(Data::Asset<RPI::ModelAsset> modelAsset);
  33. //! Connects a handler that will handle an event when the model is finished reloading
  34. void ConnectOnReloadedEventHandler(ModelReloadedEvent::Handler& onReloadedEventHandler);
  35. private:
  36. enum class State
  37. {
  38. WaitingForMeshDependencies,
  39. WaitingForModelDependencies,
  40. WaitingForModel
  41. };
  42. // Data::AssetBus::MultiHandler overrides...
  43. void OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset) override;
  44. void OnAssetReloadError(Data::Asset<Data::AssetData> asset) override;
  45. void InsertMeshDependencyIfUnique(Data::Asset<Data::AssetData> asset);
  46. void ReloadDependenciesAndWait();
  47. void AdvanceToNextLevelOfHierarchy();
  48. DependencyList& GetPendingDependencyList();
  49. ModelReloadedEvent m_onModelReloaded;
  50. // Keep track of all the asset references for each level of the hierarchy
  51. DependencyList m_modelAsset;
  52. DependencyList m_meshDependencies;
  53. DependencyList m_modelDependencies;
  54. AZStd::bitset<1024> m_pendingDependencyListStatus;
  55. State m_state;
  56. };
  57. } // namespace Render
  58. } // namespace AZ