[SOLVED & WIKKIED] Changing scene manager at runtime

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
Mr. Turner
Halfling
Posts: 88
Joined: Sun Sep 05, 2004 7:01 pm
Location: Belgium

[SOLVED & WIKKIED] Changing scene manager at runtime

Post 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
Last edited by Mr. Turner on Sun Mar 13, 2005 5:54 pm, edited 1 time in total.
Mr. Turner
Halfling
Posts: 88
Joined: Sun Sep 05, 2004 7:01 pm
Location: Belgium

Post by Mr. Turner »

Nobody ever done this?
User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3

Post 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.
User avatar
pjcast
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2543
Joined: Fri Oct 24, 2003 2:53 am
Location: San Diego, Ca
x 2
Contact:

Post by pjcast »

The multi scene manager is in ogreaddons... Though, I havn't looked at it, but, afaik is outdated and underdocumented :\
Have a question about Input? Video? WGE? Come on over... http://www.wreckedgames.com/forum/
User avatar
CombatWombat
Greenskin
Posts: 138
Joined: Fri Feb 04, 2005 11:05 pm
Location: Melbourne, Aus

Post 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
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post 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.
Mr. Turner
Halfling
Posts: 88
Joined: Sun Sep 05, 2004 7:01 pm
Location: Belgium

Post 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.
User avatar
CombatWombat
Greenskin
Posts: 138
Joined: Fri Feb 04, 2005 11:05 pm
Location: Melbourne, Aus

Post 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 :)
Mr. Turner
Halfling
Posts: 88
Joined: Sun Sep 05, 2004 7:01 pm
Location: Belgium

Post 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;
}
User avatar
CombatWombat
Greenskin
Posts: 138
Joined: Fri Feb 04, 2005 11:05 pm
Location: Melbourne, Aus

Post 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 :)
Mr. Turner
Halfling
Posts: 88
Joined: Sun Sep 05, 2004 7:01 pm
Location: Belgium

Post 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
Post Reply