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.