Feature Request: getSceneNodeFromName()

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
DrAnonymous
Posts: 34
Joined: Thu Aug 04, 2005 9:37 pm

Feature Request: getSceneNodeFromName()

Post by DrAnonymous »

The interface for scene manager has this method -

Code: Select all

ISceneNode* getSceneNodeFromId(s32 id, ISceneNode* start)
I am writing a FLT loader, which has sub groups/nodes. The nodes are named, so I want to be able to load the model and then be able to get a specific sub-node by name from the scene manager.

Could a method called

Code: Select all

getSceneNodeFromName(wchar_t* name, ISceneNode* start)
be added to the ISceneManager class?

Does anyone else think this would be useful for other model formats?

Cheers,
Dr. A>
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

Will be useful. I wrote similar function for my purposes:

Code: Select all

//!Returns the first scene node with the specified Name.
ISceneNode* getSceneNodeFromName(ISceneManager* smgr, ISceneNode* root, stringw  Name)
{
    ISceneNode* resultNode =0;

    if(root ==0)
        root = smgr->getRootSceneNode();

    const core::list<ISceneNode*>& children = root->getChildren();
    core::list<ISceneNode*>::Iterator it = children.begin();

    for (; it != children.end(); ++it)
    {
        ISceneNode* current = *(it);
        if(stringw(current->getName()) == Name)
        {
            resultNode = current;
            return resultNode;
        }

        // if any node has a children apply this function for children by recursion
        if(!current->getChildren().empty())
        {
            getSceneNodeFromName(smgr, current, Name);
        }

    }

 return resultNode;
}
You can use it, only difference is that you must ponit smgr like parameter.

Another function that will be usefull is

Code: Select all

//!Returns scene node with these ID and Name
ISceneNode* getSceneNodeFromNameAndId(ISceneManager* smgr, ISceneNode* root, stringw  Name, s32 id)
{
    ISceneNode* resultNode =0;

    if(root ==0)
        root = smgr->getRootSceneNode();

    const core::list<ISceneNode*>& children = root->getChildren();
    core::list<ISceneNode*>::Iterator it = children.begin();

    for (; it != children.end(); ++it)
    {
        ISceneNode* current = *(it);

        if(stringw(current->getName()) == Name && current->getID() == id)
        {
            resultNode = current;
            return resultNode;
        }

        // if any node has a children apply this function for children by recursion
        if(!current->getChildren().empty())
        {
            getSceneNodeFromNameAndId(smgr, current, Name, id);
        }

    }

 return resultNode;
}
Enjoy.
ImageImage
Site development -Rock and metal online
--- etcaptor.com ------freenetlife.com
DrAnonymous
Posts: 34
Joined: Thu Aug 04, 2005 9:37 pm

Post by DrAnonymous »

I think there is an error in your code. :? You aren't keeping track of the return from the recursive call.

You have this -

Code: Select all

//!Returns the first scene node with the specified Name.
        // if any node has a children apply this function for children by recursion
        if(!current->getChildren().empty())
        {
            getSceneNodeFromName(smgr, current, Name);
        }

    }

 return resultNode;
}

I believe it should look like this -

Code: Select all

//!Returns the first scene node with the specified Name.
        // if any node has a children apply this function for children by recursion
        if(!current->getChildren().empty())
        {
            resultNode = getSceneNodeFromName(smgr, current, Name);
            if(resultNode != 0)
                  return resultNode;
        }

    }

 return resultNode;
}
Thanks for the info! I hope this is put into the new version.

Cheers,
Dr. A>
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

DrAnonymous wrote:I think there is an error in your code. :? You aren't keeping track of the return from the recursive call.
I'm not full agree with this addition, because you will never get executing of this additional line after recursion.
After recussion you have a two return states:
- if name was found /rturns node/
- if name was not found /returns null/[/quote]
ImageImage
Site development -Rock and metal online
--- etcaptor.com ------freenetlife.com
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

GetSceneNodebyName(): Already on my list for several releases. Now that some people really need it, time to really add it. :)
Post Reply