<title>Tutorial 15: Loading Scenes from .irr Files</title>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<!-- Wanted to avoid copying .css to each folder, so copied default .css from doxyen in here, kicked out most stuff we don't need for examples and modified some a little bit.
Target was having a single html in each example folder which is created from the main.cpp files and needs no files besides some images below media folder.
<p>Since version 1.1, Irrlicht is able to save and load the full scene graph into an .irr file, an xml based format. There is an editor available to edit those files, named irrEdit (<ahref="http://www.ambiera.com/irredit">http://www.ambiera.com/irredit</a>) which can also be used as world and particle editor. This tutorial shows how to use .irr files.</p>
<p>Lets start: Create an Irrlicht device and setup the window. </p><divclass="fragment"><divclass="line"><spanclass="preprocessor">#include <irrlicht.h></span></div><divclass="line"><spanclass="preprocessor">#include "driverChoice.h"</span></div><divclass="line"></div><divclass="line"><spanclass="keyword">using namespace </span>irr;</div><divclass="line"></div><divclass="line"><spanclass="preprocessor">#ifdef _MSC_VER</span></div><divclass="line"><spanclass="preprocessor">#pragma comment(lib, "Irrlicht.lib")</span></div><divclass="line"><spanclass="preprocessor">#endif</span></div><divclass="line"></div><divclass="line"><spanclass="keywordtype">int</span> main(<spanclass="keywordtype">int</span> argc, <spanclass="keywordtype">char</span>** argv)</div><divclass="line">{</div><divclass="line"><spanclass="comment">// ask user for driver</span></div><divclass="line"> video::E_DRIVER_TYPE driverType=driverChoiceConsole();</div><divclass="line"><spanclass="keywordflow">if</span> (driverType==video::EDT_COUNT)</div><divclass="line"><spanclass="keywordflow">return</span> 1;</div><divclass="line"></div><divclass="line"><spanclass="comment">// create device and exit if creation failed</span></div><divclass="line"></div><divclass="line"> IrrlichtDevice* device =</div><divclass="line"> createDevice(driverType, core::dimension2d<u32>(640, 480));</div><divclass="line"></div><divclass="line"><spanclass="keywordflow">if</span> (device == 0)</div><divclass="line"><spanclass="keywordflow">return</span> 1; <spanclass="comment">// could not create selected driver.</span></div><divclass="line"></div><divclass="line"> device->setWindowCaption(L<spanclass="stringliteral">"Load .irr file example"</span>);</div><divclass="line"></div><divclass="line"> video::IVideoDriver* driver = device->getVideoDriver();</div><divclass="line"> scene::ISceneManager* smgr = device->getSceneManager();</div></div><!-- fragment --><p> Now load our .irr file. .irr files can store the whole scene graph including animators, materials and particle systems. And there is also the possibility to store arbitrary user data for every scene node in that file. To keep this example simple, we are simply loading the scene here. See the documentation at ISceneManager::loadScene and ISceneManager::saveScene for more information. So to load and display a complicated huge scene, we only need a single call to loadScene(). </p><divclass="fragment"><divclass="line"><spanclass="comment">// load the scene</span></div><divclass="line"><spanclass="keywordflow">if</span> (argc>1)</div><divclass="line"> smgr->loadScene(argv[1]);</div><divclass="line"><spanclass="keywordflow">else</span></div><divclass="line"> smgr->loadScene(<spanclass="stringliteral">"../../media/example.irr"</span>);</div></div><!-- fragment --><p> Now we'll create a camera, and give it a collision response animator that's built from the mesh nodes in the scene we just loaded. </p><divclass="fragment"><divclass="line">scene::ICameraSceneNode * camera = smgr->addCameraSceneNodeFPS(0, 50.f, 0.1f);</div><divclass="line"></div><divclass="line"><spanclass="comment">// Create a meta triangle selector to hold several triangle selectors.</span></div><divclass="line">scene::IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector();</div></div><!-- fragment --><p> Now we will find all the nodes in the scene and create triangle selectors for all suitable nodes. Typically, you would want to make a more informed decision about which nodes to performs collision checks on; you could capture that information in the node name or Id. </p><divclass="fragment"><divclass="line">core::array<scene::ISceneNode *> nodes;</div><divclass="line">smgr->getSceneNodesFromType(scene::ESNT_ANY, nodes); <spanclass="comment">// Find all nodes</span></div><divclass="line"></div><divclass="line"><spanclass="keywordflow">for</span> (u32 i=0;