Code: Select all
#include <irrlicht.h>
//some defines...
#define NODEEXPLORERWINDOW 1 //for further identification processes, if needed.
#define NODEEXPLORERTREEVIEW 2
//function declarations, this could go inside a header file...
void fillTreeViewNode(gui::IGUITreeViewNode* treeNode,scene::ISceneNode* rootNode);
void updateNodeExplorer(gui::IGUITreeView* treeExplorer,scene::ISceneManager* smgr);
void fillTreeViewNode(gui::IGUITreeViewNode* rootTreeNode,scene::ISceneNode* rootNode);
using namespace irr;
//These routines create a window such that it includes a treeView of the whole structure of the scene,
//and would allow to pick each scene node individually through an event. Its dimensions are optional...
void makeNodeExplorer(scene::ISceneManager* smgr,gui::IGUIEnvironment* env){
gui::IGUIWindow* nodeExplorer = env->addWindow(core::recti(610,10,930,640),L"Node Explorer",0,NODEEXPLORERWINDOW);
gui::IGUITreeView* treeExplorer;
treeExplorer = gui_Mod->addTreeView(core::recti(10,20,300,600),nodeExplorer,NODEEXPLORERTREEVIEW);
updateNodeExplorer(treeExplorer,smgr);
}
//Updates the whole tree. Useful if the tree must be updated, or initialized...
void updateNodeExplorer(gui::IGUITreeView* treeExplorer,scene::ISceneManager* smgr)
{
if(treeExplorer){
treeExplorer->getRoot()->clearChildren();
fillTreeViewNode(treeExplorer->getRoot(),smgr->getRootNode());
}
}
//Recursive function that fills a node of the treeView with the corresponding information, and makes the same
//for all the children of the give scene node...
void fillTreeViewNode(gui::IGUITreeViewNode* rootTreeNode,scene::ISceneNode* rootNode)
{
core::stringw name;
gui::IGUITreeViewNode* node;
core::list< scene::ISceneNode* >::Iterator IT;
core::list< scene::ISceneNode* > children;
//More cases can be added as needed. This is not a comprehensive nor closed list...
if(rootNode){
switch(rootNode->getType())
{
case scene::ESNT_ANIMATED_MESH:
name = L"Animated mesh";
break;
case scene::ESNT_SKY_DOME:
name = L"Sky Dome";
break;
case scene::ESNT_EMPTY:
name = L"Empty node";
break;
case scene::ESNT_MESH:
name = L"Static mesh";
break;
case scene::ESNT_LIGHT:
name = L"Light";
break;
case scene::ESNT_CAMERA:
name = L"Camera";
break;
case scene::ESNT_OCTREE:
name = L"Octree mesh";
break;
case scene::ESNT_TERRAIN:
name = L"Terrain mesh";
break;
case scene::ESNT_DUMMY_TRANSFORMATION:
name = L"Dummy Transformation";
break;
default:
name = L"Unknown node";
}
rootTreeNode->setData(rootNode);
//for each child of this scene node, reiterate. It is a nice exercise to get used to
//recursive tree traversing...
children = rootNode->getChildren();
IT = children.begin();
for(;IT!=children.end();++IT)
{
node = rootTreeNode->addChildBack(L"Node");
fillTreeViewNode(node,*IT);
}
}
}