Goal of this tutorial

This tutorial is about PADrend’s scene graph. You will learn to create a simple scene graph and register it to PADrend, so that it is displayed as active scene.

Creating a simple scene graph

Lets create a scene graph made of five nodes. This is only a structural example of a scene graph. To fill the graph with geometry, some cubes are created. It is not important to understand the mesh creation, since it will be the main topic of another tutorial.

//building nodes
var rootNode = new MinSG.ListNode();
var listNode = new MinSG.ListNode();

var mesh1 = Rendering.MeshBuilder.createBox(new Geometry.Box(-2, 0, 0, 1, 1, 1));
var mesh2 = Rendering.MeshBuilder.createBox(new Geometry.Box(2, 0, 0, 1, 1, 1));
var mesh3 = Rendering.MeshBuilder.createBox(new Geometry.Box(0, 0, -2, 1, 1, 1));

var geometryNode1 = new MinSG.GeometryNode(mesh1);
var geometryNode2 = new MinSG.GeometryNode(mesh2);
var geometryNode3 = new MinSG.GeometryNode(mesh3);

First we need to create the nodes themselves. This is simply done by instantiating objects. For our scene we need two objects of the class MinSG.ListNode and three of the class MinSG.GeometryNode. Next up we connect the nodes to a tree similar to the one in the image bellow.

Scene graph

The simplest way to attach a node to a list node is by using += operator. But you can also use the method addChild. The graph is created by adding listNode and one of the geometry nodes to the root node. Afterwards the two other geometry nodes are connected to the list node.

//Building the scene graph
rootNode.addChild(geometryNode1);
rootNode.addChild(listNode);

listNode += geometryNode2;
listNode += geometryNode3;

Giving the nodes an id

We can provide a name(identifier) for each node. This id’s will show up in the Node Editor and can help identifying specific nodes when the graph is traversed.

//giving nodes a unique id
PADrend.getSceneManager().registerNode("root", rootNode);
PADrend.getSceneManager().registerNode("some_list_node", listNode);

PADrend.getSceneManager().registerNode("geometry_node_1", geometryNode1);
PADrend.getSceneManager().registerNode("geometry_node_2", geometryNode2);
PADrend.getSceneManager().registerNode("geometry_node_3", geometryNode3);

You can give an id to a node by calling PADrend.getSceneManager().registerNode(ID, NODE).

Providing meta data

The last step of this tutorial is to register the scene graph to PADrend, which will treat it as a scene. Before we do that lets attach some meta data to the scene. This step is optional, however it can be important to provide this information (i.e. for license reasons). The meta data fields that can be set are:

  • Title: The title of the scene.
  • Creation Date: When was the scene created?
  • Author: Who created the scene?
  • License: The license the scene is shipped with. Possible values are “free”, “internal use” and “RESTRICTED”.
  • Note: Some information about the scene.

Before we can set the meta data we first need to load the module containing the necessary functions.

var NodeMetaInfo = Std.module('LibMinSGExt/NodeMetaInfo');

For setting the current date, we first need to fetch it.

var date = getDate();

For each field the class NodeMetaInfo contains a function to access it. Each of these functions returns a data wrapper that can be used to set or read the field. The node which should contain the meta data is passed as parameter. We want to attach the meta data to the root node of our scene (rootNode).

NodeMetaInfo.accessMetaInfo_CreationDate(rootNode)("" + date["year"] + "-"+ date["mon"] + "-" + date["mday"] );
NodeMetaInfo.accessMetaInfo_Title(rootNode)("Test Scene");
NodeMetaInfo.accessMetaInfo_Author(rootNode)("Max Mustermann");
NodeMetaInfo.accessMetaInfo_License(rootNode)("free");
NodeMetaInfo.accessMetaInfo_Note(rootNode)("Some info about the scene.");

Registering the scene to PADrend

Lets register the scene and tell PADrend to display it. Therefore PADrend offers the two functions registerScene and selectScene. We simply call first register and then select and pass the root node of our scene graph to them.

//Register the root node of the scene graph
PADrend.registerScene(rootNode);
//Selecting the root node to be the active scene
PADrend.selectScene(rootNode);

The scenes geometry will now be displayed. You can use PADrend’s Main-window to check the structure of the scene graph.

Main window showing the scenes structure