Loading obj mesh files with 32bit index type

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
drhenry
Posts: 16
Joined: Fri Mar 26, 2010 8:03 am

Loading obj mesh files with 32bit index type

Post by drhenry »

Hello,
when I load an obj file, I get the error "Too many vertices for 16bit index type, render artifacts may occur." (16bit indices limit index count to 65536)
I took a look into the Irrlicht source code and saw, that there's a struct called E_INDEX_TYPE indicating that either 16bits or 32 bits can be used.
This is how I try to get a mesh with 32bit indices:

Code: Select all

IAnimatedMesh* mesh = smgr->getMesh("media/cityModel.obj");
IMeshBuffer* mb = mesh->getMeshBuffer(0);
CDynamicMeshBuffer* dynMeshBuf = new CDynamicMeshBuffer(EVT_STANDARD, EIT_32BIT);
dynMeshBuf->append(mb);
Now I don't know, how to assign it to a scene node and add it to the scene... :oops: Can anyone help, please?
Is this the way to go when you want to load obj files with 32bit indices?
pc0de
Posts: 300
Joined: Wed Dec 05, 2007 4:41 pm

Post by pc0de »

A quick glance at the obj mesh loader (COBJMeshFileLoader.cpp) shows that it currently doesn't support dynamic mesh buffers (32 bit indexes). So after you've executed:

Code: Select all

IAnimatedMesh* mesh = smgr->getMesh("media/cityModel.obj"); 
index/vertex data has already been lost.

You can either patch CObjMeshFileLoader.h/cpp to use dynamic mesh buffers or break up your mesh into buffer sizes that can be handled by 16 bit indexes.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

For obj this is indeed really simple. Just add some groups into your mesh, Irrlicht will load groups into different meshbuffers.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Loading obj mesh files with 32bit index type

Post by robmar »

I modified CMeshBuffer.h to switch to u32´s, but it didn´t allow more vertices. I see the array in CMeshBuffer can be any type... I guess I missed where to change that to u32 somewhere.

Could you give an idea what needs to be changed to support 32-bit (knowing its not efficient for games, just to be able to view large meshes).

Or would it be more efficient to use DynamicMesh Buffer, and if so, are there any examples as to how that is done? I.e. do we replace.
ikam
Posts: 46
Joined: Sun Jun 24, 2007 4:46 pm
Location: France

Re: Loading obj mesh files with 32bit index type

Post by ikam »

that code works fine for me :

Code: Select all

 
// switch 16 to 32 bits indices type buffer if nb indices > 65535
video::E_INDEX_TYPE indexType = video::EIT_16BIT;
if(nbTriangles*3 > sPow(2,16)-1  /*65535*/ )
{
  indexType = video::EIT_32BIT;
}
scene::CDynamicMeshBuffer * buffer = new scene::CDynamicMeshBuffer(video::EVT_STANDARD, indexType);
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Loading obj mesh files with 32bit index type

Post by robmar »

thanks, so how do you use that code, can you give an example?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Loading obj mesh files with 32bit index type

Post by Nadro »

You can also try shader-pipeline branch where you can easy convert indices type between 16 and 32.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Loading obj mesh files with 32bit index type

Post by robmar »

okay, which file is that in?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Loading obj mesh files with 32bit index type

Post by Nadro »

CIndexBuffer.h, method "void setType(video::E_INDEX_TYPE type)".
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Loading obj mesh files with 32bit index type

Post by robmar »

thought that was just for the dynamic mesh... will take a look, thanks for the tip!
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Loading obj mesh files with 32bit index type

Post by Nadro »

No, in shader-pipeline branch we have unified vertex/index buffer system. There is no division of dynamic/static mesh buffers in this branch.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
AReichl
Posts: 270
Joined: Wed Jul 13, 2011 2:34 pm

Re: Loading obj mesh files with 32bit index type

Post by AReichl »

Hi,

sorry to hijack this thread, but i have a similar problem with .stl files.
For a customer i want to write a viewer for his data with Irrlicht.

The files are HUGE.

I already have tried the shader-pipeline-branch, but probably i have
misunderstood something, because i get the same warnings about
16bit indizes. When i switch to DirectX11 i see nothing.

I had a look at the stl loader and it seems to me that i have to count
the indizes and THEN when they exceed 16bit switch to 32bit (like
the TerrainSceneNode does it internally). Is that right so?

That would mean that all loaders would have to be rewritten to
support 32bit indizes.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Loading obj mesh files with 32bit index type

Post by robmar »

Just change over to 32-bit, its the simple solution and there is no penalty on performance given that all the CPUs have 32-bit buses these days.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Loading obj mesh files with 32bit index type

Post by hendu »

Yes, there is obvious penalty even on latest GPUs, which is why any loader in the library needs to do such counting. For your own use, if you mainly load big models, you can just use 32bit ones.
AReichl
Posts: 270
Joined: Wed Jul 13, 2011 2:34 pm

Re: Loading obj mesh files with 32bit index type

Post by AReichl »

fine - but HOW?
The stl loader uses 16bit by default and does NOT switch to 32bit indizes when the limit of 16bit is reached.
Post Reply