Open 3D Engine GraphModel Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
GraphModel::Graph Class Reference

#include <Graph.h>

Inherits AZStd::enable_shared_from_this< Graph >.

Public Types

typedef AZStd::unordered_map< NodeId, NodePtr > NodeMap
 
typedef AZStd::unordered_map< NodeId, ConstNodePtr > ConstNodeMap
 
typedef AZStd::unordered_map< NodeId, AZStd::pair< NodeId, AZ::u32 > > NodeWrappingMap
 
typedef AZStd::vector< ConnectionPtr > ConnectionList
 

Public Member Functions

 AZ_CLASS_ALLOCATOR (Graph, AZ::SystemAllocator)
 
 AZ_RTTI (Graph, "{CBF5DC3C-A0A7-45F5-A207-06433A9A10C5}")
 
 Graph (const Graph &)=delete
 
 Graph (GraphContextPtr graphContext)
 
void PostLoadSetup (GraphContextPtr graphContext)
 
NodeId PostLoadSetup (NodePtr node)
 
GraphContextPtr GetContext () const
 Returns the interface to client system specific data and functionality.
 
const char * GetSystemName () const
 
NodeId AddNode (NodePtr node)
 Adds a Node to the graph and gives it a unique ID.
 
bool RemoveNode (ConstNodePtr node)
 Removes a Node and all connections between it and other Nodes in the graph.
 
void WrapNode (NodePtr wrapperNode, NodePtr node, AZ::u32 layoutOrder=DefaultWrappedNodeLayoutOrder)
 
void UnwrapNode (ConstNodePtr node)
 Remove the wrapping from the specified node.
 
bool IsNodeWrapped (NodePtr node) const
 Return if the specified node is a wrapped node.
 
const NodeWrappingMap & GetNodeWrappings ()
 Return our full map of node wrappings.
 
NodePtr GetNode (NodeId nodeId)
 Search for a note with the corresponding ID.
 
const NodeMap & GetNodes ()
 Return a map of all nodes in the graph.
 
ConstNodeMap GetNodes () const
 Return a map of all nodes in the graph.
 
size_t GetNodeCount () const
 Return the number of nodes in the graph.
 
ConnectionPtr AddConnection (SlotPtr sourceSlot, SlotPtr targetSlot)
 
bool RemoveConnection (ConstConnectionPtr connection)
 Removes a connection from the Graph, and returns whether it was found and removed.
 
const ConnectionList & GetConnections ()
 Return a container of all connections in the graph.
 
size_t GetConnectionCount () const
 Return the number of connections for all nodes and slots in the graph.
 
void SetUiMetadata (const GraphModelIntegration::GraphCanvasMetadata &uiMetadata)
 
const GraphModelIntegration::GraphCanvasMetadataGetUiMetadata () const
 
GraphModelIntegration::GraphCanvasMetadataGetUiMetadata ()
 
AZStd::shared_ptr< SlotFindSlot (const Endpoint &endpoint)
 
void ClearCachedData ()
 Reset any data that was cached for this graph.
 
bool Contains (SlotPtr slot) const
 
ConnectionPtr FindConnection (ConstSlotPtr sourceSlot, ConstSlotPtr targetSlot)
 

Static Public Member Functions

static void Reflect (AZ::ReflectContext *context)
 

Detailed Description

This is the main class for the GraphModel framework. It provides a generic node graph data model that is originally intended for use with Graph Canvas providing the UI, but in theory it could be used with any node graph widget system. It is also designed with primarily editor processing in mind, rather than runtime processing, so if this were to be used at runtime we may need some improvements.

Data Model Goals

  • Keep it simple (For example, avoid using the component entity system even though that's an established pattern in Script Canvas's data model)
  • It shouldn't know anything about GraphCanvas or any other UI representation; it's purely a data model
  • Make it suitible for multiple contexts (For example, even though this is built for Shader Canvas initially, it should be generic enough to use for the Particle Editor or other contexts)
  • It shouldn't know anything about how the nodes will be used. (For example, any functionality specific to Shader Canvas, Particle Editors, or any other context should be added to some external subclasses of GraphModel classes)

Key elements of a Graph include

  • Node - The main building block of a Graph. Contains multiple input slots and output slots.
  • Slot - Every node contains input slots and/or output slots that can be connected together
  • Endpoint - A specific Slot on a specific Node; basically a {NodeID,SlotID} pair
  • Connection - A link from an output Endpoint to an input Endpoint (we could also say this is a link from an output Slot to an input Slot)
  • Metadata - Every graph can contain generic metadata like comments and node groupings for example. But this is specific to the node graph UI system, and the Graph class just stores this in an abstract way to bundle the data together.

For continued reading, see Node.h next.

Constructor & Destructor Documentation

◆ Graph()

GraphModel::Graph::Graph ( GraphContextPtr  graphContext)
explicit

Constructor

Parameters
graphContextinterface to client system specific data and functionality

Member Function Documentation

◆ AddConnection()

ConnectionPtr GraphModel::Graph::AddConnection ( SlotPtr  sourceSlot,
SlotPtr  targetSlot 
)

Adds a new connection between sourceSlot and targetSlot and returns the new Connection, or returns the existing Connection if one already exists.

◆ GetSystemName()

const char * GraphModel::Graph::GetSystemName ( ) const

This name is used for debug messages in GraphModel classes, to provide appropriate context for the user. It's a convenience function for GetContext()->GetSystemName()

◆ PostLoadSetup() [1/2]

void GraphModel::Graph::PostLoadSetup ( GraphContextPtr  graphContext)

Initializion after the Graph has been serialized in. This must be called after building a Graph from serialized data in order to connect internal pointers between elements of the Graph and perform any other precedural setup that isn't stored in the serialized data.

Parameters
graphContextinterface to client system specific data and functionality

◆ PostLoadSetup() [2/2]

NodeId GraphModel::Graph::PostLoadSetup ( NodePtr  node)

Add a node that has been deserialized to the graph This should only be necessary for cases like copy/paste where we need to load a deserialized node, but don't actually know the nodeId before-hand

◆ SetUiMetadata()

void GraphModel::Graph::SetUiMetadata ( const GraphModelIntegration::GraphCanvasMetadata uiMetadata)

Set/gets a bundle of generic metadata that is provided by the node graph UI system. This may include node positions, comment blocks, node groupings, and bookmarks, for example.

◆ WrapNode()

void GraphModel::Graph::WrapNode ( NodePtr  wrapperNode,
NodePtr  node,
AZ::u32  layoutOrder = DefaultWrappedNodeLayoutOrder 
)

Wrap (embed) the node onto the specified wrapperNode The wrapperNode and node must already exist in the graph before being wrapped


The documentation for this class was generated from the following file: