Best way to add a child to a node/joint and position it?

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
ihavenomuffins
Posts: 2
Joined: Sat Jun 04, 2011 4:55 pm

Best way to add a child to a node/joint and position it?

Post by ihavenomuffins »

Hello,

After searching the forums I've answered a good number of my certainly beginner-level questions. My short-term goal is to be able to combine models/meshes easily in a meaningful way, e.g. I want to be able to create a simple spaceship from parts such as picking a cockpit and adding engines and lasers to it.

I've so far been able to create a cockpit in Google Sketchup 8, import them into Blender 2.49 and add an armature, export them as .b3d, load it with the Irrlicht engine, and attach an engine (created in a similar manner but with no armature) to a joint (named, appropriately, "Engine.R").

When I did this, however, I pretty much did guess and check for the rotation and positioning of the engine to the ship. My true question is this: what is the best way to make models and code in Irrlicht to make fitting parts onto a spaceship as routine and hassle-free as possible? I'd ideally like to be able to use the same file, say engine.b3d, for both left and right engines and use it on several different cockpits.

I'm a beginner with both Irrlicht and Blender and right now, so I'm not sure exactly the best way to describe what I'm trying to do; I also don't want to come up with a tedious, trial and error based approach to this when there exist alternate, easier methods. At least, I hope they exist.

Thank you.
CuteAlien
Admin
Posts: 9718
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Best way to add a child to a node/joint and position it?

Post by CuteAlien »

The simplest (and usual) way is putting your models together completely in an editor.

It get's more tricky if you want this to be possible inside your game.

There's 2 ways I could think off. The first one is what I did so far. Each object has some property-file (or property-node in a xml-file usually) which has information about it. So a spaceship object would have the property informations for the main-model and maybe the positions/rotations for child-objects. Or to make it more comfortable you can write a small editor instead of working only with xml-files (still xml-files are a good start).

Another way (which I did not try yet myself) could be using meshes with an special texture at the connection-points. Those you could set in Blender. The trick is that each mesh with a special-texture has it's own mesh-buffer. So you find that meshbuffer later by checking the meshbuffer materials. If such a meshbuffer is for example simple line you can also figure out the rotation again. And in game you would remove that meshbuffer then.
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
ihavenomuffins
Posts: 2
Joined: Sat Jun 04, 2011 4:55 pm

Re: Best way to add a child to a node/joint and position it?

Post by ihavenomuffins »

Thanks for the reply. I would like for players to be able to combine parts in-game (and possibly add their own if they have the inclination to make models), so I'll likely do some combination of your two suggestions. Sorry for the late reply, but I did a lot more reading and searching to try to better understand your suggestions.

One of my major problems, I discovered, was at some point the models I was working with got centered at a point other than the origin; correcting this made the XML option seem a lot more manageable.

I know you said you haven't worked with the material based option, but I do have a few questions about the concept of it. Is the idea to essentially add some materials (or possibly joints?) to each texture, possibly in a pattern, write a function to find the position of that pattern of materials/joints, and figure out the transformation needed to have it match some other pattern on the other object? Much of my searching was related to effectively implementing this, or determining if they way I understand it is even possible to accomplish in a reasonable way with the engine.

In the end, I think adherence to stricter modeling guidelines and the XML option will likely be the way I go, but I am curious about a truly dynamic way to get position/rotation of objects relative to others that would eliminate the need for creating an XML file containing position and rotation for the model and be accomplished using only the model itself and the "game".

Incidentally, is there a way to "mirror" a model in Irrlicht (transforming it about an axis in a way that isn't a rotation). I know that this is easily something that could be done in Blender, but if an equivalently easy solution exists in Irrlicht, I think that would be preferable.

Thanks.
CuteAlien
Admin
Posts: 9718
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Best way to add a child to a node/joint and position it?

Post by CuteAlien »

ihavenomuffins wrote: I know you said you haven't worked with the material based option, but I do have a few questions about the concept of it. Is the idea to essentially add some materials (or possibly joints?) to each texture, possibly in a pattern, write a function to find the position of that pattern of materials/joints, and figure out the transformation needed to have it match some other pattern on the other object? Much of my searching was related to effectively implementing this, or determining if they way I understand it is even possible to accomplish in a reasonable way with the engine.
The idea was abusing a mesh as joint. But I didn't think too much about it, because most likely you can simply use joints. In some formats those should be exported :-)

Otherwise the idea had been:
You have one texture which stands for "joint". Doesn't really matter what kind of textures - you just need to know which one it is so you can locate it again later on. A mesh will on loading be split into meshbuffers where each meshbuffer has exactly one material type. So after loading you can search for all meshbuffers which have this texture and then you would know the position of your joints (for example the center of the bounding-box of that meshbuffer). So finding position would be easy. If you need additionally some specific rotation for that point it is getting a little bit harder. Maybe you could use vertex-colors (one end of your mesh black and one end white) and check for those.
ihavenomuffins wrote: Incidentally, is there a way to "mirror" a model in Irrlicht (transforming it about an axis in a way that isn't a rotation). I know that this is easily something that could be done in Blender, but if an equivalently easy solution exists in Irrlicht, I think that would be preferable.
Scaling a node-axis by -1 should do that I think.
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
nespa
Posts: 167
Joined: Wed Feb 24, 2010 12:02 pm

Re: Best way to add a child to a node/joint and position it?

Post by nespa »

one rule: each 3D object added to the scene will be 1st positioned at 0,0,0 in 3D space, so...

1. load your pivot object (default at 0,0,0 position);
2. load a child (it is loading at 0,0,0 position too);
3.position the child object against relative to its parent;
4. set the joint between the child and the parent
5. repeat the steps from 2 to 4 with the others objects........
.................................................

then, move/rotate the parent object for all the children, or just rotate a separate child ;

P.S. take care to set the center of each child, this will be the pivot for its local rotation;
Post Reply