LandscapeCanvasSystemComponent.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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 <AzCore/RTTI/BehaviorContext.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include <AzCore/Serialization/EditContextConstants.inl>
  12. #include <AzToolsFramework/ActionManager/Action/ActionManagerInterface.h>
  13. #include <AzToolsFramework/API/ViewPaneOptions.h>
  14. #include <LyViewPaneNames.h>
  15. // LmbrCentral
  16. #include <LmbrCentral/Shape/BoxShapeComponentBus.h>
  17. #include <LmbrCentral/Shape/CapsuleShapeComponentBus.h>
  18. #include <LmbrCentral/Shape/CompoundShapeComponentBus.h>
  19. #include <LmbrCentral/Shape/CylinderShapeComponentBus.h>
  20. #include <LmbrCentral/Shape/DiskShapeComponentBus.h>
  21. #include <LmbrCentral/Shape/PolygonPrismShapeComponentBus.h>
  22. #include <LmbrCentral/Shape/ReferenceShapeComponentBus.h>
  23. #include <LmbrCentral/Shape/SphereShapeComponentBus.h>
  24. #include <LmbrCentral/Shape/TubeShapeComponentBus.h>
  25. // Gradient Signal
  26. #include <GradientSignal/Editor/EditorGradientTypeIds.h>
  27. // Graph Model
  28. #include <GraphModel/Integration/NodePalette/StandardNodePaletteItem.h>
  29. // Landscape Canvas
  30. #include "LandscapeCanvasSystemComponent.h"
  31. #include <Editor/MainWindow.h>
  32. #include <Editor/Core/GraphContext.h>
  33. #include <Editor/Nodes/Areas/AreaBlenderNode.h>
  34. #include <Editor/Nodes/Areas/BlockerAreaNode.h>
  35. #include <Editor/Nodes/Areas/MeshBlockerAreaNode.h>
  36. #include <Editor/Nodes/Areas/SpawnerAreaNode.h>
  37. #include <Editor/Nodes/AreaFilters/AltitudeFilterNode.h>
  38. #include <Editor/Nodes/AreaFilters/DistanceBetweenFilterNode.h>
  39. #include <Editor/Nodes/AreaFilters/DistributionFilterNode.h>
  40. #include <Editor/Nodes/AreaFilters/ShapeIntersectionFilterNode.h>
  41. #include <Editor/Nodes/AreaFilters/SlopeFilterNode.h>
  42. #include <Editor/Nodes/AreaFilters/SurfaceMaskDepthFilterNode.h>
  43. #include <Editor/Nodes/AreaFilters/SurfaceMaskFilterNode.h>
  44. #include <Editor/Nodes/AreaModifiers/PositionModifierNode.h>
  45. #include <Editor/Nodes/AreaModifiers/RotationModifierNode.h>
  46. #include <Editor/Nodes/AreaModifiers/ScaleModifierNode.h>
  47. #include <Editor/Nodes/AreaModifiers/SlopeAlignmentModifierNode.h>
  48. #include <Editor/Nodes/AreaSelectors/AssetWeightSelectorNode.h>
  49. #include <Editor/Nodes/Gradients/AltitudeGradientNode.h>
  50. #include <Editor/Nodes/Gradients/ConstantGradientNode.h>
  51. #include <Editor/Nodes/Gradients/FastNoiseGradientNode.h>
  52. #include <Editor/Nodes/Gradients/GradientBakerNode.h>
  53. #include <Editor/Nodes/Gradients/ImageGradientNode.h>
  54. #include <Editor/Nodes/Gradients/PerlinNoiseGradientNode.h>
  55. #include <Editor/Nodes/Gradients/RandomNoiseGradientNode.h>
  56. #include <Editor/Nodes/Gradients/ShapeAreaFalloffGradientNode.h>
  57. #include <Editor/Nodes/Gradients/SlopeGradientNode.h>
  58. #include <Editor/Nodes/Gradients/SurfaceMaskGradientNode.h>
  59. #include <Editor/Nodes/GradientModifiers/DitherGradientModifierNode.h>
  60. #include <Editor/Nodes/GradientModifiers/GradientMixerNode.h>
  61. #include <Editor/Nodes/GradientModifiers/InvertGradientModifierNode.h>
  62. #include <Editor/Nodes/GradientModifiers/LevelsGradientModifierNode.h>
  63. #include <Editor/Nodes/GradientModifiers/PosterizeGradientModifierNode.h>
  64. #include <Editor/Nodes/GradientModifiers/SmoothStepGradientModifierNode.h>
  65. #include <Editor/Nodes/GradientModifiers/ThresholdGradientModifierNode.h>
  66. #include <Editor/Nodes/Shapes/AxisAlignedBoxShapeNode.h>
  67. #include <Editor/Nodes/Shapes/BoxShapeNode.h>
  68. #include <Editor/Nodes/Shapes/CapsuleShapeNode.h>
  69. #include <Editor/Nodes/Shapes/CompoundShapeNode.h>
  70. #include <Editor/Nodes/Shapes/CylinderShapeNode.h>
  71. #include <Editor/Nodes/Shapes/DiskShapeNode.h>
  72. #include <Editor/Nodes/Shapes/PolygonPrismShapeNode.h>
  73. #include <Editor/Nodes/Shapes/ReferenceShapeNode.h>
  74. #include <Editor/Nodes/Shapes/SphereShapeNode.h>
  75. #include <Editor/Nodes/Shapes/TubeShapeNode.h>
  76. #include <Editor/Nodes/Terrain/PhysXHeightfieldColliderNode.h>
  77. #include <Editor/Nodes/Terrain/TerrainHeightGradientListNode.h>
  78. #include <Editor/Nodes/Terrain/TerrainLayerSpawnerNode.h>
  79. #include <Editor/Nodes/Terrain/TerrainMacroMaterialNode.h>
  80. #include <Editor/Nodes/Terrain/TerrainPhysicsHeightfieldColliderNode.h>
  81. #include <Editor/Nodes/Terrain/TerrainSurfaceGradientListNode.h>
  82. #include <Editor/Nodes/Terrain/TerrainSurfaceMaterialsListNode.h>
  83. namespace LandscapeCanvas
  84. {
  85. namespace Internal
  86. {
  87. // The FastNoise gem is optional, so we need to keep track of its component type ID
  88. // ourselves since we can't rely on the headers being there.
  89. static constexpr AZ::TypeId EditorFastNoiseGradientComponentTypeId{ "{FD018DE5-5EB4-4219-9D0C-CB3C55DE656B}" };
  90. // The Terrain gem is optional, so we need to keep track of the component type IDs
  91. // ourselves since we can't rely on the headers being there.
  92. namespace Terrain
  93. {
  94. static constexpr AZ::TypeId EditorPhysXHeightfieldColliderComponentTypeId{ "{C388C3DB-8D2E-4D26-96D3-198EDC799B77}" };
  95. static constexpr AZ::TypeId EditorTerrainHeightGradientListComponentTypeId{ "{2D945B90-ADAB-4F9A-A113-39E714708068}" };
  96. static constexpr AZ::TypeId EditorTerrainLayerSpawnerComponentTypeId{ "{9403FC94-FA38-4387-BEFD-A728C7D850C1}" };
  97. static constexpr AZ::TypeId EditorTerrainMacroMaterialComponentTypeId{ "{24D87D5F-6845-4F1F-81DC-05B4CEBA3EF4}" };
  98. static constexpr AZ::TypeId EditorTerrainPhysicsHeightfieldColliderComponentTypeId{ "{C43FAB8F-3968-46A6-920E-E84AEDED3DF5}" };
  99. static constexpr AZ::TypeId EditorTerrainSurfaceGradientListComponentTypeId{ "{49831E91-A11F-4EFF-A824-6D85C284B934}" };
  100. static constexpr AZ::TypeId EditorTerrainSurfaceMaterialsListComponentTypeId{ "{335CDED5-2E76-4342-8675-A60F66C471BF}" };
  101. }
  102. // The Vegetation gem is optional, so we need to keep track of the component type IDs
  103. // ourselves since we can't rely on the headers being there.
  104. namespace Vegetation
  105. {
  106. static constexpr AZ::TypeId EditorAreaBlenderComponentTypeId{ "{374A5C69-A252-4C4B-AE10-A673EF7AFE82}" };
  107. static constexpr AZ::TypeId EditorBlockerComponentTypeId{ "{9E765835-9CEB-4AEC-A913-787D3D21451D}" };
  108. static constexpr AZ::TypeId EditorMeshBlockerComponentTypeId{ "{130F5DFF-EF6F-4B37-8717-194876DE12DB}" };
  109. static constexpr AZ::TypeId EditorSpawnerComponentTypeId{ "{DD96FD51-A86B-48BC-A6AB-89183B538269}" };
  110. static constexpr AZ::TypeId EditorDistanceBetweenFilterComponentTypeId{ "{78DE1245-7023-40D6-B365-CC45EB4CE622}" };
  111. static constexpr AZ::TypeId EditorDistributionFilterComponentTypeId{ "{8EDD1DA2-B597-4BCE-9285-C68886504EC7}" };
  112. static constexpr AZ::TypeId EditorShapeIntersectionFilterComponentTypeId{ "{8BCE1190-6681-4C27-834A-AFFC8FBBDCD1}" };
  113. static constexpr AZ::TypeId EditorSurfaceAltitudeFilterComponentTypeId{ "{CD722D14-9C3B-4F89-B695-65B584279EB3}" };
  114. static constexpr AZ::TypeId EditorSurfaceMaskDepthFilterComponentTypeId{ "{A5441713-89DF-49C1-BA4E-3429FF23B43F}" };
  115. static constexpr AZ::TypeId EditorSurfaceMaskFilterComponentTypeId{ "{D2F223B4-60BE-4AC5-A1AA-260B91119918}" };
  116. static constexpr AZ::TypeId EditorSurfaceSlopeFilterComponentTypeId{ "{5130DA4B-6586-4249-9B86-6496EB2B1A78}" };
  117. static constexpr AZ::TypeId EditorPositionModifierComponentTypeId{ "{E1A2D544-B54A-437F-A40D-1FA5C5999D1C}" };
  118. static constexpr AZ::TypeId EditorRotationModifierComponentTypeId{ "{6E4B91BC-DAD7-4630-A78C-261D96EEA979}" };
  119. static constexpr AZ::TypeId EditorScaleModifierComponentTypeId{ "{D2391F8A-BB54-463E-9691-9290A802C6DE}" };
  120. static constexpr AZ::TypeId EditorSlopeAlignmentModifierComponentTypeId{ "{B0C62968-562B-4A8C-9969-E2AAB5379F66}" };
  121. static constexpr AZ::TypeId EditorDescriptorWeightSelectorComponentTypeId{ "{0FB90550-149B-4E05-B22C-2753F6526E97}" };
  122. }
  123. }
  124. // Define all of our supported nodes with their corresponding Component TypeId
  125. // so we can use these mappings for registration and factory method creation
  126. #define LANDSCAPE_CANVAS_NODE_TABLE(VISITOR_FUNCTION, ...) \
  127. /* Area nodes */ \
  128. VISITOR_FUNCTION<AreaBlenderNode>(Internal::Vegetation::EditorAreaBlenderComponentTypeId, ##__VA_ARGS__); \
  129. VISITOR_FUNCTION<BlockerAreaNode>(Internal::Vegetation::EditorBlockerComponentTypeId, ##__VA_ARGS__); \
  130. VISITOR_FUNCTION<MeshBlockerAreaNode>(Internal::Vegetation::EditorMeshBlockerComponentTypeId, ##__VA_ARGS__); \
  131. VISITOR_FUNCTION<SpawnerAreaNode>(Internal::Vegetation::EditorSpawnerComponentTypeId, ##__VA_ARGS__); \
  132. /* Area filter nodes */ \
  133. VISITOR_FUNCTION<AltitudeFilterNode>(Internal::Vegetation::EditorSurfaceAltitudeFilterComponentTypeId, ##__VA_ARGS__); \
  134. VISITOR_FUNCTION<DistanceBetweenFilterNode>(Internal::Vegetation::EditorDistanceBetweenFilterComponentTypeId, ##__VA_ARGS__); \
  135. VISITOR_FUNCTION<DistributionFilterNode>(Internal::Vegetation::EditorDistributionFilterComponentTypeId, ##__VA_ARGS__); \
  136. VISITOR_FUNCTION<ShapeIntersectionFilterNode>(Internal::Vegetation::EditorShapeIntersectionFilterComponentTypeId, ##__VA_ARGS__); \
  137. VISITOR_FUNCTION<SlopeFilterNode>(Internal::Vegetation::EditorSurfaceSlopeFilterComponentTypeId, ##__VA_ARGS__); \
  138. VISITOR_FUNCTION<SurfaceMaskDepthFilterNode>(Internal::Vegetation::EditorSurfaceMaskDepthFilterComponentTypeId, ##__VA_ARGS__); \
  139. VISITOR_FUNCTION<SurfaceMaskFilterNode>(Internal::Vegetation::EditorSurfaceMaskFilterComponentTypeId, ##__VA_ARGS__); \
  140. /* Area modifier nodes */ \
  141. VISITOR_FUNCTION<PositionModifierNode>(Internal::Vegetation::EditorPositionModifierComponentTypeId, ##__VA_ARGS__); \
  142. VISITOR_FUNCTION<RotationModifierNode>(Internal::Vegetation::EditorRotationModifierComponentTypeId, ##__VA_ARGS__); \
  143. VISITOR_FUNCTION<ScaleModifierNode>(Internal::Vegetation::EditorScaleModifierComponentTypeId, ##__VA_ARGS__); \
  144. VISITOR_FUNCTION<SlopeAlignmentModifierNode>(Internal::Vegetation::EditorSlopeAlignmentModifierComponentTypeId, ##__VA_ARGS__); \
  145. /* Area selector nodes */ \
  146. VISITOR_FUNCTION<AssetWeightSelectorNode>(Internal::Vegetation::EditorDescriptorWeightSelectorComponentTypeId, ##__VA_ARGS__); \
  147. /* Shape nodes */ \
  148. VISITOR_FUNCTION<AxisAlignedBoxShapeNode>(LmbrCentral::EditorAxisAlignedBoxShapeComponentTypeId, ##__VA_ARGS__); \
  149. VISITOR_FUNCTION<BoxShapeNode>(LmbrCentral::EditorBoxShapeComponentTypeId, ##__VA_ARGS__); \
  150. VISITOR_FUNCTION<CapsuleShapeNode>(LmbrCentral::EditorCapsuleShapeComponentTypeId, ##__VA_ARGS__); \
  151. VISITOR_FUNCTION<CompoundShapeNode>(LmbrCentral::EditorCompoundShapeComponentTypeId, ##__VA_ARGS__); \
  152. VISITOR_FUNCTION<CylinderShapeNode>(LmbrCentral::EditorCylinderShapeComponentTypeId, ##__VA_ARGS__); \
  153. VISITOR_FUNCTION<DiskShapeNode>(LmbrCentral::EditorDiskShapeComponentTypeId, ##__VA_ARGS__); \
  154. VISITOR_FUNCTION<PolygonPrismShapeNode>(LmbrCentral::EditorPolygonPrismShapeComponentTypeId, ##__VA_ARGS__); \
  155. VISITOR_FUNCTION<ReferenceShapeNode>(LmbrCentral::EditorReferenceShapeComponentTypeId, ##__VA_ARGS__); \
  156. VISITOR_FUNCTION<SphereShapeNode>(LmbrCentral::EditorSphereShapeComponentTypeId, ##__VA_ARGS__); \
  157. VISITOR_FUNCTION<TubeShapeNode>(LmbrCentral::EditorTubeShapeComponentTypeId, ##__VA_ARGS__); \
  158. /* Terrain nodes */ \
  159. VISITOR_FUNCTION<PhysXHeightfieldColliderNode>(Internal::Terrain::EditorPhysXHeightfieldColliderComponentTypeId, ##__VA_ARGS__); \
  160. VISITOR_FUNCTION<TerrainHeightGradientListNode>(Internal::Terrain::EditorTerrainHeightGradientListComponentTypeId, ##__VA_ARGS__); \
  161. VISITOR_FUNCTION<TerrainLayerSpawnerNode>(Internal::Terrain::EditorTerrainLayerSpawnerComponentTypeId, ##__VA_ARGS__); \
  162. VISITOR_FUNCTION<TerrainMacroMaterialNode>(Internal::Terrain::EditorTerrainMacroMaterialComponentTypeId, ##__VA_ARGS__); \
  163. VISITOR_FUNCTION<TerrainPhysicsHeightfieldColliderNode>(Internal::Terrain::EditorTerrainPhysicsHeightfieldColliderComponentTypeId, ##__VA_ARGS__); \
  164. VISITOR_FUNCTION<TerrainSurfaceGradientListNode>(Internal::Terrain::EditorTerrainSurfaceGradientListComponentTypeId, ##__VA_ARGS__); \
  165. VISITOR_FUNCTION<TerrainSurfaceMaterialsListNode>(Internal::Terrain::EditorTerrainSurfaceMaterialsListComponentTypeId, ##__VA_ARGS__); \
  166. /* Gradient generator nodes */ \
  167. VISITOR_FUNCTION<FastNoiseGradientNode>(Internal::EditorFastNoiseGradientComponentTypeId, ##__VA_ARGS__); \
  168. VISITOR_FUNCTION<PerlinNoiseGradientNode>(GradientSignal::EditorPerlinGradientComponentTypeId, ##__VA_ARGS__); \
  169. VISITOR_FUNCTION<RandomNoiseGradientNode>(GradientSignal::EditorRandomGradientComponentTypeId, ##__VA_ARGS__); \
  170. /* Gradient nodes */ \
  171. VISITOR_FUNCTION<AltitudeGradientNode>(GradientSignal::EditorSurfaceAltitudeGradientComponentTypeId, ##__VA_ARGS__); \
  172. VISITOR_FUNCTION<ConstantGradientNode>(GradientSignal::EditorConstantGradientComponentTypeId, ##__VA_ARGS__); \
  173. VISITOR_FUNCTION<GradientBakerNode>(GradientSignal::EditorGradientBakerComponentTypeId, ##__VA_ARGS__); \
  174. VISITOR_FUNCTION<ImageGradientNode>(GradientSignal::EditorImageGradientComponentTypeId, ##__VA_ARGS__); \
  175. VISITOR_FUNCTION<ShapeAreaFalloffGradientNode>(GradientSignal::EditorShapeAreaFalloffGradientComponentTypeId, ##__VA_ARGS__); \
  176. VISITOR_FUNCTION<SlopeGradientNode>(GradientSignal::EditorSurfaceSlopeGradientComponentTypeId, ##__VA_ARGS__); \
  177. VISITOR_FUNCTION<SurfaceMaskGradientNode>(GradientSignal::EditorSurfaceMaskGradientComponentTypeId, ##__VA_ARGS__); \
  178. /* Gradient modifier nodes */ \
  179. VISITOR_FUNCTION<DitherGradientModifierNode>(GradientSignal::EditorDitherGradientComponentTypeId, ##__VA_ARGS__); \
  180. VISITOR_FUNCTION<GradientMixerNode>(GradientSignal::EditorMixedGradientComponentTypeId, ##__VA_ARGS__); \
  181. VISITOR_FUNCTION<InvertGradientModifierNode>(GradientSignal::EditorInvertGradientComponentTypeId, ##__VA_ARGS__); \
  182. VISITOR_FUNCTION<LevelsGradientModifierNode>(GradientSignal::EditorLevelsGradientComponentTypeId, ##__VA_ARGS__); \
  183. VISITOR_FUNCTION<PosterizeGradientModifierNode>(GradientSignal::EditorPosterizeGradientComponentTypeId, ##__VA_ARGS__); \
  184. VISITOR_FUNCTION<SmoothStepGradientModifierNode>(GradientSignal::EditorSmoothStepGradientComponentTypeId, ##__VA_ARGS__); \
  185. VISITOR_FUNCTION<ThresholdGradientModifierNode>(GradientSignal::EditorThresholdGradientComponentTypeId, ##__VA_ARGS__); \
  186. template<typename NodeType>
  187. void RegisterNode([[maybe_unused]] const AZ::TypeId& typeId, AZ::ReflectContext* context)
  188. {
  189. GraphModelIntegration::ReflectAndCreateNodeMimeEvent<NodeType>(context);
  190. }
  191. void LandscapeCanvasSystemComponent::NotifyRegisterViews()
  192. {
  193. AzToolsFramework::ViewPaneOptions options;
  194. options.paneRect = QRect(100, 100, 1280, 1024);
  195. options.showOnToolsToolbar = true;
  196. options.toolbarIcon = ":/Menu/landscape_canvas_editor.svg";
  197. AzToolsFramework::RegisterViewPane<LandscapeCanvasEditor::MainWindow>(LyViewPane::LandscapeCanvas, LyViewPane::CategoryTools, options);
  198. }
  199. LandscapeCanvasSystemComponent::LandscapeCanvasSystemComponent()
  200. {
  201. LandscapeCanvas::GraphContext::SetInstance(AZStd::make_shared<LandscapeCanvas::GraphContext>());
  202. // Register factory methods for creating for all supported nodes
  203. LANDSCAPE_CANVAS_NODE_TABLE(RegisterFactoryMethod);
  204. AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler::BusConnect();
  205. }
  206. LandscapeCanvasSystemComponent::~LandscapeCanvasSystemComponent()
  207. {
  208. AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler::BusDisconnect();
  209. LandscapeCanvas::GraphContext::SetInstance(nullptr);
  210. AzToolsFramework::CloseViewPane(LyViewPane::LandscapeCanvas);
  211. AzToolsFramework::UnregisterViewPane(LyViewPane::LandscapeCanvas);
  212. }
  213. void LandscapeCanvasSystemComponent::OnActionContextRegistrationHook()
  214. {
  215. static constexpr AZStd::string_view LandscapeCanvasActionContextIdentifier = "o3de.context.editor.landscapecanvas";
  216. if (auto actionManagerInterface = AZ::Interface<AzToolsFramework::ActionManagerInterface>::Get())
  217. {
  218. AzToolsFramework::ActionContextProperties contextProperties;
  219. contextProperties.m_name = "O3DE Landscape Canvas";
  220. // Register a custom action context to allow duplicated shortcut hotkeys to work
  221. actionManagerInterface->RegisterActionContext(LandscapeCanvasActionContextIdentifier, contextProperties);
  222. }
  223. }
  224. void LandscapeCanvasSystemComponent::Reflect(AZ::ReflectContext* context)
  225. {
  226. // Reflect all our base node types so they can be serialized/deserialized, since
  227. // the below LANDSCAPE_CANVAS_NODE_TABLE macro only reflects the actual concrete classes
  228. BaseNode::Reflect(context);
  229. BaseAreaFilterNode::Reflect(context);
  230. BaseAreaModifierNode::Reflect(context);
  231. BaseAreaNode::Reflect(context);
  232. BaseGradientModifierNode::Reflect(context);
  233. BaseGradientNode::Reflect(context);
  234. BaseShapeNode::Reflect(context);
  235. // Reflect and create the node mime events for all our supported nodes
  236. LANDSCAPE_CANVAS_NODE_TABLE(RegisterNode, context);
  237. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  238. {
  239. serialize->Class<LandscapeCanvasSystemComponent, AZ::Component>()
  240. ->Version(0)
  241. ;
  242. if (AZ::EditContext* ec = serialize->GetEditContext())
  243. {
  244. ec->Class<LandscapeCanvasSystemComponent>("LandscapeCanvas", "Graph canvas representation of Dynamic Vegetation")
  245. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  246. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  247. ;
  248. }
  249. }
  250. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  251. {
  252. behaviorContext->ConstantProperty("LANDSCAPE_CANVAS_EDITOR_ID", []() { return LANDSCAPE_CANVAS_EDITOR_ID; })
  253. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
  254. behaviorContext->EBus<LandscapeCanvasNodeFactoryRequestBus>("LandscapeCanvasNodeFactoryRequestBus")
  255. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  256. ->Attribute(AZ::Script::Attributes::Category, "Editor")
  257. ->Attribute(AZ::Script::Attributes::Module, "landscapecanvas")
  258. ->Event("CreateNodeForTypeName", &LandscapeCanvasNodeFactoryRequests::CreateNodeForTypeName)
  259. ;
  260. behaviorContext->EBus<LandscapeCanvasRequestBus>("LandscapeCanvasRequestBus")
  261. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  262. ->Attribute(AZ::Script::Attributes::Category, "Editor")
  263. ->Attribute(AZ::Script::Attributes::Module, "landscapecanvas")
  264. ->Event("OnGraphEntity", &LandscapeCanvasRequests::OnGraphEntity)
  265. ->Event("GetNodeMatchingEntityInGraph", &LandscapeCanvasRequests::GetNodeMatchingEntityInGraph)
  266. ->Event("GetNodeMatchingEntityComponentInGraph", &LandscapeCanvasRequests::GetNodeMatchingEntityComponentInGraph)
  267. ->Event("GetAllNodesMatchingEntity", &LandscapeCanvasRequests::GetAllNodesMatchingEntity)
  268. ->Event("GetAllNodesMatchingEntityComponent", &LandscapeCanvasRequests::GetAllNodesMatchingEntityComponent)
  269. ;
  270. }
  271. }
  272. #undef LANDSCAPE_CANVAS_NODE_TABLE
  273. void LandscapeCanvasSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  274. {
  275. provided.push_back(AZ_CRC_CE("LandscapeCanvasService"));
  276. }
  277. void LandscapeCanvasSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  278. {
  279. incompatible.push_back(AZ_CRC_CE("LandscapeCanvasService"));
  280. }
  281. void LandscapeCanvasSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  282. {
  283. AZ_UNUSED(required);
  284. }
  285. void LandscapeCanvasSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  286. {
  287. AZ_UNUSED(dependent);
  288. }
  289. void LandscapeCanvasSystemComponent::Init()
  290. {
  291. AZ::ComponentApplicationBus::BroadcastResult(m_serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
  292. }
  293. void LandscapeCanvasSystemComponent::Activate()
  294. {
  295. AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
  296. LandscapeCanvasNodeFactoryRequestBus::Handler::BusConnect();
  297. LandscapeCanvasSerializationRequestBus::Handler::BusConnect();
  298. }
  299. void LandscapeCanvasSystemComponent::Deactivate()
  300. {
  301. LandscapeCanvasSerializationRequestBus::Handler::BusDisconnect();
  302. LandscapeCanvasNodeFactoryRequestBus::Handler::BusDisconnect();
  303. AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
  304. }
  305. BaseNode::BaseNodePtr LandscapeCanvasSystemComponent::CreateNodeForType(GraphModel::GraphPtr graph, const AZ::TypeId& typeId)
  306. {
  307. auto it = m_nodeFactory.find(typeId);
  308. if (it == m_nodeFactory.end())
  309. {
  310. return nullptr;
  311. }
  312. return it->second(graph);
  313. }
  314. GraphModel::NodePtr LandscapeCanvasSystemComponent::CreateNodeForTypeName(GraphModel::GraphPtr graph, AZStd::string_view nodeName)
  315. {
  316. AZ::TypeId nodeTypeId = AZ::TypeId::CreateNull();
  317. // Search through all registered Nodes to find the TypeId for one that
  318. // matches the requested class name.
  319. m_serializeContext->EnumerateDerived<GraphModel::Node>(
  320. [&nodeTypeId, nodeName](const AZ::SerializeContext::ClassData* componentClass, const AZ::Uuid& knownType) -> bool
  321. {
  322. AZ_UNUSED(knownType);
  323. if (componentClass->m_name == nodeName)
  324. {
  325. nodeTypeId = componentClass->m_typeId;
  326. return false;
  327. }
  328. return true;
  329. });
  330. if (!nodeTypeId.IsNull())
  331. {
  332. AZ::TypeId componentTypeId = GetComponentTypeId(nodeTypeId);
  333. return CreateNodeForType(graph, componentTypeId);
  334. }
  335. return nullptr;
  336. }
  337. const AZ::TypeId LandscapeCanvasSystemComponent::GetComponentTypeId(const AZ::TypeId& nodeTypeId)
  338. {
  339. auto it = m_nodeComponentTypeIds.find(nodeTypeId);
  340. if (it == m_nodeComponentTypeIds.end())
  341. {
  342. return AZ::TypeId();
  343. }
  344. return it->second.first;
  345. }
  346. int LandscapeCanvasSystemComponent::GetNodeRegisteredIndex(const AZ::TypeId& nodeTypeId) const
  347. {
  348. auto it = m_nodeComponentTypeIds.find(nodeTypeId);
  349. if (it == m_nodeComponentTypeIds.end())
  350. {
  351. return -1;
  352. }
  353. return it->second.second;
  354. }
  355. const LandscapeCanvasSerialization& LandscapeCanvasSystemComponent::GetSerializedMappings()
  356. {
  357. return m_serialization;
  358. }
  359. void LandscapeCanvasSystemComponent::SetDeserializedEntities(const AZStd::unordered_map<AZ::EntityId, AZ::EntityId>& entities)
  360. {
  361. m_serialization.m_deserializedEntities = entities;
  362. }
  363. }