PositionModifierComponent.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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/PositionModifierRequestBus.h>
  13. #include <GradientSignal/GradientSampler.h>
  14. #include <LmbrCentral/Dependency/DependencyMonitor.h>
  15. #include <SurfaceData/SurfaceDataSystemRequestBus.h>
  16. namespace LmbrCentral
  17. {
  18. template<typename, typename>
  19. class EditorWrappedComponentBase;
  20. }
  21. namespace Vegetation
  22. {
  23. class PositionModifierConfig
  24. : public AZ::ComponentConfig
  25. {
  26. public:
  27. AZ_CLASS_ALLOCATOR(PositionModifierConfig, AZ::SystemAllocator);
  28. AZ_RTTI(PositionModifierConfig, "{B7A0A88D-4FDF-487F-A0E6-5BE04C82862A}", AZ::ComponentConfig);
  29. static void Reflect(AZ::ReflectContext* context);
  30. bool m_allowOverrides = false;
  31. bool m_autoSnapToSurface = true;
  32. SurfaceData::SurfaceTagVector m_surfaceTagsToSnapTo;
  33. float m_rangeMinX = -0.3f;
  34. float m_rangeMaxX = 0.3f;
  35. GradientSignal::GradientSampler m_gradientSamplerX;
  36. float m_rangeMinY = -0.3f;
  37. float m_rangeMaxY = 0.3f;
  38. GradientSignal::GradientSampler m_gradientSamplerY;
  39. float m_rangeMinZ = 0.0f;
  40. float m_rangeMaxZ = 0.0f;
  41. GradientSignal::GradientSampler m_gradientSamplerZ;
  42. size_t GetNumTags() const;
  43. AZ::Crc32 GetTag(int tagIndex) const;
  44. void RemoveTag(int tagIndex);
  45. void AddTag(AZStd::string tag);
  46. };
  47. inline constexpr AZ::TypeId PositionModifierComponentTypeId{ "{A5E84838-57D7-4F40-B011-73D9FD9AE33D}" };
  48. /**
  49. * Component implementing VegetationModifierRequestBus that offsets position
  50. */
  51. class PositionModifierComponent
  52. : public AZ::Component
  53. , public ModifierRequestBus::Handler
  54. , private PositionModifierRequestBus::Handler
  55. {
  56. public:
  57. template<typename, typename> friend class LmbrCentral::EditorWrappedComponentBase;
  58. AZ_COMPONENT(PositionModifierComponent, PositionModifierComponentTypeId);
  59. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  60. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  61. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  62. static void Reflect(AZ::ReflectContext* context);
  63. PositionModifierComponent(const PositionModifierConfig& configuration);
  64. PositionModifierComponent() = default;
  65. ~PositionModifierComponent() = default;
  66. //////////////////////////////////////////////////////////////////////////
  67. // AZ::Component interface implementation
  68. void Activate() override;
  69. void Deactivate() override;
  70. bool ReadInConfig(const AZ::ComponentConfig* baseConfig) override;
  71. bool WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const override;
  72. //////////////////////////////////////////////////////////////////////////
  73. // VegetationModifierRequestBus
  74. void Execute(InstanceData& instanceData) const override;
  75. ModifierStage GetModifierStage() const override;
  76. protected:
  77. //////////////////////////////////////////////////////////////////////////
  78. // PositionModifierRequestBus
  79. bool GetAllowOverrides() const override;
  80. void SetAllowOverrides(bool value) override;
  81. AZ::Vector3 GetRangeMin() const override;
  82. void SetRangeMin(AZ::Vector3 rangeMin) override;
  83. AZ::Vector3 GetRangeMax() const override;
  84. void SetRangeMax(AZ::Vector3 rangeMax) override;
  85. GradientSignal::GradientSampler& GetGradientSamplerX() override;
  86. GradientSignal::GradientSampler& GetGradientSamplerY() override;
  87. GradientSignal::GradientSampler& GetGradientSamplerZ() override;
  88. size_t GetNumTags() const override;
  89. AZ::Crc32 GetTag(int tagIndex) const override;
  90. void RemoveTag(int tagIndex) override;
  91. void AddTag(AZStd::string tag) override;
  92. private:
  93. PositionModifierConfig m_configuration;
  94. LmbrCentral::DependencyMonitor m_dependencyMonitor;
  95. //reserve for masks to re-snap to surface
  96. mutable SurfaceData::SurfaceTagVector m_surfaceTagsToSnapToCombined;
  97. //point vector reserved for reuse
  98. mutable SurfaceData::SurfacePointList m_points;
  99. };
  100. }