EditorTerrainMacroMaterialComponent.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/Preprocessor/Enum.h>
  10. #include <AzFramework/PaintBrush/PaintBrushNotificationBus.h>
  11. #include <GradientSignal/Editor/PaintableImageAssetHelper.h>
  12. #include <TerrainRenderer/Components/TerrainMacroMaterialComponent.h>
  13. #include <TerrainRenderer/EditorComponents/EditorTerrainMacroMaterialComponentMode.h>
  14. #include <TerrainRenderer/TerrainMacroMaterialBus.h>
  15. #include <LmbrCentral/Dependency/DependencyNotificationBus.h>
  16. #include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
  17. #include <AzToolsFramework/ComponentMode/ComponentModeDelegate.h>
  18. #include <AzToolsFramework/Manipulators/PaintBrushManipulator.h>
  19. namespace Terrain
  20. {
  21. // Due to the EditorTerrainMacroMaterialComponent having a member where it passes itself as the type below
  22. // `PaintableImageAssetHelper<EditorTerrainMacroMaterialComponent, EditorTerrainMacroMaterialComponentMode>`
  23. // The AzTypeInfo can't be queried due to EditorImageGradientComponent still be defined
  24. // So define AzTypeInfo using a forward declaration
  25. // Then use the AZ_RTTI_NO_TYPE_INFO_DECL/AZ_RTTI_NO_TYPE_INFO_IMPL to add Rtti
  26. class EditorTerrainMacroMaterialComponent;
  27. AZ_TYPE_INFO_SPECIALIZE(EditorTerrainMacroMaterialComponent, "{24D87D5F-6845-4F1F-81DC-05B4CEBA3EF4}");
  28. class EditorTerrainMacroMaterialComponent
  29. : public AzToolsFramework::Components::EditorComponentBase
  30. , protected AzToolsFramework::EditorVisibilityNotificationBus::Handler
  31. , protected LmbrCentral::DependencyNotificationBus::Handler
  32. , protected AzFramework::PaintBrushNotificationBus::Handler
  33. , protected TerrainMacroMaterialNotificationBus::Handler
  34. {
  35. public:
  36. AZ_EDITOR_COMPONENT_INTRUSIVE_DESCRIPTOR_TYPE(EditorTerrainMacroMaterialComponent);
  37. AZ_COMPONENT_BASE(EditorTerrainMacroMaterialComponent);
  38. AZ_CLASS_ALLOCATOR(EditorTerrainMacroMaterialComponent, AZ::ComponentAllocator);
  39. AZ_RTTI_NO_TYPE_INFO_DECL();
  40. static void Reflect(AZ::ReflectContext* context);
  41. static constexpr const char* const s_categoryName = "Terrain";
  42. static constexpr const char* const s_componentName = "Terrain Macro Material";
  43. static constexpr const char* const s_componentDescription = "Provides a macro material for a region to the terrain renderer";
  44. static constexpr const char* const s_icon = "Editor/Icons/Components/TerrainMacroMaterial.svg";
  45. static constexpr const char* const s_viewportIcon = "Editor/Icons/Components/Viewport/TerrainMacroMaterial.svg";
  46. static constexpr const char* const s_helpUrl = "";
  47. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  48. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  49. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  50. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  51. //! Component overrides ...
  52. void Init() override;
  53. void Activate() override;
  54. void Deactivate() override;
  55. void BuildGameEntity(AZ::Entity* gameEntity) override;
  56. // AzToolsFramework::EditorVisibilityNotificationBus overrides ...
  57. void OnEntityVisibilityChanged(bool visibility) override;
  58. // DependencyNotificationBus overrides ...
  59. void OnCompositionChanged() override;
  60. void OnCompositionRegionChanged(const AZ::Aabb& dirtyRegion) override;
  61. protected:
  62. // TerrainMacroMaterialNotificationBus overrides ...
  63. void OnTerrainMacroMaterialCreated(AZ::EntityId macroMaterialEntity, const MacroMaterialData& macroMaterial) override;
  64. void OnTerrainMacroMaterialChanged(AZ::EntityId macroMaterialEntity, const MacroMaterialData& macroMaterial) override;
  65. void OnTerrainMacroMaterialDestroyed(AZ::EntityId macroMaterialEntity) override;
  66. bool SavePaintedData();
  67. // PaintBrushNotificationBus overrides
  68. void OnPaintModeBegin() override;
  69. void OnPaintModeEnd() override;
  70. void OnBrushStrokeBegin(const AZ::Color& color) override;
  71. void OnBrushStrokeEnd() override;
  72. void OnPaint(const AZ::Color& color, const AZ::Aabb& dirtyArea, ValueLookupFn& valueLookupFn, BlendFn& blendFn) override;
  73. void OnSmooth(
  74. const AZ::Color& color,
  75. const AZ::Aabb& dirtyArea,
  76. ValueLookupFn& valueLookupFn,
  77. AZStd::span<const AZ::Vector3> valuePointOffsets,
  78. SmoothFn& smoothFn) override;
  79. AZ::Color OnGetColor(const AZ::Vector3& brushCenter) const override;
  80. AZStd::vector<uint8_t> ConvertLinearToSrgbGamma(AZStd::span<const uint32_t> pixelBuffer) const;
  81. void RefreshPaintableAssetStatus();
  82. AZ::u32 ConfigurationChanged();
  83. private:
  84. GradientSignal::ImageCreatorUtils::
  85. PaintableImageAssetHelper<EditorTerrainMacroMaterialComponent, EditorTerrainMacroMaterialComponentMode>
  86. m_paintableMacroColorAssetHelper;
  87. //! Copies of the runtime component and configuration - we use these to run the full runtime logic in the Editor.
  88. TerrainMacroMaterialComponent m_component;
  89. TerrainMacroMaterialConfig m_configuration;
  90. bool m_visible = true;
  91. bool m_runtimeComponentActive = false;
  92. };
  93. } // namespace Terrain