How to get a scenenode or a camera i 2.x?

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

How to get a scenenode or a camera i 2.x?

Post by OGREHEAD »

getScenode and getCamera can not be used with a name as parameter in ogre 2.x

So what should be done instead to get a certain scenenode or a camera?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5490
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1361

Re: How to get a scenenode or a camera i 2.x?

Post by dark_sylinc »

You should be caching their pointers instead of grabbing them by name. Starting since 2.0; names for nodes are not unique nor mandatory, so it's perfectly possible to have two nodes with the same name (unless you enforce uniqueness yourself). Cameras though, still needed a unique name for technical reasons.

For cameras you can use SceneManager::findCamera.
For nodes, you can search them via its unique ID using SceneManager::getSceneNode. But if you were able to retrieve the ID, this means you once had access to the pointer, which you should be caching the pointer instead.
If you have an Entity/Item and want to know its node its attached to, grab the SceneNode via MovableObject::getParentSceneNode()
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

Re: How to get a scenenode or a camera i 2.x?

Post by OGREHEAD »

Thanks for answering.

So like I assumed I have to throw pointers around myself, which is OK, but kind of nice just to be able to call scenemanager and find camera I think and it sounds like I can still do that if I just make sure I do not create any cameras with the same name.
Just wanted to know if I was suppose to do something else.

I know about getparentscenenode.

So for nodes I can do getscenenode("SOME_NAME") and I use setname for both cameras and scenenodes, but with setname I would be able to give two scenenodes the same name, wouldn't I?
Then how is it different from me not giving two cameras the same name, when it comes to scenenodes?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5490
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1361

Re: How to get a scenenode or a camera i 2.x?

Post by dark_sylinc »

OGREHEAD wrote:Then how is it different from me not giving two cameras the same name, when it comes to scenenodes?
We can literally have 100k of SceneNodes.
Most of the users didn't care about node names. However they were forced into creating dummy ones. This caused unnecessary string allocations for every Node created, and hindered threadability (because the unique of strings needs to be in sync in all threads). We also wasted several bytes per Node (and even kilobytes per node if the allocations were fragmented)

Additionally, we had to spend memory and CPU resources maintaining a map when then entities got created and destroyed. This is slow and causes a lot of bloat. And headaches for coders who don't care about the names.

Having named nodes is only useful for a couple of nodes, or for an Editor. In both cases, we don't prevent you from doing this as you can still name the nodes as a way to tag them. But keeping them in a lookup table (i.e. std::map) or ensuring they're unique is up to you.

Cameras on the other hand, are rarely created or destroyed, and are very few (i.e. less than 10). Thus this overhead is minimal. Furthermore core components such as the Compositor can reference cameras by name, in case you want to render something to from one camera's perspective, and then something else from another camera's perspective. Hence unique names on camera are very useful.

It's basically a cost-benefit analysis. Unique names on SceneNode provide little benefits and a lot of problems for a lot of people, while unique names on Cameras provide a lot of benefits and very few problems.
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Re: How to get a scenenode or a camera i 2.x?

Post by syedhs »

Why dont you create a wrapper yourself.. such as

Code: Select all

void Game::createSceneNode(const String& name, etc etc)
{
   mNode[name] = mSceneMgr->createSceneNode ...
}

SceneNode* Game::getSceneNode(const String& name)
{
  mNode.find(...)
  return node;
}
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

Re: How to get a scenenode or a camera i 2.x?

Post by OGREHEAD »

Makes sense....

I decided to throw references around between objects, similar to what was suggested.

Although I could not get getSceneNode to work, so just to understand this completely..
Previously it as possible to write getSceneNode("SceneNodeName"), but now getSceneNode takes Ogre::idtype as argument.
What is this idtype and how do I get a scenenode by name, apart from creating a map myself, if it is still possible at all?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5490
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1361

Re: How to get a scenenode or a camera i 2.x?

Post by dark_sylinc »

OGREHEAD wrote:Previously it as possible to write getSceneNode("SceneNodeName"), but now getSceneNode takes Ogre::idtype as argument. What is this idtype (...)?
You can get the id via sceneNode->getId(). That's what I meant by: "But if you were able to retrieve the ID, this means you once had access to the pointer, which you should be caching the pointer instead."
OGREHEAD wrote:...how do I get a scenenode by name, apart from creating a map myself, if it is still possible at all?
You can't. You have to do it yourself.
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

Re: How to get a scenenode or a camera i 2.x?

Post by OGREHEAD »

Thanks for clearing this up.