AuxGeomExampleComponent.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. #include <AuxGeomExampleComponent.h>
  8. #include <Atom/Component/DebugCamera/NoClipControllerComponent.h>
  9. #include <Atom/RPI.Public/AuxGeom/AuxGeomFeatureProcessorInterface.h>
  10. #include <Atom/RPI.Public/AuxGeom/AuxGeomDraw.h>
  11. #include <AzCore/Component/Entity.h>
  12. #include <AzCore/Math/Matrix3x3.h>
  13. #include <AzFramework/Components/TransformComponent.h>
  14. #include <AzFramework/Components/CameraBus.h>
  15. #include <SampleComponentManager.h>
  16. #include <SampleComponentConfig.h>
  17. #include <AuxGeomSharedDrawFunctions.h>
  18. #include <RHI/BasicRHIComponent.h>
  19. namespace AtomSampleViewer
  20. {
  21. void AuxGeomExampleComponent::Reflect(AZ::ReflectContext* context)
  22. {
  23. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  24. {
  25. serializeContext->Class<AuxGeomExampleComponent, AZ::Component>()
  26. ->Version(0)
  27. ;
  28. }
  29. }
  30. AuxGeomExampleComponent::AuxGeomExampleComponent()
  31. {
  32. }
  33. void AuxGeomExampleComponent::LoadConfigFiles()
  34. {
  35. }
  36. void AuxGeomExampleComponent::Activate()
  37. {
  38. AZ::Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &AZ::Debug::CameraControllerRequestBus::Events::Enable,
  39. azrtti_typeid<AZ::Debug::NoClipControllerComponent>());
  40. Camera::CameraRequestBus::Event(GetCameraEntityId(),
  41. &Camera::CameraRequestBus::Events::SetFarClipDistance,
  42. 200.f);
  43. m_imguiSidebar.Activate();
  44. AZ::TickBus::Handler::BusConnect();
  45. }
  46. void AuxGeomExampleComponent::Deactivate()
  47. {
  48. AZ::TickBus::Handler::BusDisconnect();
  49. m_imguiSidebar.Deactivate();
  50. AZ::Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &AZ::Debug::CameraControllerRequestBus::Events::Disable);
  51. }
  52. void AuxGeomExampleComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
  53. {
  54. if (m_imguiSidebar.Begin())
  55. {
  56. ImGui::Text("Draw Options");
  57. if (ScriptableImGui::Button("Select All"))
  58. {
  59. m_drawBackgroundBox = true;
  60. m_drawThreeGridsOfPoints = true;
  61. m_drawAxisLines = true;
  62. m_drawLines = true;
  63. m_drawTriangles = true;
  64. m_drawShapes = true;
  65. m_drawBoxes = true;
  66. m_drawManyPrimitives = true;
  67. m_drawDepthTestPrimitives = true;
  68. m_draw2DWireRect = true;
  69. }
  70. if (ScriptableImGui::Button("Unselect All"))
  71. {
  72. m_drawBackgroundBox = false;
  73. m_drawThreeGridsOfPoints = false;
  74. m_drawAxisLines = false;
  75. m_drawLines = false;
  76. m_drawTriangles = false;
  77. m_drawShapes = false;
  78. m_drawBoxes = false;
  79. m_drawManyPrimitives = false;
  80. m_drawDepthTestPrimitives = false;
  81. m_draw2DWireRect = false;
  82. }
  83. ImGui::Indent();
  84. ScriptableImGui::Checkbox("Draw background box", &m_drawBackgroundBox);
  85. ScriptableImGui::Checkbox("Draw three grids of points", &m_drawThreeGridsOfPoints);
  86. ScriptableImGui::Checkbox("Draw axis lines", &m_drawAxisLines);
  87. ScriptableImGui::Checkbox("Draw lines", &m_drawLines);
  88. ScriptableImGui::Checkbox("Draw triangles", &m_drawTriangles);
  89. ScriptableImGui::Checkbox("Draw shapes", &m_drawShapes);
  90. ScriptableImGui::Checkbox("Draw boxes", &m_drawBoxes);
  91. ScriptableImGui::Checkbox("Draw many primitives", &m_drawManyPrimitives);
  92. ScriptableImGui::Checkbox("Draw depth test primitives", &m_drawDepthTestPrimitives);
  93. ScriptableImGui::Checkbox("Draw 2d wire rect", &m_draw2DWireRect);
  94. ImGui::Unindent();
  95. m_imguiSidebar.End();
  96. }
  97. // Currently this does this one thing, the intention is that this sample has a sidebar to allow selection of different
  98. // examples/tests
  99. DrawSampleOfAllAuxGeom();
  100. }
  101. void AuxGeomExampleComponent::DrawSampleOfAllAuxGeom() const
  102. {
  103. auto defaultScene = AZ::RPI::RPISystemInterface::Get()->GetDefaultScene();
  104. if (auto auxGeom = AZ::RPI::AuxGeomFeatureProcessorInterface::GetDrawQueueForScene(defaultScene))
  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