Scene node explorer

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Mel
Competition winner
Posts: 2293
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Scene node explorer

Post by Mel »

This is a small code i've done lately. It is creates a tree view with all the nodes of the scene, which could, for instance, allow to pick up nodes from this structure directly in a gui based application.

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);
                }
        }
}
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Scene node explorer

Post by christianclavet »

Thanks Mel!

Have you put in the examples how to retrieve the node when selected?
Mel
Competition winner
Posts: 2293
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Scene node explorer

Post by Mel »

No, and honestly, i think it would need more documentation, because it isn't as direct as it would look. I will post something tomorrow or so...
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Mel
Competition winner
Posts: 2293
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Scene node explorer

Post by Mel »

this event receiver is able to get the scene node chosen in the tree view :)

Code: Select all

 
//This event handler is able to pick up the scene nodes from the treeView explorer created before, 
 
class treeNodeReceiver : public IEventReceiver{
 
        gui::IGUITreeView* tree;
        gui::IGUITreeViewNode* treeNode;
 
public:
 
        scene::ISceneNode* selectedNode; //It is declared public so it can be accessed quickly from outside this class. This node should be tested outside, though,
                                         //so it doesn't contain null data.
 
        virtual bool OnEvent(const irr::SEvent& event)
        {
                switch(event.EventType){//if more types of events are to be handled they maybe handled in here.
                        case EET_GUI_EVENT:
                                tree = (gui::IGUITreeView*) event.GUIEvent.Caller;
                                if(tree){
                                        treeNode = tree->getSelected();
                                        if(treeNode){
                                                selectedNode = treeNode->getData();
                                        }
                                }
                        break;
                }
        }
};
 
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Scene node explorer

Post by christianclavet »

Cool! Thanks Mel. I will surely use that soon! Thanks!
Post Reply