MeshletsExampleComponent.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <Atom/Utils/ImGuiMaterialDetails.h>
  15. #include <Utils/ImGuiAssetBrowser.h>
  16. #include <Atom/Bootstrap/DefaultWindowBus.h>
  17. #include <Atom/Feature/ImGui/ImGuiUtils.h>
  18. #include <Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h>
  19. #include <MeshletsAssets.h>
  20. #include <MeshletsRenderObject.h>
  21. namespace AZ
  22. {
  23. namespace Meshlets
  24. {
  25. class MeshletsFeatureProcessor;
  26. }
  27. }
  28. namespace AtomSampleViewer
  29. {
  30. class MeshletsExampleComponent final
  31. : public CommonSampleComponentBase
  32. , public AZ::Render::Bootstrap::DefaultWindowNotificationBus::Handler
  33. , public AZ::TickBus::Handler
  34. {
  35. public:
  36. AZ_COMPONENT(MeshletsExampleComponent, "{BFE93321-91A4-4087-BABE-8B475087BBAD}", CommonSampleComponentBase);
  37. static void Reflect(AZ::ReflectContext* context);
  38. MeshletsExampleComponent();
  39. ~MeshletsExampleComponent() override = default;
  40. // AZ::Component
  41. void Activate() override;
  42. void Deactivate() override;
  43. private:
  44. // AZ::TickBus::Handler
  45. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  46. // AZ::EntityBus::MultiHandler
  47. void OnEntityDestruction(const AZ::EntityId& entityId) override;
  48. void ModelChange();
  49. void CreateGroundPlane();
  50. void UpdateGroundPlane();
  51. void RemoveGroundPlane();
  52. void UseArcBallCameraController();
  53. void UseNoClipCameraController();
  54. void RemoveController();
  55. void SetArcBallControllerParams();
  56. void ResetCameraController();
  57. void DefaultWindowCreated() override;
  58. AZ::Meshlets::MeshletsFeatureProcessor* GetMeshletsFeatureProcessor();
  59. AZStd::shared_ptr<AZ::RPI::WindowContext> m_windowContext;
  60. AZ::Render::ImGuiActiveContextScope m_imguiScope;
  61. enum class CameraControllerType : int32_t
  62. {
  63. ArcBall = 0,
  64. NoClip,
  65. Count
  66. };
  67. static const uint32_t CameraControllerCount = static_cast<uint32_t>(CameraControllerType::Count);
  68. static const char* CameraControllerNameTable[CameraControllerCount];
  69. CameraControllerType m_currentCameraControllerType = CameraControllerType::ArcBall;
  70. AZ::Render::MeshFeatureProcessorInterface::ModelChangedEvent::Handler m_changedHandler;
  71. static constexpr float ArcballRadiusMinModifier = 0.01f;
  72. static constexpr float ArcballRadiusMaxModifier = 4.0f;
  73. static constexpr float ArcballRadiusDefaultModifier = 2.0f;
  74. AZ::RPI::Cullable::LodConfiguration m_lodConfig;
  75. bool m_enableMaterialOverride = true;
  76. // If false, only azmaterials generated from ".material" files will be listed.
  77. // Otherwise, all azmaterials, regardless of its source (e.g ".fbx"), will
  78. // be shown in the material list.
  79. bool m_showModelMaterials = false;
  80. bool m_showGroundPlane = false;
  81. bool m_cameraControllerDisabled = false;
  82. AZ::Meshlets::MeshletsFeatureProcessor* m_meshletsFeatureProcessor = nullptr;
  83. AZ::Data::Instance<AZ::RPI::Material> m_materialOverrideInstance; //< Holds a copy of the material instance being used when m_enableMaterialOverride is true.
  84. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle;
  85. AZ::Data::Asset<AZ::RPI::ModelAsset> m_modelAsset;
  86. // This is the data stored for the copied mesh with the new generated meshlets structure.
  87. AZ::Data::Instance<AZ::RPI::Material> m_meshletsDebugMaterial;
  88. AZ::Meshlets::MeshletsModel* m_meshetsModel = nullptr;
  89. AZ::Meshlets::MeshletsRenderObject* m_meshetsRenderObject = nullptr;
  90. AZ::Data::Asset<AZ::RPI::ModelAsset> m_meshletsModelAsset;
  91. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshletsMeshHandle;
  92. AZ::Render::TransformServiceFeatureProcessorInterface::ObjectId m_meshletObjectId;
  93. AZ::Data::Asset<AZ::RPI::ModelAsset> m_groundPlaneModelAsset;
  94. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_groundPlandMeshHandle;
  95. AZ::Data::Instance<AZ::RPI::Material> m_groundPlaneMaterial;
  96. ImGuiSidebar m_imguiSidebar;
  97. AZ::Render::ImGuiMaterialDetails m_imguiMaterialDetails;
  98. ImGuiAssetBrowser m_materialBrowser;
  99. ImGuiAssetBrowser m_modelBrowser;
  100. };
  101. } // namespace AtomSampleViewer