Page 1 of 1

Object creation during game runtime.

Posted: Wed Oct 26, 2005 10:46 am
by soldier_
Hi everyone!
I have a question on Irrlicht scene management system.
I have downloaded the Newton-irrlicht tutorial and took a look at the source code. In the demo application you have some boxes falling down from the sky. During the application if you make a mouse click a box appears in front of you. I took a look at the box creation code and I have noticed this:

NewtonCube *CGame::MakeCube(vector3df loc)
{
NewtonCube *tmp = new NewtonCube;

tmp->mesh = smgr->getMesh("data/smallcube.3ds");

I am confused about the last line. The application loads the mesh from the hard disk each time a new object is being created? Does't this slow down the application?

Posted: Wed Oct 26, 2005 2:04 pm
by Guest
i guess the models are shared in memory if they are used more than once (would be stupid if it wouldnt be like this :D )

Posted: Wed Oct 26, 2005 5:11 pm
by Podunk
whatever you guess, soldier is saying that the code IS loading the mesh from a file every time the object is instantiated.

To answer your question, yes it is slower.

Posted: Wed Oct 26, 2005 6:10 pm
by WToma
the code IS loading the mesh from a file every time the object is instantiated
When you call getMesh for the first time with a filename, it loads the mesh from the file. But if you call it more times, it will return the same object. So meshes are shared among mesh scene nodes. To physically load a mesh every time use the meshbuffer (new in 0.12).
(Anyway, I still need a function that copies a mesh optionally with its materials without loading it again from file.)
Toma

Posted: Thu Oct 27, 2005 1:12 pm
by Guest
Thanks for your input. I have a better picture now on how mesh loading works.

Posted: Thu Oct 27, 2005 1:14 pm
by soldier_
^^that was me