An OGRE scene node hierarchy is organized in a specific way. At the top of the hierarchy there is a root scene node (the ultimate ancestor), and beneath this there may be any number of scene nodes that in turn may contain more child nodes. Each scene node may also have attached to it any number of entities-meshes and other objects of the scene-that are to be included as part of the scene. The two objects responsible for creating and managing scenes in OGRE are SceneNode and Entity.
Let's illustrate the process of creating an example 3D scene that contains a single robot. The robot.mesh file is provided with the OGRE SDK and contains a sample mesh of a robot. It can be found in the media folder where OGRE was installed.
To load this mesh into a 3D scene, an Entity object needs to be created. This can be achieved by calling the createEntity method of the scene manager class. This class manages a scene, just like the ClanLib scene manager. Consider the following code, which is part of the createScene method of ExampleApplication. The createEntity method of the scene manager accepts a file name to a mesh file.
Entity *Entity = mSceneMgr->createEntity("Robot", "Robot.mesh");
A SceneNode can contain Entities, and attaching them to a SceneNode makes them part of a scene. To create a new SceneNode in the scene and then attach an Entity to this SceneNode, consider the following code:
SceneNode *Node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); Node->attachObject(Entity);
The code to create an Entity and SceneNode and then to make the Entity part of the scene follows.
class SampleApp : public ExampleApplication { public: // Basic constructor SampleApp() {} AppListener *m_AppListener; protected: // Just override the mandatory create scene method void createScene(void) { SceneNode *Node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); Entity *Entity = mSceneMgr->createEntity("Robot", "Robot.mesh"); Node->attachObject(Entity); } };