BaseNode.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/ComponentBus.h>
  11. #include <AzCore/Component/EntityId.h>
  12. #include <AzCore/std/smart_ptr/shared_ptr.h>
  13. #include <GraphModel/Model/Node.h>
  14. namespace AZ
  15. {
  16. class Component;
  17. class ReflectContext;
  18. }
  19. namespace LandscapeCanvas
  20. {
  21. /**
  22. * Base Node class that all our LandscapeCanvas nodes must derive from for
  23. * tracking the associated vegetation Entity that holds the node, and other
  24. * common functionality
  25. */
  26. class BaseNode : public GraphModel::Node
  27. {
  28. public:
  29. AZ_CLASS_ALLOCATOR(BaseNode, AZ::SystemAllocator);
  30. AZ_RTTI(BaseNode, "{94ECF2FF-C46C-4CCA-878C-5C47B943B6B7}", Node);
  31. using BaseNodePtr = AZStd::shared_ptr<BaseNode>;
  32. enum BaseNodeType
  33. {
  34. Invalid = -1,
  35. Shape,
  36. VegetationArea,
  37. Gradient,
  38. GradientGenerator,
  39. GradientModifier,
  40. TerrainArea,
  41. TerrainExtender,
  42. TerrainSurfaceExtender,
  43. VegetationAreaModifier,
  44. VegetationAreaFilter,
  45. VegetationAreaSelector
  46. };
  47. static void Reflect(AZ::ReflectContext* context);
  48. BaseNode() = default;
  49. explicit BaseNode(GraphModel::GraphPtr graph);
  50. virtual const BaseNodeType GetBaseNodeType() const { return Invalid; }
  51. const AZ::EntityId& GetVegetationEntityId() const { return m_vegetationEntityId; }
  52. void SetVegetationEntityId(const AZ::EntityId& entityId);
  53. /// Refresh the name in the entity name property slot
  54. void RefreshEntityName();
  55. const AZ::ComponentId& GetComponentId() const { return m_componentId; }
  56. void SetComponentId(const AZ::ComponentId& componentId);
  57. virtual AZ::ComponentDescriptor::DependencyArrayType GetOptionalRequiredServices() const;
  58. /// Retrieve a pointer to the Component on the respective Entity that
  59. /// this Node represents
  60. AZ::Component* GetComponent() const;
  61. /// Returns whether or not this node is a Vegetation Area Extender (Filter/Modifier/Selector)
  62. bool IsAreaExtender() const;
  63. /// Override the PostLoadSetup calls to ensure the entity name is refreshed correctly.
  64. void PostLoadSetup(GraphModel::GraphPtr graph, GraphModel::NodeId id) override;
  65. void PostLoadSetup() override;
  66. protected:
  67. /// Create the property slot on our node to show the Entity name
  68. void CreateEntityNameSlot();
  69. /// EntityId of the Vegetation Entity that holds this node
  70. AZ::EntityId m_vegetationEntityId;
  71. AZ::ComponentId m_componentId = AZ::InvalidComponentId;
  72. };
  73. }