GridComponentController.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <Atom/RPI.Public/SceneBus.h>
  10. #include <AtomLyIntegration/CommonFeatures/Grid/GridComponentBus.h>
  11. #include <AtomLyIntegration/CommonFeatures/Grid/GridComponentConfig.h>
  12. #include <AzCore/Component/Component.h>
  13. #include <AzCore/Component/TransformBus.h>
  14. namespace AZ
  15. {
  16. namespace Render
  17. {
  18. //! Controls behavior and rendering of a wireframe grid
  19. class GridComponentController final
  20. : public GridComponentRequestBus::Handler
  21. , public AZ::TransformNotificationBus::Handler
  22. , public AZ::RPI::SceneNotificationBus::Handler
  23. {
  24. public:
  25. friend class EditorGridComponent;
  26. AZ_CLASS_ALLOCATOR(GridComponentController, SystemAllocator);
  27. AZ_RTTI(AZ::Render::GridComponentController, "{D2FF04F5-2F8D-44C5-99CA-A6FF800187DD}");
  28. static void Reflect(ReflectContext* context);
  29. static void GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided);
  30. static void GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible);
  31. GridComponentController() = default;
  32. GridComponentController(const GridComponentConfig& config);
  33. void Activate(EntityId entityId);
  34. void Deactivate();
  35. void SetConfiguration(const GridComponentConfig& config);
  36. const GridComponentConfig& GetConfiguration() const;
  37. static constexpr float MinGridSize = 0.0f;
  38. static constexpr float MaxGridSize = 1000000.0f;
  39. static constexpr float MinSpacing = 0.01f;
  40. private:
  41. AZ_DISABLE_COPY(GridComponentController);
  42. //! GridComponentRequestBus overrides...
  43. void SetSize(float size) override;
  44. float GetSize() const override;
  45. void SetPrimarySpacing(float spacing) override;
  46. float GetPrimarySpacing() const override;
  47. void SetSecondarySpacing(float spacing) override;
  48. float GetSecondarySpacing() const override;
  49. void SetAxisColor(const AZ::Color& color) override;
  50. AZ::Color GetAxisColor() const override;
  51. void SetPrimaryColor(const AZ::Color& color) override;
  52. AZ::Color GetPrimaryColor() const override;
  53. void SetSecondaryColor(const AZ::Color& color) override;
  54. AZ::Color GetSecondaryColor() const override;
  55. //! AZ::TransformNotificationBus::Handler overrides ...
  56. void OnTransformChanged(const Transform& local, const Transform& world) override;
  57. // AZ::RPI::SceneNotificationBus::Handler overrides ...
  58. void OnBeginPrepareRender() override;
  59. void BuildGrid();
  60. EntityId m_entityId;
  61. GridComponentConfig m_configuration;
  62. AZStd::vector<AZ::Vector3> m_axisGridPoints;
  63. AZStd::vector<AZ::Vector3> m_primaryGridPoints;
  64. AZStd::vector<AZ::Vector3> m_secondaryGridPoints;
  65. bool m_dirty = true; // must be set to true for any configuration change that rebuilds the grid
  66. };
  67. } // namespace Render
  68. } // namespace AZ