TerrainSurfaceDataSystemComponent.h 3.7 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 <AzCore/Component/Component.h>
  10. #include <AzCore/Component/Entity.h>
  11. #include <AzCore/EBus/EBus.h>
  12. #include <AzFramework/Terrain/TerrainDataRequestBus.h>
  13. #include <SurfaceData/SurfaceDataModifierRequestBus.h>
  14. #include <SurfaceData/SurfaceDataProviderRequestBus.h>
  15. #include <SurfaceData/SurfaceDataTagProviderRequestBus.h>
  16. namespace Terrain
  17. {
  18. class TerrainSurfaceDataSystemConfig
  19. : public AZ::ComponentConfig
  20. {
  21. public:
  22. AZ_CLASS_ALLOCATOR(TerrainSurfaceDataSystemConfig, AZ::SystemAllocator);
  23. AZ_RTTI(TerrainSurfaceDataSystemConfig, "{2B93F5E5-5346-47A1-9C4D-EFBC6BDF468F}", AZ::ComponentConfig);
  24. static void Reflect(AZ::ReflectContext* context);
  25. };
  26. /**
  27. * The system component to serve for the game side queries for surface values
  28. */
  29. class TerrainSurfaceDataSystemComponent
  30. : public AZ::Component
  31. , private SurfaceData::SurfaceDataProviderRequestBus::Handler
  32. , private AzFramework::Terrain::TerrainDataNotificationBus::Handler
  33. , private SurfaceData::SurfaceDataTagProviderRequestBus::Handler
  34. {
  35. friend class EditorTerrainSurfaceDataSystemComponent;
  36. TerrainSurfaceDataSystemComponent(const TerrainSurfaceDataSystemConfig&);
  37. public:
  38. TerrainSurfaceDataSystemComponent();
  39. //////////////////////////////////////////////////////////////////////////
  40. // Component static
  41. AZ_COMPONENT(TerrainSurfaceDataSystemComponent, "{0C821DA4-6DB1-4860-BE25-CB57B3E3F4D4}", AZ::Component);
  42. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  43. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  44. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  45. static void Reflect(AZ::ReflectContext* context);
  46. //////////////////////////////////////////////////////////////////////////
  47. // Component
  48. void Activate() override;
  49. void Deactivate() override;
  50. bool ReadInConfig(const AZ::ComponentConfig* baseConfig) override;
  51. bool WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const override;
  52. //////////////////////////////////////////////////////////////////////////
  53. // SurfaceDataProviderRequestBus
  54. void GetSurfacePoints(const AZ::Vector3& inPosition, SurfaceData::SurfacePointList& surfacePointList) const override;
  55. void GetSurfacePointsFromList(
  56. AZStd::span<const AZ::Vector3> inPositions, SurfaceData::SurfacePointList& surfacePointList) const override;
  57. //////////////////////////////////////////////////////////////////////////
  58. // AzFramework::Terrain::TerrainDataNotificationBus
  59. void OnTerrainDataChanged(const AZ::Aabb& dirtyRegion, TerrainDataChangedMask dataChangedMask) override;
  60. private:
  61. void UpdateTerrainData(const AZ::Aabb& dirtyRegion);
  62. AZ::Aabb GetSurfaceAabb() const;
  63. SurfaceData::SurfaceTagVector GetSurfaceTags() const;
  64. SurfaceData::SurfaceDataRegistryHandle m_providerHandle = SurfaceData::InvalidSurfaceDataRegistryHandle;
  65. TerrainSurfaceDataSystemConfig m_configuration;
  66. AZ::Aabb m_terrainBounds = AZ::Aabb::CreateNull();
  67. AZStd::atomic_bool m_terrainBoundsIsValid{ false };
  68. //////////////////////////////////////////////////////////////////////////
  69. // SurfaceData::SurfaceDataTagProviderRequestBus
  70. void GetRegisteredSurfaceTagNames(SurfaceData::SurfaceTagNameSet& names) const override;
  71. };
  72. }