Creating entities across scene managers

Problems building or running the engine, queries about how to use features etc.
Post Reply
Nucleartree
Kobold
Posts: 28
Joined: Tue Apr 04, 2017 9:10 pm
Location: Cardiff, UK
x 16

Creating entities across scene managers

Post by Nucleartree »

Hi everyone.

I've spent the last little while trying to make a map editor using ogre and wx widgets. It's been going well so far but I've run into a bit of a snag.

The system I have at the moment is that the user can go file > new map and this will create a new map within a 'notebook' (basically a tabbed window) so that they can work on multiple maps at the same time. Each map is just an ogre window that is attached to a wxGLCanvas. Each map has it's own scene manager because I expect the maps might end up getting pretty big.

I've set up a function that runs during the first draw of the canvas that populates the scene with entities. It looks like this:

Code: Select all

sceneManager = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC);

camera = sceneManager->createCamera("Camera");
camera->setPosition(0, 0, 80);
camera->lookAt(0, 0, -300);
camera->setNearClipDistance(5);

viewport = canvas->getWindow()->addViewport(camera);

viewport->setBackgroundColour(Ogre::ColourValue(0, 0, 0));
canvas->setViewportSize();

Ogre::Entity *ogreEntity;
ogreEntity = sceneManager->createEntity("ogreEntity", "ogrehead.mesh");
Ogre::SceneNode* ogreNode = sceneManager->getRootSceneNode()->createChildSceneNode();
ogreNode->attachObject(ogreEntity);

sceneManager->setAmbientLight(Ogre::ColourValue(.5, .5, .5));

Ogre::Light* light = sceneManager->createLight("light");
light->setPosition(20, 80, 50);
It's pretty much boiler-plate code and shows the ogre head correctly in the canvas. The problem is that if I create another map and thus another canvas, I don't get anything. I just get black. I tried fiddling around with it and found that if I did something like:

Code: Select all

if(id == 0)ogreEntity = sceneManager->createEntity("ogreEntity", "ogrehead.mesh");
else ogreEntity = sceneManager->createEntity("ogreEntity", "someOtherMesh.mesh");
I would get something. Each canvas has an id so the first canvas would be 0. The someOtherMesh.mesh would appear on the second canvas created, but then if I made a third I would again get nothing. Given how each canvas runs the same code each time it starts I find it strange how it sometimes doesn't do anything.

So my question is more about how the resource manager works than anything. I know that ogre attempts to only load meshes once but surely this doesn't mean that they are bound to one scene manager at a time? I can add a second ogre head to the first canvas but I can't add any to the second. Is it just the way that I'm creating the entities, or have I got the fundamentals a bit wrong? I do need to have multiple tabbed windows and at some point I will need to have the same mesh appear in different tabs.

If anyone has any ideas what I problem is then I'd love to hear them. Thanks!
Post Reply