MeshExampleComponent.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 <CommonSampleComponentBase.h>
  10. #include <AzCore/Component/EntityBus.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <Utils/Utils.h>
  13. #include <Utils/ImGuiSidebar.h>
  14. #include <Utils/ImGuiAssetBrowser.h>
  15. #include <Atom/Bootstrap/DefaultWindowBus.h>
  16. #include <Atom/Feature/ImGui/ImGuiUtils.h>
  17. #include <Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h>
  18. #include <Atom/Utils/ImGuiMaterialDetails.h>
  19. namespace AtomSampleViewer
  20. {
  21. class MeshExampleComponent final
  22. : public CommonSampleComponentBase
  23. , public AZ::Render::Bootstrap::DefaultWindowNotificationBus::Handler
  24. , public AZ::TickBus::Handler
  25. {
  26. public:
  27. AZ_COMPONENT(MeshExampleComponent, "{A2402165-5DF1-4981-BF7F-665209640BBD}", CommonSampleComponentBase);
  28. static void Reflect(AZ::ReflectContext* context);
  29. MeshExampleComponent();
  30. ~MeshExampleComponent() override = default;
  31. // AZ::Component
  32. void Activate() override;
  33. void Deactivate() override;
  34. private:
  35. // AZ::TickBus::Handler
  36. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  37. // AZ::EntityBus::MultiHandler
  38. void OnEntityDestruction(const AZ::EntityId& entityId) override;
  39. void ModelChange();
  40. void CreateGroundPlane();
  41. void UpdateGroundPlane();
  42. void RemoveGroundPlane();
  43. void UseArcBallCameraController();
  44. void UseNoClipCameraController();
  45. void RemoveController();
  46. void SetArcBallControllerParams();
  47. void ResetCameraController();
  48. void DefaultWindowCreated() override;
  49. void CreateLowEndPipeline();
  50. void DestroyLowEndPipeline();
  51. void CreateDeferredPipeline();
  52. void DestroyDeferredPipeline();
  53. void CreateMultiViewXRPipeline();
  54. void DestroyMultiViewXRPipeline();
  55. void ActivateLowEndPipeline();
  56. void ActivateMultiViewXRPipeline();
  57. void ActivateDeferredPipeline();
  58. void ActivateOriginalPipeline();
  59. enum class Pipeline
  60. {
  61. Original,
  62. LowEnd,
  63. Deferred
  64. };
  65. Pipeline m_currentPipeline = Pipeline::Original;
  66. AZ::RPI::RenderPipelinePtr m_lowEndPipeline = nullptr;
  67. AZ::RPI::RenderPipelinePtr m_deferredPipeline = nullptr;
  68. AZ::RPI::RenderPipelinePtr m_multiViewXRPipeline = nullptr;
  69. AZ::RPI::RenderPipelinePtr m_originalPipeline = nullptr;
  70. AZStd::shared_ptr<AZ::RPI::WindowContext> m_windowContext;
  71. AZ::Render::ImGuiActiveContextScope m_imguiScope;
  72. enum class CameraControllerType : int32_t
  73. {
  74. ArcBall = 0,
  75. NoClip,
  76. Count
  77. };
  78. static const uint32_t CameraControllerCount = static_cast<uint32_t>(CameraControllerType::Count);
  79. static const char* CameraControllerNameTable[CameraControllerCount];
  80. CameraControllerType m_currentCameraControllerType = CameraControllerType::ArcBall;
  81. static constexpr float ArcballRadiusMinModifier = 0.01f;
  82. static constexpr float ArcballRadiusMaxModifier = 4.0f;
  83. static constexpr float ArcballRadiusDefaultModifier = 2.0f;
  84. AZ::RPI::Cullable::LodConfiguration m_lodConfig;
  85. bool m_enableMaterialOverride = true;
  86. // If false, only azmaterials generated from ".material" files will be listed.
  87. // Otherwise, all azmaterials, regardless of its source (e.g ".fbx"), will
  88. // be shown in the material list.
  89. bool m_showModelMaterials = false;
  90. bool m_showGroundPlane = false;
  91. bool m_cameraControllerDisabled = false;
  92. bool m_useLowEndPipeline = false;
  93. bool m_useDeferredPipeline = false;
  94. bool m_useMultiViewXRPipeline = false;
  95. bool m_switchPipeline = false;
  96. AZ::Data::Instance<AZ::RPI::Material> m_customMaterialInstance; //< Holds a copy of the material instance being used when m_enableMaterialOverride is true.
  97. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle;
  98. AZ::Data::Asset<AZ::RPI::ModelAsset> m_modelAsset;
  99. AZ::Data::Asset<AZ::RPI::ModelAsset> m_groundPlaneModelAsset;
  100. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_groundPlandMeshHandle;
  101. AZ::Data::Instance<AZ::RPI::Material> m_groundPlaneMaterial;
  102. ImGuiSidebar m_imguiSidebar;
  103. AZ::Render::ImGuiMaterialDetails m_imguiMaterialDetails;
  104. ImGuiAssetBrowser m_materialBrowser;
  105. ImGuiAssetBrowser m_modelBrowser;
  106. };
  107. } // namespace AtomSampleViewer