AssetLoadTestComponent.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #pragma once
  13. #include <EntityLatticeTestComponent.h>
  14. #include <Utils/ImGuiSidebar.h>
  15. #include <Utils/ImGuiAssetBrowser.h>
  16. #include <AzCore/Component/TickBus.h>
  17. namespace AtomSampleViewer
  18. {
  19. /*
  20. This test loads a configurable lattice of entities and swaps out each entity's model and material
  21. at given time steps. Each entity can have its assets swapped very rapidly (10ths of seconds).
  22. The assets that are applied to the entities are chosen from a configurable
  23. "allow-list" of models and materials. The allow-list is saved to the cache's user folder and
  24. loaded on startup. This makes it easy to chose "working" assets to use in the test vs more development
  25. assets that may not be working properly. It also allows you to build cases where we want
  26. to test instancing more than loading. UI to modify allow-list is a core part of this component.
  27. */
  28. class AssetLoadTestComponent final
  29. : public EntityLatticeTestComponent
  30. , public AZ::TickBus::Handler
  31. {
  32. using Base = EntityLatticeTestComponent;
  33. public:
  34. AZ_COMPONENT(AssetLoadTestComponent, "{30E6EE46-2CD5-4903-801F-56AE70A33656}", EntityLatticeTestComponent);
  35. static void Reflect(AZ::ReflectContext* context);
  36. AssetLoadTestComponent();
  37. //! AZ::Component overrides...
  38. void Activate() override;
  39. void Deactivate() override;
  40. private:
  41. AZ_DISABLE_COPY_MOVE(AssetLoadTestComponent);
  42. // CommonSampleComponentBase overrides...
  43. void OnAllAssetsReadyActivate() override;
  44. //! EntityLatticeTestComponent overrides...
  45. void PrepareCreateLatticeInstances(uint32_t instanceCount) override;
  46. void CreateLatticeInstance(const AZ::Transform& transform) override;
  47. void FinalizeLatticeInstances() override;
  48. void DestroyLatticeInstances() override;
  49. void DestroyHandles();
  50. AZ::Data::AssetId GetRandomModelId() const;
  51. AZ::Data::AssetId GetRandomMaterialId() const;
  52. void OnTick(float deltaTime, AZ::ScriptTimePoint scriptTime) override;
  53. struct ModelInstanceData
  54. {
  55. AZ::Transform m_transform;
  56. AZ::Data::AssetId m_modelAssetId;
  57. AZ::Data::AssetId m_materialAssetId;
  58. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle;
  59. };
  60. ImGuiSidebar m_imguiSidebar;
  61. ImGuiAssetBrowser m_materialBrowser;
  62. ImGuiAssetBrowser m_modelBrowser;
  63. AZStd::vector<ModelInstanceData> m_modelInstanceData;
  64. struct Compare
  65. {
  66. bool operator()(const AZ::Data::Asset<AZ::RPI::MaterialAsset>& lhs, const AZ::Data::Asset<AZ::RPI::MaterialAsset>& rhs) const
  67. {
  68. if (lhs.GetId().m_guid == rhs.GetId().m_guid)
  69. {
  70. return lhs.GetId().m_subId > rhs.GetId().m_subId;
  71. }
  72. return lhs.GetId().m_guid > rhs.GetId().m_guid;
  73. }
  74. };
  75. using MaterialAssetSet = AZStd::set<AZ::Data::Asset<AZ::RPI::MaterialAsset>, Compare>;
  76. MaterialAssetSet m_cachedMaterials;
  77. uint32_t m_pinnedMaterialCount = 0;
  78. size_t m_lastPinnedModelCount = 0;
  79. float m_lastMaterialSwitchInSeconds = 0;
  80. float m_lastModelSwitchInSeconds = 0;
  81. float m_materialSwitchTimeInSeconds = 5.0f;
  82. float m_modelSwitchTimeInSeconds = 3.0f;
  83. bool m_materialSwitchEnabled = true;
  84. bool m_modelSwitchEnabled = true;
  85. bool m_updateTransformEnabled = false;
  86. };
  87. } // namespace AtomSampleViewer