RotationModifierComponent.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 <AzCore/Component/Component.h>
  10. #include <AzCore/Math/Vector3.h>
  11. #include <Vegetation/Ebuses/ModifierRequestBus.h>
  12. #include <Vegetation/Ebuses/RotationModifierRequestBus.h>
  13. #include <GradientSignal/GradientSampler.h>
  14. #include <LmbrCentral/Dependency/DependencyMonitor.h>
  15. namespace LmbrCentral
  16. {
  17. template<typename, typename>
  18. class EditorWrappedComponentBase;
  19. }
  20. namespace Vegetation
  21. {
  22. class RotationModifierConfig
  23. : public AZ::ComponentConfig
  24. {
  25. public:
  26. AZ_CLASS_ALLOCATOR(RotationModifierConfig, AZ::SystemAllocator);
  27. AZ_RTTI(RotationModifierConfig, "{FF8B1DED-C1A8-4322-86D2-C8432E4B0526}", AZ::ComponentConfig);
  28. static void Reflect(AZ::ReflectContext* context);
  29. bool m_allowOverrides = false;
  30. float m_rangeMinX = 0.0f;
  31. float m_rangeMaxX = 0.0f;
  32. GradientSignal::GradientSampler m_gradientSamplerX;
  33. float m_rangeMinY = 0.0f;
  34. float m_rangeMaxY = 0.0f;
  35. GradientSignal::GradientSampler m_gradientSamplerY;
  36. float m_rangeMinZ = -180.0f;
  37. float m_rangeMaxZ = 180.0f;
  38. GradientSignal::GradientSampler m_gradientSamplerZ;
  39. };
  40. inline constexpr AZ::TypeId RotationModifierComponentTypeId{ "{9C9158D1-6386-4375-8A3C-B9CA325246FB}" };
  41. /**
  42. * Component implementing VegetationModifierRequestBus that offsets rotation
  43. */
  44. class RotationModifierComponent
  45. : public AZ::Component
  46. , public ModifierRequestBus::Handler
  47. , private RotationModifierRequestBus::Handler
  48. {
  49. public:
  50. template<typename, typename> friend class LmbrCentral::EditorWrappedComponentBase;
  51. AZ_COMPONENT(RotationModifierComponent, RotationModifierComponentTypeId);
  52. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  53. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  54. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  55. static void Reflect(AZ::ReflectContext* context);
  56. RotationModifierComponent(const RotationModifierConfig& configuration);
  57. RotationModifierComponent() = default;
  58. ~RotationModifierComponent() = default;
  59. //////////////////////////////////////////////////////////////////////////
  60. // AZ::Component interface implementation
  61. void Activate() override;
  62. void Deactivate() override;
  63. bool ReadInConfig(const AZ::ComponentConfig* baseConfig) override;
  64. bool WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const override;
  65. //////////////////////////////////////////////////////////////////////////
  66. // VegetationModifierRequestBus
  67. void Execute(InstanceData& instanceData) const override;
  68. protected:
  69. //////////////////////////////////////////////////////////////////////////
  70. // RotationModifierRequestBus
  71. bool GetAllowOverrides() const override;
  72. void SetAllowOverrides(bool value) override;
  73. AZ::Vector3 GetRangeMin() const override;
  74. void SetRangeMin(AZ::Vector3 rangeMin) override;
  75. AZ::Vector3 GetRangeMax() const override;
  76. void SetRangeMax(AZ::Vector3 rangeMax) override;
  77. GradientSignal::GradientSampler& GetGradientSamplerX() override;
  78. GradientSignal::GradientSampler& GetGradientSamplerY() override;
  79. GradientSignal::GradientSampler& GetGradientSamplerZ() override;
  80. private:
  81. RotationModifierConfig m_configuration;
  82. LmbrCentral::DependencyMonitor m_dependencyMonitor;
  83. };
  84. }