[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 » Tue Mar 08, 2005 11:02 pm

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

Mr. Turner
Halfling
Posts: 88
Joined: Sun Sep 05, 2004 7:01 pm
Location: Belgium

Post by Mr. Turner » Wed Mar 09, 2005 7:51 pm

Nobody ever done this?
0 x

User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am

Post by johnhpus » Wed Mar 09, 2005 8:53 pm

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

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
Contact:

Post by pjcast » Wed Mar 09, 2005 9:08 pm

The multi scene manager is in ogreaddons... Though, I havn't looked at it, but, afaik is outdated and underdocumented :\
0 x
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 » Thu Mar 10, 2005 12:20 am

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

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands

Post by :wumpus: » Thu Mar 10, 2005 10:02 am

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

Mr. Turner
Halfling
Posts: 88
Joined: Sun Sep 05, 2004 7:01 pm
Location: Belgium

Post by Mr. Turner » Thu Mar 10, 2005 8:11 pm

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

User avatar
CombatWombat
Greenskin
Posts: 138
Joined: Fri Feb 04, 2005 11:05 pm
Location: Melbourne, Aus

Post by CombatWombat » Fri Mar 11, 2005 2:05 am

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

Mr. Turner
Halfling
Posts: 88
Joined: Sun Sep 05, 2004 7:01 pm
Location: Belgium

Post by Mr. Turner » Fri Mar 11, 2005 6:00 pm

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

User avatar
CombatWombat
Greenskin
Posts: 138
Joined: Fri Feb 04, 2005 11:05 pm
Location: Melbourne, Aus

Post by CombatWombat » Sat Mar 12, 2005 1:14 am

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

Mr. Turner
Halfling
Posts: 88
Joined: Sun Sep 05, 2004 7:01 pm
Location: Belgium

Post by Mr. Turner » Sat Mar 12, 2005 12:48 pm

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

Post Reply