AuxGeomExampleComponent.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. if (m_imguiSidebar.Begin())
  56. {
  57. ImGui::Text("Draw Options");
  58. if (ScriptableImGui::Button("Select All"))
  59. {
  60. m_drawBackgroundBox = true;
  61. m_drawThreeGridsOfPoints = true;
  62. m_drawAxisLines = true;
  63. m_drawLines = true;
  64. m_drawTriangles = true;
  65. m_drawShapes = true;
  66. m_drawBoxes = true;
  67. m_drawManyPrimitives = true;
  68. m_drawDepthTestPrimitives = true;
  69. m_draw2DWireRect = true;
  70. }
  71. if (ScriptableImGui::Button("Unselect All"))
  72. {
  73. m_drawBackgroundBox = false;
  74. m_drawThreeGridsOfPoints = false;
  75. m_drawAxisLines = false;
  76. m_drawLines = false;
  77. m_drawTriangles = false;
  78. m_drawShapes = false;
  79. m_drawBoxes = false;
  80. m_drawManyPrimitives = false;
  81. m_drawDepthTestPrimitives = false;
  82. m_draw2DWireRect = false;
  83. }
  84. ImGui::Indent();
  85. ScriptableImGui::Checkbox("Draw background box", &m_drawBackgroundBox);
  86. ScriptableImGui::Checkbox("Draw three grids of points", &m_drawThreeGridsOfPoints);
  87. ScriptableImGui::Checkbox("Draw axis lines", &m_drawAxisLines);
  88. ScriptableImGui::Checkbox("Draw lines", &m_drawLines);
  89. ScriptableImGui::Checkbox("Draw triangles", &m_drawTriangles);
  90. ScriptableImGui::Checkbox("Draw shapes", &m_drawShapes);
  91. ScriptableImGui::Checkbox("Draw boxes", &m_drawBoxes);
  92. ScriptableImGui::Checkbox("Draw many primitives", &m_drawManyPrimitives);
  93. ScriptableImGui::Checkbox("Draw depth test primitives", &m_drawDepthTestPrimitives);
  94. ScriptableImGui::Checkbox("Draw 2d wire rect", &m_draw2DWireRect);
  95. ImGui::Unindent();
  96. m_imguiSidebar.End();
  97. }
  98. // Currently this does this one thing, the intention is that this sample has a sidebar to allow selection of different
  99. // examples/tests
  100. DrawSampleOfAllAuxGeom();
  101. }
  102. void AuxGeomExampleComponent::DrawSampleOfAllAuxGeom() const
  103. {
  104. if (auto auxGeom = AZ::RPI::AuxGeomFeatureProcessorInterface::GetDrawQueueForScene(m_scene))
  105. {
  106. if (m_drawBackgroundBox)
  107. {
  108. DrawBackgroundBox(auxGeom);
  109. }
  110. if (m_drawThreeGridsOfPoints)
  111. {
  112. DrawThreeGridsOfPoints(auxGeom);
  113. }
  114. if (m_drawAxisLines)
  115. {
  116. DrawAxisLines(auxGeom);
  117. }
  118. if (m_drawLines)
  119. {
  120. DrawLines(auxGeom);
  121. }
  122. if (m_drawTriangles)
  123. {
  124. DrawTriangles(auxGeom);
  125. }
  126. if (m_drawShapes)
  127. {
  128. DrawShapes(auxGeom);
  129. }
  130. if (m_drawBoxes)
  131. {
  132. DrawBoxes(auxGeom);
  133. }
  134. if (m_drawManyPrimitives)
  135. {
  136. DrawManyPrimitives(auxGeom);
  137. }
  138. if (m_drawDepthTestPrimitives)
  139. {
  140. DrawDepthTestPrimitives(auxGeom);
  141. }
  142. if (m_draw2DWireRect)
  143. {
  144. Draw2DWireRect(auxGeom, AZ::Colors::Red, 1.0f);
  145. }
  146. }
  147. }
  148. } // namespace AtomSampleViewer