AuxGeomExampleComponent.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #include <AuxGeomExampleComponent.h>
  13. #include <Atom/Component/DebugCamera/NoClipControllerComponent.h>
  14. #include <Atom/RPI.Public/AuxGeom/AuxGeomFeatureProcessorInterface.h>
  15. #include <Atom/RPI.Public/AuxGeom/AuxGeomDraw.h>
  16. #include <AzCore/Component/Entity.h>
  17. #include <AzCore/Math/Matrix3x3.h>
  18. #include <AzFramework/Components/TransformComponent.h>
  19. #include <AzFramework/Components/CameraBus.h>
  20. #include <SampleComponentManager.h>
  21. #include <SampleComponentConfig.h>
  22. #include <AuxGeomSharedDrawFunctions.h>
  23. #include <RHI/BasicRHIComponent.h>
  24. namespace AtomSampleViewer
  25. {
  26. void AuxGeomExampleComponent::Reflect(AZ::ReflectContext* context)
  27. {
  28. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  29. {
  30. serializeContext->Class<AuxGeomExampleComponent, AZ::Component>()
  31. ->Version(0)
  32. ;
  33. }
  34. }
  35. AuxGeomExampleComponent::AuxGeomExampleComponent()
  36. {
  37. }
  38. void AuxGeomExampleComponent::LoadConfigFiles()
  39. {
  40. }
  41. void AuxGeomExampleComponent::Activate()
  42. {
  43. AZ::Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &AZ::Debug::CameraControllerRequestBus::Events::Enable,
  44. azrtti_typeid<AZ::Debug::NoClipControllerComponent>());
  45. Camera::CameraRequestBus::Event(GetCameraEntityId(),
  46. &Camera::CameraRequestBus::Events::SetFarClipDistance,
  47. 200.f);
  48. m_imguiSidebar.Activate();
  49. AZ::TickBus::Handler::BusConnect();
  50. }
  51. void AuxGeomExampleComponent::Deactivate()
  52. {
  53. AZ::TickBus::Handler::BusDisconnect();
  54. m_imguiSidebar.Deactivate();
  55. AZ::Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &AZ::Debug::CameraControllerRequestBus::Events::Disable);
  56. }
  57. void AuxGeomExampleComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
  58. {
  59. if (m_imguiSidebar.Begin())
  60. {
  61. ImGui::Text("Draw Options");
  62. if (ScriptableImGui::Button("Select All"))
  63. {
  64. m_drawBackgroundBox = true;
  65. m_drawThreeGridsOfPoints = true;
  66. m_drawAxisLines = true;
  67. m_drawLines = true;
  68. m_drawTriangles = true;
  69. m_drawShapes = true;
  70. m_drawBoxes = true;
  71. m_drawManyPrimitives = true;
  72. m_drawDepthTestPrimitives = true;
  73. m_draw2DWireRect = true;
  74. }
  75. if (ScriptableImGui::Button("Unselect All"))
  76. {
  77. m_drawBackgroundBox = false;
  78. m_drawThreeGridsOfPoints = false;
  79. m_drawAxisLines = false;
  80. m_drawLines = false;
  81. m_drawTriangles = false;
  82. m_drawShapes = false;
  83. m_drawBoxes = false;
  84. m_drawManyPrimitives = false;
  85. m_drawDepthTestPrimitives = false;
  86. m_draw2DWireRect = false;
  87. }
  88. ImGui::Indent();
  89. ScriptableImGui::Checkbox("Draw background box", &m_drawBackgroundBox);
  90. ScriptableImGui::Checkbox("Draw three grids of points", &m_drawThreeGridsOfPoints);
  91. ScriptableImGui::Checkbox("Draw axis lines", &m_drawAxisLines);
  92. ScriptableImGui::Checkbox("Draw lines", &m_drawLines);
  93. ScriptableImGui::Checkbox("Draw triangles", &m_drawTriangles);
  94. ScriptableImGui::Checkbox("Draw shapex", &m_drawShapes);
  95. ScriptableImGui::Checkbox("Draw boxes", &m_drawBoxes);
  96. ScriptableImGui::Checkbox("Draw many primitives", &m_drawManyPrimitives);
  97. ScriptableImGui::Checkbox("Draw depth test primitives", &m_drawDepthTestPrimitives);
  98. ScriptableImGui::Checkbox("Draw 2d wire rect", &m_draw2DWireRect);
  99. ImGui::Unindent();
  100. m_imguiSidebar.End();
  101. }
  102. // Currently this does this one thing, the intention is that this sample has a sidebar to allow selection of different
  103. // examples/tests
  104. DrawSampleOfAllAuxGeom();
  105. }
  106. void AuxGeomExampleComponent::DrawSampleOfAllAuxGeom() const
  107. {
  108. auto defaultScene = AZ::RPI::RPISystemInterface::Get()->GetDefaultScene();
  109. if (auto auxGeom = AZ::RPI::AuxGeomFeatureProcessorInterface::GetDrawQueueForScene(defaultScene))
  110. {
  111. if (m_drawBackgroundBox)
  112. {
  113. DrawBackgroundBox(auxGeom);
  114. }
  115. if (m_drawThreeGridsOfPoints)
  116. {
  117. DrawThreeGridsOfPoints(auxGeom);
  118. }
  119. if (m_drawAxisLines)
  120. {
  121. DrawAxisLines(auxGeom);
  122. }
  123. if (m_drawLines)
  124. {
  125. DrawLines(auxGeom);
  126. }
  127. if (m_drawTriangles)
  128. {
  129. DrawTriangles(auxGeom);
  130. }
  131. if (m_drawShapes)
  132. {
  133. DrawShapes(auxGeom);
  134. }
  135. if (m_drawBoxes)
  136. {
  137. DrawBoxes(auxGeom);
  138. }
  139. if (m_drawManyPrimitives)
  140. {
  141. DrawManyPrimitives(auxGeom);
  142. }
  143. if (m_drawDepthTestPrimitives)
  144. {
  145. DrawDepthTestPrimitives(auxGeom);
  146. }
  147. if (m_draw2DWireRect)
  148. {
  149. Draw2DWireRect(auxGeom, AZ::Colors::Red, 1.0f);
  150. }
  151. }
  152. }
  153. } // namespace AtomSampleViewer