[fixed] Using Multiple SceneManagers

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
MasterD
Posts: 153
Joined: Sun Feb 15, 2004 4:17 pm
Location: Lübeck, Germany
Contact:

[fixed] Using Multiple SceneManagers

Post by MasterD »

What is the proper way to use multiple SceneManagers, which are created by device->createNewSceneManager()?

This is the way I thought it could work: (pseudo code)

Code: Select all

node = smgr1->getSomeNode(..)
.... some time after, I have a new scenemanager ....
smgr2 = device->createNewSceneManager(false) // false: don't clone content of smgr1
node->setParent(smgr2->getRootSceneNode())
The problem here is the usage of setParent(). It does not take into account the SceneManager of the parent node. So, when drawing using smgr2->drawAll(), node->onRegisterSceneNode is called, but the node registers to smgr1 ...

So it seems, that you can only use multiple SceneManagers, if you create the nodes with the "correct" SceneManager and switching a nodes' SceneManager relation is not possible.

Well, what do you think, shouldn't it be also possible with setParent() ?
YASS - Yet another Space Shooter
under Devolpment, see http://yass-engine.de
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

I have been playing with moving nodes between scene managers and never even thought to do it this way. I actually added setSceneManager() and getSceneManager() to ISceneNode in my local version :oops: (but didn't commit it because it seemed ugly)

It would be much more sensible to make setParent() or addChild() change the scene manager if required. I'll move this to bug reports, and if nobody has objections will commit a fix to svn.

Thanks for pointing this out :)

edit:
okay, patch here if you want to test it before I commit-

Code: Select all

Index: ISceneNode.h
===================================================================
--- ISceneNode.h	(revision 1635)
+++ ISceneNode.h	(working copy)
@@ -248,6 +248,10 @@
 		{
 			if (child && (child != this))
 			{
+				// Change scene manager?
+				if (SceneManager != child->SceneManager)
+					child->setSceneManager(SceneManager);
+
 				child->grab();
 				child->remove(); // remove from old parent
 				Children.push_back(child);
@@ -717,6 +721,17 @@
 			}
 		}
 
+		//! Sets the new scene manager for this node and all children.
+		//! Called by addChild when moving nodes between scene managers
+		void setSceneManager(ISceneManager* newManager)
+		{
+			SceneManager = newManager;
+
+			core::list<ISceneNode*>::Iterator it = Children.begin();
+			for (; it != Children.end(); ++it)
+				(*it)->setSceneManager(newManager);
+		}
+
 		//! Name of the scene node.
 		core::stringc Name;
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Works For Me. Heh, I had a similar local patch which I was too Goddamn lazy and wishy washy to even upload.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
MasterD
Posts: 153
Joined: Sun Feb 15, 2004 4:17 pm
Location: Lübeck, Germany
Contact:

Post by MasterD »

Sorry, does not work for me:

CSceneManager constructs it's ISceneNode Implementation with
ISceneNode(parent=0, smgr=0)

without setting SceneManager of ISceneNode afterwards. So when calling:

Code: Select all

root = smgr2->getRootSceneNode()
node->setParent(root)
// within addChild
if(node->SceneManager != root->SceneManager) // true, since Root->smgr == 0
{
  node->setSceneManager(0) // actually.
}
With setting
SceneManager = this
in CSceneManager's constructor, this is fixed.
YASS - Yet another Space Shooter
under Devolpment, see http://yass-engine.de
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Using Multiple SceneManagers, proper way?

Post by CuteAlien »

MasterD wrote:What is the proper way to use multiple SceneManagers, which are created by device->createNewSceneManager()?
Man - don't make posts sending people on the wrong track ^^

It's ISceneManager::createNewSceneManager and not device->createNewSceneManager(). (and don't tell me you call your SceneManager instances always device)

*grmblgrmblhalfanhourlostforsearchingthatstupidfunction*
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Re: Using Multiple SceneManagers, proper way?

Post by MasterGod »

CuteAlien wrote:*grmblgrmblhalfanhourlostforsearchingthatstupidfunction*
Lol!

Well, at least it took only that much time.. :wink:
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Post Reply