Skip to content

Graphics engine

Julien Pires edited this page Nov 8, 2013 · 4 revisions

HomeModules overview ▸ Graphics engine

Introduction

The graphics module provides all necessary to display 3D environnements.

How it works

All functionalities can be accessed via the GraphicsEngine class. GraphicsEngine provides window management, scene graph and anything else necessary to build 3D worlds.

A scene graph is a tree structure composed of child node and each node can have child node too. SceneTree is the base class for all scene graph. The graphics module have a Node base class and SceneNode which inherit from Node. The Node class provides common implementation of a node. SceneNode has specific implementation to be used in a scene graph.

It's easy to create a new scene:

SceneTree graph = graphicsEngine.CreateSceneGraph("myWorld");

The SceneTree class has a Root node. You can create new child from this node:

SceneNode rootNode = graph.Root;
SceneNode childNode = rootNode.CreateChild("FirstChild");

To display a 3D model you have to create an Entity and attached it to a scene node. One entity = one mesh, there is a 1:1 relationship. As a mesh is composed of multiple sub-mesh, an entity is composed of multiple sub-entity each one attached to a sub-mesh. An entity has to be attached on a scene node to be rendered. You can create entity with the CreateEntity method of the scene graph:

Entity myCharacter = graph.CreateEntity("meshFilename", "entityName");
childNode.AttachObject(myCharacter);

Once you have created all your entity and set them up, the next thing to do is to create a Camera. Camera are managed with the CameraManager. Each scene graph has a CameraManager instance.

As we said, GraphicsEngine instance has a Window instance. A window is composed of one or more viewports and a viewport needs a camera instance in order to render something:

Viewport mainViewport = graphicsEngine.Window.CreateViewport(0);
Camera playerCamera = graph.CameraManager.CreateCamera("playerPointOfView");
mainViewport.Camera = playerCamera;

Now your scene will be displayed on the screen.