Best way to add multiple models [SOLVED]

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
TJBaldy
Posts: 16
Joined: Fri Dec 02, 2011 3:06 pm

Best way to add multiple models [SOLVED]

Post by TJBaldy »

I did a quick search before posting this and didn't find anything that was specific to my question.

OK so I'm new to Irrlicht, new to c++ in fact.

My question is how would be best to load different models in to my scene? I currently have about five different 3D models loaded into my scene hovering above a terrain I created from the terrain tutorial. At the moment I'm using the method from tutorial 1 where you create a mesh then a node for the mesh, then an if statement for each node. So how would be best to do it? Also, how would I go about using the same model and loading it multiple times across the terrain (e.g a tree).

Thanks for everyones replies in advance :D

Tom
Last edited by TJBaldy on Mon Jan 09, 2012 2:27 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Best way to add multiple models.

Post by CuteAlien »

You can have multiple nodes working with the same mesh. So you need to load the mesh just once and then can use it all over the place. Maybe check this page on Wiki if you're new to this stuff: http://www.irrlicht3d.org/wiki/index.ph ... ommonTerms

For larger scenes you will no longer load each model one-by-one in code, but instead use some scene-format. You can for example use the .irr format which allows you to create scene in irrEdit which you can load then with a single command.
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
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Best way to add multiple models.

Post by hybrid »

Well, sounds really like a basic programming question. You can refine all those steps into a function and call that function with the mesh file name, returning the scene node. This would save code duplication. Other possibility is to create a scene file somewhere and load a whole scene with one call. This is only applicable if you can create the scene file prior to all this of course.
Loading the same mesh multiple times does not create a significant overhead. Irrlicht has a mesh cache which avoid mesh duplication. You could be a little more efficient by storing the mesh pointer and adding scene nodes from that mesh multiple times. But since you don't call this method thousands of times it's ok to go first the first approach.
Ahh, CuteAlien was faster, but I'll still post my text...
TJBaldy
Posts: 16
Joined: Fri Dec 02, 2011 3:06 pm

Re: Best way to add multiple models.

Post by TJBaldy »

Thanks for the replies guys. I've managed to work out how to add multiple objects of the same item by playing around with the code. I added three tree objects using the same mesh :). My project is part of a University Degree and the course is about using a game engine so unfortunately I can't just go and create a scene using some software and then load it up with code.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Best way to add multiple models.

Post by randomMesh »

the course is about using a game engine so unfortunately I can't just go and create a scene using some software and then load it up with code.
Irrlicht is NOT a game engine, it's a 3D engine. There's a huge difference.
And you can compose your scene with irrEdit and load it in Irrlicht easily.
"Whoops..."
shadowghost21
Posts: 56
Joined: Wed Nov 23, 2011 11:53 pm

Re: Best way to add multiple models.

Post by shadowghost21 »

It's not hard to make into a game engine. You just need to write all that code yourself :) Irrlicht is pretty simple to work with and has some nice wrappers and data structures, one I am particularly in love with ATM is array<T> <3
TJBaldy
Posts: 16
Joined: Fri Dec 02, 2011 3:06 pm

Re: Best way to add multiple models.

Post by TJBaldy »

Yeh I meant 3D engine... Thanks again for everyone's help :D
Post Reply