TerrainMacroMaterialBus.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #include "TerrainMacroMaterialBus.h"
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/RTTI/BehaviorContext.h>
  11. namespace Terrain
  12. {
  13. // Create a handler that can be accessed from Python scripts to receive terrain change notifications.
  14. class TerrainMacroMaterialNotificationHandler final
  15. : public Terrain::TerrainMacroMaterialNotificationBus::Handler
  16. , public AZ::BehaviorEBusHandler
  17. {
  18. public:
  19. AZ_EBUS_BEHAVIOR_BINDER(
  20. TerrainMacroMaterialNotificationHandler,
  21. "{B0ED8B29-0E0D-4567-BEAF-C842C4DB2700}",
  22. AZ::SystemAllocator,
  23. OnTerrainMacroMaterialCreated,
  24. OnTerrainMacroMaterialChanged,
  25. OnTerrainMacroMaterialRegionChanged,
  26. OnTerrainMacroMaterialDestroyed);
  27. void OnTerrainMacroMaterialCreated(
  28. [[maybe_unused]] AZ::EntityId macroMaterialEntity,
  29. [[maybe_unused]] const Terrain::MacroMaterialData& macroMaterial) override
  30. {
  31. Call(FN_OnTerrainMacroMaterialCreated);
  32. }
  33. void OnTerrainMacroMaterialChanged(
  34. [[maybe_unused]] AZ::EntityId macroMaterialEntity,
  35. [[maybe_unused]] const Terrain::MacroMaterialData& macroMaterial) override
  36. {
  37. Call(FN_OnTerrainMacroMaterialChanged);
  38. }
  39. void OnTerrainMacroMaterialRegionChanged(
  40. [[maybe_unused]] AZ::EntityId macroMaterialEntity,
  41. [[maybe_unused]] const AZ::Aabb& oldRegion,
  42. [[maybe_unused]] const AZ::Aabb& newRegion) override
  43. {
  44. Call(FN_OnTerrainMacroMaterialRegionChanged);
  45. }
  46. void OnTerrainMacroMaterialDestroyed([[maybe_unused]] AZ::EntityId macroMaterialEntity) override
  47. {
  48. Call(FN_OnTerrainMacroMaterialDestroyed);
  49. }
  50. static void Reflect(AZ::ReflectContext* context)
  51. {
  52. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  53. {
  54. behaviorContext->EBus<Terrain::TerrainMacroMaterialNotificationBus>("TerrainMacroMaterialAutomationBus")
  55. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  56. ->Attribute(AZ::Script::Attributes::Module, "terrain")
  57. ->Handler<TerrainMacroMaterialNotificationHandler>();
  58. }
  59. }
  60. };
  61. void MacroMaterialData::Reflect(AZ::ReflectContext* context)
  62. {
  63. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  64. {
  65. behaviorContext->Class<MacroMaterialData>()
  66. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  67. ->Attribute(AZ::Script::Attributes::Category, "Terrain")
  68. ->Attribute(AZ::Script::Attributes::Module, "terrain")
  69. ->Property("EntityId", BehaviorValueProperty(&MacroMaterialData::m_entityId))
  70. ->Property("Bounds", BehaviorValueProperty(&MacroMaterialData::m_bounds))
  71. ->Property("NormalFlipX", BehaviorValueProperty(&MacroMaterialData::m_normalFlipX))
  72. ->Property("NormalFlipY", BehaviorValueProperty(&MacroMaterialData::m_normalFlipY))
  73. ->Property("NormalFactor", BehaviorValueProperty(&MacroMaterialData::m_normalFactor))
  74. ;
  75. }
  76. }
  77. void TerrainMacroMaterialRequests::Reflect(AZ::ReflectContext* context)
  78. {
  79. MacroMaterialData::Reflect(context);
  80. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  81. {
  82. behaviorContext->EBus<Terrain::TerrainMacroMaterialRequestBus>("TerrainMacroMaterialRequestBus")
  83. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  84. ->Attribute(AZ::Script::Attributes::Category, "Terrain")
  85. ->Attribute(AZ::Script::Attributes::Module, "terrain")
  86. ->Event("GetTerrainMacroMaterialData", &Terrain::TerrainMacroMaterialRequestBus::Events::GetTerrainMacroMaterialData)
  87. ;
  88. behaviorContext->EBus<Terrain::TerrainMacroMaterialNotificationBus>("TerrainMacroMaterialNotificationBus")
  89. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  90. ->Attribute(AZ::Script::Attributes::Category, "Terrain")
  91. ->Attribute(AZ::Script::Attributes::Module, "terrain")
  92. ->Event("OnTerrainMacroMaterialCreated", &Terrain::TerrainMacroMaterialNotifications::OnTerrainMacroMaterialCreated)
  93. ->Event("OnTerrainMacroMaterialChanged", &Terrain::TerrainMacroMaterialNotifications::OnTerrainMacroMaterialChanged)
  94. ->Event("OnTerrainMacroMaterialRegionChanged", &Terrain::TerrainMacroMaterialNotifications::OnTerrainMacroMaterialRegionChanged)
  95. ->Event("OnTerrainMacroMaterialDestroyed", &Terrain::TerrainMacroMaterialNotifications::OnTerrainMacroMaterialDestroyed)
  96. ;
  97. Terrain::TerrainMacroMaterialNotificationHandler::Reflect(context);
  98. }
  99. }
  100. } // namespace Terrain