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.
Post Reply
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm

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

Post by OGREHEAD » Sun Feb 14, 2016 8:23 pm

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?
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3747
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 130
Contact:

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

Post by dark_sylinc » Sun Feb 14, 2016 8:51 pm

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()
0 x

OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm

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

Post by OGREHEAD » Fri Feb 26, 2016 8:56 pm

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?
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3747
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 130
Contact:

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

Post by dark_sylinc » Fri Feb 26, 2016 9:32 pm

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.
0 x

User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2702
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 1

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

Post by syedhs » Sat Feb 27, 2016 5:18 pm

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;
}
0 x
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

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

Post by OGREHEAD » Tue Mar 08, 2016 4:34 pm

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?
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3747
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 130
Contact:

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

Post by dark_sylinc » Tue Mar 08, 2016 4:50 pm

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.
0 x

OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm

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

Post by OGREHEAD » Sat Mar 12, 2016 7:36 pm

Thanks for clearing this up.
0 x

Post Reply