Graph manipulation¶
What is the project’s “graph”?¶
The project’s graph
represents
all nodes of your project.
// Create an instance of InstantTerra
InstantTerra instantTerra = new InstantTerra();
// Get the current graph
Graph graph = instantTerra.GetProject().GetGraph();
Retrieving the number of nodes in the graph¶
// Returns the numbers of nodes in the graph
int numberOfNodes = graph.GetNodeCount();
Console.WriteLine(number_of_nodes);
See GetNodeCount()
in the documentation.
Retrieving all nodes in the graph¶
// Returns the list of nodes in the graph
List<Node> listOfNodes = graph.GetAllNodes();
The GetAllNodes()
method
lists the nodes
of the graph.
Tip
More information about the nodes is found in the section Accessing node data.
Adding a node on the graph¶
// Add a node in the graph
Node newNode = graph.AddNode(ApiNodeType.PerlinNoise, 10, 10);
The AddNode(ApiNodeType, int, int)
method creates
a node on the graph at the specified location, and returns the new node.
Adding a node on the graph next to another one¶
// Add a node in the graph next to another one
Node newNode = graph.AddNodeNextTo(ApiNodeType.PerlinNoise, NodeLocation.Right, previousNode);
The AddNodeNextTo(ApiNodeType, NodeLocation, Node)
method
creates a node on the graph next to a specified node, and returns the new node.
Removing a node from the graph¶
// Remove a node from the graph
graph.RemoveNode(nodeToRemove);
The RemoveNode()
method
removes the node from the graph.
Adding a link wetween two nodes¶
// Get connectors
Connector startConnector = perlinNode.GetConnectors()[ConnectorMode.Output][0]; # Has only one output connector
Connector endConnector = applyCurveNode.GetConnectors()[ConnectorMode.Input][0]; # Has only one output connector
// Add a link between two nodes
Link link = graph.AddLink(perlinNode, startConnector, applyCurveNode, endConnector);
The AddLink(Node startNode, Connector startConnector, Node endNode, Connector endConnector)
method
creates a link between two nodes of the graph.
Adding a link between two nodes using the connector name¶
// Add a link between two nodes
Link link = graph.AddLinkUsingName(perlinNode, "output_terrain_1", applyCurveNode, "input_terrain_1");
The AddLinkUsingName(Node startNode, string startConnectorName, Node endNode, string endConnectorName)
method
creates a link between two nodes of the graph.
Removing a link¶
// Remove a link
graph.RemoveLink(perlin_link);
The RemoveLink(Link)
method removes the link.