AuxGeomExampleComponent.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. #include <AuxGeomExampleComponent.h>
  9. #include <Atom/Component/DebugCamera/NoClipControllerComponent.h>
  10. #include <Atom/RPI.Public/AuxGeom/AuxGeomFeatureProcessorInterface.h>
  11. #include <Atom/RPI.Public/AuxGeom/AuxGeomDraw.h>
  12. #include <AzCore/Component/Entity.h>
  13. #include <AzCore/Math/Matrix3x3.h>
  14. #include <AzFramework/Components/TransformComponent.h>
  15. #include <AzFramework/Components/CameraBus.h>
  16. #include <SampleComponentManager.h>
  17. #include <SampleComponentConfig.h>
  18. #include <AuxGeomSharedDrawFunctions.h>
  19. #include <RHI/BasicRHIComponent.h>
  20. namespace AtomSampleViewer
  21. {
  22. void AuxGeomExampleComponent::Reflect(AZ::ReflectContext* context)
  23. {
  24. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  25. {
  26. serializeContext->Class<AuxGeomExampleComponent, AZ::Component>()
  27. ->Version(0)
  28. ;
  29. }
  30. }
  31. AuxGeomExampleComponent::AuxGeomExampleComponent()
  32. {
  33. }
  34. void AuxGeomExampleComponent::LoadConfigFiles()
  35. {
  36. }
  37. void AuxGeomExampleComponent::Activate()
  38. {
  39. AZ::Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &AZ::Debug::CameraControllerRequestBus::Events::Enable,
  40. azrtti_typeid<AZ::Debug::NoClipControllerComponent>());
  41. Camera::CameraRequestBus::Event(GetCameraEntityId(),
  42. &Camera::CameraRequestBus::Events::SetFarClipDistance,
  43. 200.f);
  44. m_imguiSidebar.Activate();
  45. AZ::TickBus::Handler::BusConnect();
  46. }
  47. void AuxGeomExampleComponent::Deactivate()
  48. {
  49. AZ::TickBus::Handler::BusDisconnect();
  50. m_imguiSidebar.Deactivate();
  51. AZ::Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &AZ::Debug::CameraControllerRequestBus::Events::Disable);
  52. }
  53. void AuxGeomExampleComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
  54. {
  55. AZ_PROFILE_SCOPE(AzRender, "AuxGeomExampleComponent: OnTick");
  56. if (m_imguiSidebar.Begin())
  57. {
  58. ImGui::Text("Draw Options");
  59. if (ScriptableImGui::Button("Select All"))
  60. {
  61. m_drawBackgroundBox = true;
  62. m_drawThreeGridsOfPoints = true;
  63. m_drawAxisLines = true;
  64. m_drawLines = true;
  65. m_drawTriangles = true;
  66. m_drawShapes = true;
  67. m_drawBoxes = true;
  68. m_drawManyPrimitives = true;
  69. m_drawDepthTestPrimitives = true;
  70. m_draw2DWireRect = true;
  71. }
  72. if (ScriptableImGui::Button("Unselect All"))
  73. {
  74. m_drawBackgroundBox = false;
  75. m_drawThreeGridsOfPoints = false;
  76. m_drawAxisLines = false;
  77. m_drawLines = false;
  78. m_drawTriangles = false;
  79. m_drawShapes = false;
  80. m_drawBoxes = false;
  81. m_drawManyPrimitives = false;
  82. m_drawDepthTestPrimitives = false;
  83. m_draw2DWireRect = false;
  84. }
  85. ImGui::Indent();
  86. ScriptableImGui::Checkbox("Draw background box", &m_drawBackgroundBox);
  87. ScriptableImGui::Checkbox("Draw three grids of points", &m_drawThreeGridsOfPoints);
  88. ScriptableImGui::Checkbox("Draw axis lines", &m_drawAxisLines);
  89. ScriptableImGui::Checkbox("Draw lines", &m_drawLines);
  90. ScriptableImGui::Checkbox("Draw triangles", &m_drawTriangles);
  91. ScriptableImGui::Checkbox("Draw shapes", &m_drawShapes);
  92. ScriptableImGui::Checkbox("Draw boxes", &m_drawBoxes);
  93. ScriptableImGui::Checkbox("Draw many primitives", &m_drawManyPrimitives);
  94. ScriptableImGui::Checkbox("Draw depth test primitives", &m_drawDepthTestPrimitives);
  95. ScriptableImGui::Checkbox("Draw 2d wire rect", &m_draw2DWireRect);
  96. ImGui::Unindent();
  97. m_imguiSidebar.End();
  98. }
  99. // Currently this does this one thing, the intention is that this sample has a sidebar to allow selection of different
  100. // examples/tests
  101. DrawSampleOfAllAuxGeom();
  102. }
  103. void AuxGeomExampleComponent::DrawSampleOfAllAuxGeom() const
  104. {
  105. if (auto auxGeom = AZ::RPI::AuxGeomFeatureProcessorInterface::GetDrawQueueForScene(m_scene))
  106. {
  107. if (m_drawBackgroundBox)
  108. {
  109. DrawBackgroundBox(auxGeom);
  110. }
  111. if (m_drawThreeGridsOfPoints)
  112. {
  113. DrawThreeGridsOfPoints(auxGeom);
  114. }
  115. if (m_drawAxisLines)
  116. {
  117. DrawAxisLines(auxGeom);
  118. }
  119. if (m_drawLines)
  120. {
  121. DrawLines(auxGeom);
  122. }
  123. if (m_drawTriangles)
  124. {
  125. DrawTriangles(auxGeom);
  126. }
  127. if (m_drawShapes)
  128. {
  129. DrawShapes(auxGeom);
  130. }
  131. if (m_drawBoxes)
  132. {
  133. DrawBoxes(auxGeom);
  134. }
  135. if (m_drawManyPrimitives)
  136. {
  137. DrawManyPrimitives(auxGeom);
  138. }
  139. if (m_drawDepthTestPrimitives)
  140. {
  141. DrawDepthTestPrimitives(auxGeom);
  142. }
  143. if (m_draw2DWireRect)
  144. {
  145. Draw2DWireRect(auxGeom, AZ::Colors::Red, 1.0f);
  146. }
  147. }
  148. }
  149. } // namespace AtomSampleViewer