Page 1 of 1

[SOLVED & WIKKIED] Changing scene manager at runtime

Posted: Tue Mar 08, 2005 11:02 pm
by Mr. Turner
Hi,

I'm creating the Ogre Toolbox (a utility box for artists). While working on the dot scene editor I noticed that the terrain scene manager complains when doing a Ray Query on a scene without a terrain. It breaks, because it tries to get the terrain pages.

Now can I change the SceneManager between GENERIC and EXTERIOR_CLOSE at runtime?

I did some experimenting, but all I got was some black darkness.

Any ideas?

Thanks

Mr. Turner

Posted: Wed Mar 09, 2005 7:51 pm
by Mr. Turner
Nobody ever done this?

Posted: Wed Mar 09, 2005 8:53 pm
by johnhpus
There's some code around that uses more than one Scene Manager at the same time. MulitiSceneManager it might have been called ...

Short of finding that code and trying to apply whatever it does to your project, I would recomend just shutting down the Ogre parts of your program and reinitializing with the newly selected Scene Manager.

Posted: Wed Mar 09, 2005 9:08 pm
by pjcast
The multi scene manager is in ogreaddons... Though, I havn't looked at it, but, afaik is outdated and underdocumented :\

Posted: Thu Mar 10, 2005 12:20 am
by CombatWombat
You can have multiple SceneManagers at the same time. You have to directly create the SceneManagers, and use setSceneManager on Root to set it up (which has the side-effect of setting up the render target for the SceneManager).

When flipping between SceneManagers (for me the different managers correspond to various modes in my game) you'll have to create a new viewport each time, but this doesn't appear to be an expensive operation.

I'm unsure whether it is possible to have two viewports into different SceneManagers rendering at once, haven't tried to do that.

Let me know if you have any hassles...

Cheers,

Mark/CW

Posted: Thu Mar 10, 2005 10:02 am
by :wumpus:
CombatWombat wrote: I'm unsure whether it is possible to have two viewports into different SceneManagers rendering at once, haven't tried to do that.
That's possible :)

SceneManager is no singleton in ogre (there can be one per viewport), so you can have more of them if you create them manually.

Posted: Thu Mar 10, 2005 8:11 pm
by Mr. Turner
You have to directly create the SceneManagers, and use setSceneManager on Root to set it up (which has the side-effect of setting up the render target for the SceneManager).
So you mean setSceneManager(classname) on the Root for the two SceneManagers on the initialization?
And then getSceneManager(classname) & recreate the viewport stuff to switch between them?

I currently restart the whole Root, but it's a very slow hack.

Posted: Fri Mar 11, 2005 2:05 am
by CombatWombat
(this code is edited on the fly, so there could be some minor inaccuracies :))

Let's say you have two modes (similar kind of idea to http://www.ogre3d.org/wiki/index.php/Ma ... _with_OGRE) - and each creates a scene manager. To do this do:

Code: Select all

	mSceneManager = new Ogre::SceneManager();
	Ogre::Root::getSingleton().setSceneManager(Ogre::ST_GENERIC, mSceneManager);
	mCamera = mSceneManager->createCamera("PlayerCam");
To bring up one of these modes:

Code: Select all

	Ogre::Root::getSingleton().setSceneManager(ST_GENERIC, mSceneManager);
	Ogre::Viewport* vp = Overseer::getSingleton()->getWindow()->addViewport(mCamera, 0, 0, 0, 1,1);
 	mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
And to tear down one of these modes:

Code: Select all

	// mWindow is the return value from Root::initialise
	mWindow->removeAllViewports();
This will allow you to change scene managers (assuming I've not forgotten anything vital) - let me know if there are problems and I can go find what I forgot to mention :)

Posted: Fri Mar 11, 2005 6:00 pm
by Mr. Turner
Thanks for all your help so far.

Ok I got it working, but my window isn't updating. I just get a black screen when switching to landscape mode. It does seem to update when switching back to generic mode.

I looked at the ogre.log and I saw the viewport being recreated, landscape is loading good also, but I don't see anything.

My code is like this:

I do the normal initialisation (no special stuff there) and when needed I change with this code:

Code: Select all

void OgreManager::Restart(SceneType mType)
{
    mWnd->removeAllViewports();
    mCurrSceneManager->clearScene();
    mCam->setPosition(0, 0, 300);
    mCam->lookAt(0, 0, 0);
    if(mType == ST_GENERIC){
        mCurrSceneManager = Root::getSingleton().getSceneManager(ST_GENERIC);
        mWnd->addViewport(mCam);
    }
    else if(mType == ST_EXTERIOR_CLOSE)
    {
        mCurrSceneManager = Root::getSingleton().getSceneManager(ST_EXTERIOR_CLOSE);
        mWnd->addViewport(mCam);
        LogManager::getSingleton().logMessage("SceneManager: switched to ST_EXTERIOR_CLOSE");
    }
    mCurrSceneManager->clearScene();
    currSceneType = mType;
}

Posted: Sat Mar 12, 2005 1:14 am
by CombatWombat
I'm guessing then that you created the Camera from the Generic SceneManager? You want a different camera for each scene.

(When you change to landscape mode, you clear the Generic scene - but since your camera is viewing the Generic scene rather than the Landscape, you can't see anything.)

I'd aim to avoid clearing the scene when switching, but I can also think of some exceptions to this suggestion too, so it might not be right for your code :)

Posted: Sat Mar 12, 2005 12:48 pm
by Mr. Turner
Thanks man, now it works.

I'll add my code to the Ogre Wiki.

Code added: http://www.ogre3d.org/wiki/index.php/Ch ... gerRunTime