The right way to load the same objects thousands of times

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
Burton
Posts: 5
Joined: Fri Aug 03, 2018 12:08 am

The right way to load the same objects thousands of times

Post by Burton »

Hi everyone,

I have a question about how to avoid using up memory when loading the same mesh thousands of times. My current project requires to duplicate the selected objects thousands of times (>3600), the mesh is a .obj file with a .mtl texture, which are altogether 1MB. I duplicated this object by the following codes:

Code: Select all

 
 
    scene::IAnimatedMesh* m = smgr->getMesh(filename.c_str());
    
    for (int i = 0; i < 3600; i++) {
 
        // set default material properties
        scene::ISceneNode* newModel;
 
        /*set mesh as pickable and hightlightable
        */
        if (Octree)
        {
            newModel = smgr->addOctreeSceneNode(m->getMesh(0), 0, ID_IsNotPickable);
        }
 
        ...
    }
 
Somehow, the irrlicht duplicates the mesh as well since the memory used up more than 3GB in x64 MSVC 2017 release version. Another problem is when moving the viewpoint, the fps is only 2 which means it would be too slow and not smooth anymore.

Any suggestions about how should I avoid these problems? Thanks in advance.

Best.
Burton
Posts: 5
Joined: Fri Aug 03, 2018 12:08 am

Re: The right way to load the same objects thousands of time

Post by Burton »

based on this post
http://irrlicht.sourceforge.net/forum/v ... ts#p218333
I realized the irrlicht may stil not be able to deal with too many triangles, no matter they come from the same object or from different objects. So I tried to decrease the number the triangles in my mesh (15806 to 2138 tris). Now after loading 3600 times, the fps can be 10. Not good enough, but at least better than before. Any other solutions would be appreciated.

Thanks.
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: The right way to load the same objects thousands of time

Post by devsh »

Unfortunately the Octree sene node creates a sort-of duplicate of your mesh, I don't believe the results per-mesh are cached (even though for same size leaf node octree they could).

Also the octree scene node was created back in the day when 512 triangles drawn was actually a lot, so the leaf triangle count may have to be increased.

Secondly 15k*3600 = 45 Million Triangles, which unless you have a Nvidia GPU ending with 80 (like 1080,980,780) is beyond even a modern graphics card's capabilties. I recommend keeping your whole scene triange count below 10Mil.

IT really sounds like you need instancing and level-of-detail.
CuteAlien
Admin
Posts: 9647
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: The right way to load the same objects thousands of time

Post by CuteAlien »

Yeah, don't use octree scenenode. And without instancing this is hard to get really fast and instancing is not supported by Irrlicht. Depending on use case imposters might also work (rendering your object to an image and then just showing a billboard of that image - when objects are far away that might be sufficient that users don't notice).
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