Page 1 of 1
How to get a scenenode or a camera i 2.x?
Posted: Sun Feb 14, 2016 8:23 pm
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?
Re: How to get a scenenode or a camera i 2.x?
Posted: Sun Feb 14, 2016 8:51 pm
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()
Re: How to get a scenenode or a camera i 2.x?
Posted: Fri Feb 26, 2016 8:56 pm
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?
Re: How to get a scenenode or a camera i 2.x?
Posted: Fri Feb 26, 2016 9:32 pm
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.
Re: How to get a scenenode or a camera i 2.x?
Posted: Sat Feb 27, 2016 5:18 pm
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;
}
Re: How to get a scenenode or a camera i 2.x?
Posted: Tue Mar 08, 2016 4:34 pm
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?
Re: How to get a scenenode or a camera i 2.x?
Posted: Tue Mar 08, 2016 4:50 pm
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.
Re: How to get a scenenode or a camera i 2.x?
Posted: Sat Mar 12, 2016 7:36 pm
by OGREHEAD
Thanks for clearing this up.