Gentle Introduction to OmniGraph

Welcome to the very first tutorial of OmniGraph!

In this tutorial, we will give a very gentle introduction to OmniGraph by doing something very simple.

Before we can do anything with OmniGraph, we must make sure the appropriate extensions have been loaded. Please open the extension manager:

../../_images/ext_omnigraph_gentle_intro_01.png

Make sure at least the omni.graph.bundle.action extension bundle is loaded. It’s a good idea to turn on auto-load as well, so we’ll only need to do it once.

../../_images/ext_omnigraph_gentle_intro_02.png

Note: If you are unable to find the omni.graph.bundle.action extension bundle, try removing any filters that you may have applied.

Preparing your Scene

Currently, the scene is completely empty. Let’s start by adding a cube and a cone to the scene.

Right click on the scene. In the popup menu, click on Create -> Shape -> Cube. This will create a cube prim at the position of the cursor.

../../_images/ext_omnigraph_gentle_intro_03.png

Similarly, right click and then click on Create -> Shape -> Cone to create a cone prim.

Alternatively, one can also use the top menu bar to add prims to the scene. For example, clicking on Create -> Shape -> Cone in the top menu bar will also create a cone prim.

../../_images/ext_omnigraph_gentle_intro_04.png

Setting Up the Graph

Now that we have this very simple scene set up, let’s set up the graph.

Bring up the specialized graph editor UI by clicking on Window -> Visual Scripting -> Action Graph.

../../_images/ext_omnigraph_gentle_intro_05.png

In the graph editor UI, click on New Action Graph.

../../_images/ext_omnigraph_gentle_intro_06.png

The UI will ask for the path of the graph. We can leave it at its default value, and just click OK.

This will create an empty action graph at the default path, and the graph editor UI should automatically show the newly created graph.

Note

You might be wondering what an action graph is. We will dive deeper into this topic in the next few tutorials. For now, it suffices to understand the following: OmniGraph supports multiple different types of graphs, and each type of graph handles node evaluation in a different manner. For example, an action graph is a type of graph that performs node evaluation upon receipt of an event.

Adding Nodes to the Graph

Now that we have an empty graph, let’s add some nodes to the graph!

Since this is the very first tutorial, we will do something very simple: We will add nodes to the graph, so that whenever we move the cube, the cone moves along with it. See the following GIF for an example.

../../_images/ext_omnigraph_gentle_intro_07.gif

On a high level, what we want to do is: We want to read the position of the cube, add some fixed constant to it, and use that as the position of the cone.

Step 1: Create a Read Prim Attribute node to read the position of the cube

This can be done by dragging and dropping the cube from the Stage window to the graph editor like so:

../../_images/ext_omnigraph_gentle_intro_08.png

In the popup dialog, select Read Attribute. This creates a Read Prim Attribute node, which can read information from the cube prim that we dragged in.

But we haven’t specified what piece of information do we want it to read.

Left click on the new node in the graph editor. In the Property window on the right, set Attribute Name to xformOp:translate.

This tells the node to read the xformOp:translate attribute of the cube prim, which is the position of the cube.

../../_images/ext_omnigraph_gentle_intro_09.png

Step 2: Create an Add node and a Constant Vec3d node to add a fixed constant to the position

In the search box on the left, type “Add” to search for the Add node.

Drag and drop the Add node to the graph editor like so:

../../_images/ext_omnigraph_gentle_intro_10.png

Similarly, search for “Constant Vec3d” in the search box, and drag and drop the Constant Vec3d node to the graph editor.

Now we need to specify what constant value the Constant Vec3d node is holding.

Left click on the Constant Vec3d node in the graph editor. In the Property window on the right, set the Y value to 120.0, and leave X and Z at 0.0.

../../_images/ext_omnigraph_gentle_intro_11.png

With this, the Constant Vec3d node will hold the constant 3-tuple (0.0, 120.0, 0.0).

Finally, we still need to wire up the three nodes.

Connect the Constant Vec3d node to the First Addend of the Add node, by dragging from one port to the other. Similarly, connect the Read Prim Attribute node to the Second Addend of the Add node.

../../_images/ext_omnigraph_gentle_intro_12.png

Step 3: Create a Write Prim Attribute node to set the position of the cone

The process will be very similar to how we created the Read Prim Attribute node.

Drag and drop the cone from the Stage window to the graph editor like so:

../../_images/ext_omnigraph_gentle_intro_13.png

In the popup dialog, select Write Attribute. This creates a Write Prim Attribute node, which can write information to the cone prim that we dragged in.

Left click on the new node in the graph editor. In the Property window on the right, set Attribute Name to xformOp:translate.

This tells the node to write to the xformOp:translate attribute of the cone prim, which is the position of the cone.

Finally, connect the Add node to the Write Prim Attribute node like so:

../../_images/ext_omnigraph_gentle_intro_14.png

With this, our graph will read the position of the cube, add (0.0, 120.0, 0.0) to it, and set it to be the position of the cone.

However, we are not done yet. We still need to tell the graph when to perform node evaluation, when to read the position, calculate the sum and set the position.

For this purpose, we need an On Tick node.

Step 4: Create an On Tick node

Just like before, we search for “On Tick” in the search box on the left, and drag and drop the On Tick node to the graph editor.

../../_images/ext_omnigraph_gentle_intro_15.png

Finally, connect the On Tick node to the Exec In of the Write Prim Attribute node.

../../_images/ext_omnigraph_gentle_intro_16.png

Note

You might be wondering what exactly does the On Tick node do. In short, it fires an execution signal through its Tick execution pin every single frame. Because of this, anything connected to its Tick execution pin (the Write Prim Attribute node) will be evaluated every single frame. This makes sure that the position of the cone is updated in every frame, using the latest position of the cube. We will discuss this topic in more detail in the next few tutorials.

Woohoo! Our graph is completed!

Go back to the scene. Click on the Play button on the far left side.

../../_images/ext_omnigraph_gentle_intro_17.png

Now try dragging the cube around. You should see the cone stick to the top of the cube and move along with the cube.

../../_images/ext_omnigraph_gentle_intro_07.gif