How to load new scenenode?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
NewerCookie
Posts: 20
Joined: Sat Jan 10, 2009 12:53 pm

How to load new scenenode?

Post by NewerCookie »

I wrote new scenenode and made irredit plugin (name..suppose "CSomeSceneNode")
Also, "CSomeSceneNodeFactory" was written for load .irr file.
And then, I need "CSomeSceneNodeFactory::addSceneNode()" like "CDefaultSceneNodeFactory::addSceneNode()"

Code: Select all

ISceneNode* CDefaultSceneNodeFactory::addSceneNode(ESCENE_NODE_TYPE type, ISceneNode* parent)
{
	switch(type)
	{
	case ESNT_CUBE:
		return Manager->addCubeSceneNode(10, parent);
	case ESNT_SPHERE:
		return Manager->addSphereSceneNode(5, 16, parent);
......
......
Here is problem.
I tried to "addSomeSceneNode()" but cant.
"add...SceneNode" function is ISceneManager's.
I'll make new scenemanager has "addSomeSceneNode()" derived from ISceneManager?
So then I control two different scenegraph? It's waste!

gimme some help, plz~
I hope you understand my poor english.
If i used wrong sentence, notify me.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You need to implement all of the methods of ISceneNodeFactory. Once you've done that, you register your scene node factory with the scene manager like

Code: Select all

ISceneNodeFactory* myFactory = new CSomeSceneNodeFactory;
smgr->registerSceneNodeFactory(myFactory);
myFactory->drop();
This will allow the scene manager to create your node types when reading back from a .irr file. You can also create your node type by type name like this...

Code: Select all

ISceneNode* myNode = smgr->addSceneNode("myNodeType", parent);
If you want to create an instance of your scene node explicitly, you can do this...

Code: Select all

ISceneNode* myNode = new CSomeSceneNode(parent, smgr, ...);
myNode->drop();
If, at any point, you need to get a derived class pointer, you can do that like this...

Code: Select all

if (myNode->getType() == ESNT_SOMENODE) {
  CSomeSceneNode* someNode = (CSomeSceneNode*)myNode;
  // do stuff specific to derived class
}
If you've compiled the library and your code with RTTI enabled, you can use this also...

Code: Select all

CSomeSceneNode* someNode = dynamic_cast<CSomeSceneNode*>(myNode);
if (someNode) {
  // do stuff specific to derived class
}
Travis
NewerCookie
Posts: 20
Joined: Sat Jan 10, 2009 12:53 pm

Post by NewerCookie »

I get your point.
Don't use "add...SceneNode" function by perforce.
you're right.. I thought so complicated.
but, any other scenenodes are provided with "add...SceneNode" interface..
It's not smooth..:?
thanks, vitek
I hope you understand my poor english.
If i used wrong sentence, notify me.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

If you want to call smgr->addSomeSceneNode(...), you need to modify ISceneManager.h, CSceneManager.h and CSceneManager.cpp to create your derived scene node type. Once you do this, you need to rebuild your Irrlicht library. In the grand scheme of things, it's not really worth it.

Travis
NewerCookie
Posts: 20
Joined: Sat Jan 10, 2009 12:53 pm

Post by NewerCookie »

No, I don't want to modify engine.
It's make harder to use next version.
Thanks your advice, vitek
I hope you understand my poor english.
If i used wrong sentence, notify me.
Post Reply