MeshExampleComponent.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <CommonSampleComponentBase.h>
  9. #include <AzCore/Component/EntityBus.h>
  10. #include <AzCore/Component/TickBus.h>
  11. #include <Utils/Utils.h>
  12. #include <Utils/ImGuiSidebar.h>
  13. #include <Utils/ImGuiMaterialDetails.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. namespace AtomSampleViewer
  19. {
  20. class MeshExampleComponent final
  21. : public CommonSampleComponentBase
  22. , public AZ::Render::Bootstrap::DefaultWindowNotificationBus::Handler
  23. , public AZ::TickBus::Handler
  24. {
  25. public:
  26. AZ_COMPONENT(MeshExampleComponent, "{A2402165-5DF1-4981-BF7F-665209640BBD}", CommonSampleComponentBase);
  27. static void Reflect(AZ::ReflectContext* context);
  28. MeshExampleComponent();
  29. ~MeshExampleComponent() override = default;
  30. // AZ::Component
  31. void Activate() override;
  32. void Deactivate() override;
  33. private:
  34. // AZ::TickBus::Handler
  35. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  36. // AZ::EntityBus::MultiHandler
  37. void OnEntityDestruction(const AZ::EntityId& entityId) override;
  38. void ModelChange();
  39. void CreateGroundPlane();
  40. void UpdateGroundPlane();
  41. void RemoveGroundPlane();
  42. void UseArcBallCameraController();
  43. void UseNoClipCameraController();
  44. void RemoveController();
  45. void SetArcBallControllerParams();
  46. void ResetCameraController();
  47. void DefaultWindowCreated() override;
  48. void CreateLowEndPipeline();
  49. void DestroyLowEndPipeline();
  50. void ActivateLowEndPipeline();
  51. void DeactivateLowEndPipeline();
  52. AZ::RPI::RenderPipelinePtr m_lowEndPipeline;
  53. AZ::RPI::RenderPipelinePtr m_originalPipeline;
  54. AZStd::shared_ptr<AZ::RPI::WindowContext> m_windowContext;
  55. AZ::Render::ImGuiActiveContextScope m_imguiScope;
  56. enum class CameraControllerType : int32_t
  57. {
  58. ArcBall = 0,
  59. NoClip,
  60. Count
  61. };
  62. static const uint32_t CameraControllerCount = static_cast<uint32_t>(CameraControllerType::Count);
  63. static const char* CameraControllerNameTable[CameraControllerCount];
  64. CameraControllerType m_currentCameraControllerType = CameraControllerType::ArcBall;
  65. // Not owned by this sample, we look this up
  66. AZ::Component* m_cameraControlComponent = nullptr;
  67. AZ::Render::MeshFeatureProcessorInterface::ModelChangedEvent::Handler m_changedHandler;
  68. static constexpr float ArcballRadiusMinModifier = 0.01f;
  69. static constexpr float ArcballRadiusMaxModifier = 4.0f;
  70. static constexpr float ArcballRadiusDefaultModifier = 2.0f;
  71. AZ::RPI::Cullable::LodOverride m_lodOverride = AZ::RPI::Cullable::NoLodOverride;
  72. bool m_enableMaterialOverride = true;
  73. // If false, only azmaterials generated from ".material" files will be listed.
  74. // Otherwise, all azmaterials, regardless of its source (e.g ".fbx"), will
  75. // be shown in the material list.
  76. bool m_showModelMaterials = false;
  77. bool m_showGroundPlane = false;
  78. bool m_cameraControllerDisabled = false;
  79. bool m_useLowEndPipeline = false;
  80. bool m_switchPipeline = false;
  81. AZ::Data::Instance<AZ::RPI::Material> m_materialOverrideInstance; //< Holds a copy of the material instance being used when m_enableMaterialOverride is true.
  82. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle;
  83. AZ::Data::Asset<AZ::RPI::ModelAsset> m_modelAsset;
  84. AZ::Data::Asset<AZ::RPI::ModelAsset> m_groundPlaneModelAsset;
  85. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_groundPlandMeshHandle;
  86. AZ::Data::Instance<AZ::RPI::Material> m_groundPlaneMaterial;
  87. ImGuiSidebar m_imguiSidebar;
  88. ImGuiMaterialDetails m_imguiMaterialDetails;
  89. ImGuiAssetBrowser m_materialBrowser;
  90. ImGuiAssetBrowser m_modelBrowser;
  91. };
  92. } // namespace AtomSampleViewer