Attaching extra information to a Scene Node

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
itsagam
Posts: 10
Joined: Wed Dec 28, 2011 3:39 am

Attaching extra information to a Scene Node

Post by itsagam »

What would be the best way to attach information to a scene node so I can extract it when I'm picking the scene node doing raycasting. I have an Enemy class that contains a reference to an AnimatedMeshSceneNode. So what would be the nicest way to get the reference to the Enemy class so that I can, say, deduct its health when I'm shooting at it.
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Attaching extra information to a Scene Node

Post by Granyte »

i just went through the same issue a couple of days ago and the only way of doing it was to write an interphase between a physic engine and irrlicht that would point to my data

an other way to do it when using only irrlicht would have been to derive custom classes from the diferent scene node class you need and have them point toward your custom data
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Re: Attaching extra information to a Scene Node

Post by Brainsaw »

I use custom scene nodes for this issue. I got tons of those (with plugins for IrrEdit), and the integration is great (though it does increase the size of my scene files).
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Attaching extra information to a Scene Node

Post by greenya »

I would use some map, like:

Code: Select all

map<int, nodeAttachment>
And when you need to get node's custom data, you simply pick item from this map using node's id. Ofcause all nodes should have distinct id.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Attaching extra information to a Scene Node

Post by CuteAlien »

Depending on the rest of the code you can maybe also use a map with <ISceneNode*, nodeAttachment>, which can be useful as the id is also needed for collision-groups (something I've run into in the past). Or you might abuse the "name" parameter - you can put a lot in a string.
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
itsagam
Posts: 10
Joined: Wed Dec 28, 2011 3:39 am

Re: Attaching extra information to a Scene Node

Post by itsagam »

Thanks for the heads up! Sticking to custom scene nodes, I fear I might get into issues like managing IDs or housekeeping the map separately.
itsagam
Posts: 10
Joined: Wed Dec 28, 2011 3:39 am

Re: Attaching extra information to a Scene Node

Post by itsagam »

@Brainsaw Can you post some code of a custom node scene node that addresses this? I'm doing it this way

Code: Select all

class EntitySceneNode : public ISceneNode
{
protected:
        aabbox3d<f32> Box;
        S3DVertex Vertices[4];
        SMaterial Material;
        
        void* userData;
public:
        EntitySceneNode(void* userData, ISceneNode* parent, ISceneManager* mgr, s32 id) : scene::ISceneNode(parent, mgr, id)
        {
                setUserData(userData);
        }
 
        virtual void render()
        {
        }
 
        virtual const core::aabbox3d<f32>& getBoundingBox() const
        {
                return Box;
        }
 
        virtual void setUserData(void* userData)
        {
                this->userData = userData;
        }
 
        virtual void* getUserData()
        {
                return userData;
        }
};

Code: Select all

        EntitySceneNode *entity = new EntitySceneNode(this, mapMesh, smgr, -1);
        mesh = smgr->addAnimatedMeshSceneNode(smgr->getMesh("./data/models/enemies/fatdude/fatdude.x"), 
                                mapMesh, 1, vector3df(0, 0, 0), vector3df(0, 0, 0), vector3df(0.3, 0.3, 0.3));
 
But it seems more like a hack than anything
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Re: Attaching extra information to a Scene Node

Post by Brainsaw »

You could just take a look at my "ManagedShadowSceneNode" (http://bulletbyte.de/products.php?sub=i ... dowmanager). It is very simple, just adds a single integer as custom data (a level to define when a shadow should be added to an AnimatedMeshSceneNode which is this node's parent), it provides a shadow manager (singleton) that does the creation and removing. There also is a scenenodefactory and a plugin for IrrEdit so that I don't need to code this by hand. The package does also contain a small demo to show how it works. I hope you can get the necessary information from there, but feel free to ask if there are more questions.
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Re: Attaching extra information to a Scene Node

Post by sudi »

Did anyone of you think about using a scenenode animator to hold userdata?
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Attaching extra information to a Scene Node

Post by CuteAlien »

Hm, advantage would be that it would allow adding a real custom object, but disadvantage is that it's update will be called each frame.

But shows more or less what a real custom-data would probably have to look like. Serializable custom objects.
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
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Re: Attaching extra information to a Scene Node

Post by Brainsaw »

Sudi wrote:Did anyone of you think about using a scenenode animator to hold userdata?
I tried that, but I never go custom animators working in IrrEdit (which is a showstopper for me ;) )
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Re: Attaching extra information to a Scene Node

Post by sudi »

Brainsaw wrote:
Sudi wrote:Did anyone of you think about using a scenenode animator to hold userdata?
I tried that, but I never go custom animators working in IrrEdit (which is a showstopper for me ;) )
hmm ok i don't think i ever had that problem...besides there is still EditIrr somewhere^^
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Attaching extra information to a Scene Node

Post by Mel »

No, It has been a long time since i used Irredit for the last time... though i have my own custom editor, anyway...

The MOST risky way to have custom data attached to your scene nodes, though the simplest, is to hack directly the engine and add a public void* pointer to the ISceneNode class, recompile the engine, and acces that pointer like any other method or attribute of the ISceneNode class. That way, any the scene nodes could have any data attached to them and can be accessed inmediately, no need for searches nor anything. The bad thing is that it may break compatibility with other versions of the engine, but, customizing the engine maybe a need sometimes. But it is up to you.

Why Irrlicht doesn't have a void pointer in the scene nodes by default? it is useful to integrate Irrlicht with almost anything out there.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Attaching extra information to a Scene Node

Post by serengeor »

Mel wrote:Why Irrlicht doesn't have a void pointer in the scene nodes by default? it is useful to integrate Irrlicht with almost anything out there.
It might also work, by making ISceneNode inherit another class that would allow you to set some custom data. That would still need a recompile, but you then wouldn't have to rely on void pointers, I think. Don't really know how practical that would be, but it's an option.
Actually if you're not using irrlichts collision system to get nodes it is quite useless to have some other data attached to it from my point of view. Most of the times you would still write some sort of Object system that would allow you storing that information. I once used void pointers in bullet physics engine, but it is really dangerous as you mentioned. After that I changed it to work with bullets derived motion state class (a class that receives transformations of rigid body, used to update visual nodes) and that seemed to do the job quite better.
Working on game: Marrbles (Currently stopped).
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Attaching extra information to a Scene Node

Post by CuteAlien »

Void pointers alone still are not sufficient as soon as you also want to support serialization of user data. In that case you need some custom userdata class and a way for users to add factories for those. That would be the clean solution. Which gets us back to the serialization system which is imho at the bottom of many problems right now.
Then again - adding a custom-data without serialization possibilities also has it's uses, leaving aside that it might be confusing as soon as we add a cleaner solution in the future. Personally I miss it a lot more in some gui-elements, where then again a void* pointer might not be optimimal but maybe rather some long int or similar (but not sure...). Actually at different times we already got 2 user-data values smuggeled in the engine (one in the IGUITable, the other somewhere in shaders) which as nothing ever was decided on how to implement that got implemented different (which might be ok or not).

Maybe we could name it something like runtime-user-data to make certain people realize it can't be used for serialization. And later on a clean solution. As it indeed makes coding just simpler in many cases I would be fine with that, but I won't add it without consent of other engine-coders as I know that especially Niko was a lot against adding user-data in the past.

Or maybe someone starts thinking up a clean solution for our serialization system which (beside other features) allows adding serializable custom structures in an easy way. Or any other idea... (just noting that in the past I also simply wanted to add a void* until I got some explanation why this is not optimial).
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
Post Reply