Page 1 of 2

Loading obj mesh files with 32bit index type

Posted: Sun Aug 15, 2010 2:19 pm
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?

Posted: Sun Aug 15, 2010 8:26 pm
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.

Posted: Sun Aug 15, 2010 9:48 pm
by hybrid
For obj this is indeed really simple. Just add some groups into your mesh, Irrlicht will load groups into different meshbuffers.

Re: Loading obj mesh files with 32bit index type

Posted: Mon Apr 15, 2013 4:42 pm
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.

Re: Loading obj mesh files with 32bit index type

Posted: Mon Apr 15, 2013 9:37 pm
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);

Re: Loading obj mesh files with 32bit index type

Posted: Tue Apr 16, 2013 6:17 pm
by robmar
thanks, so how do you use that code, can you give an example?

Re: Loading obj mesh files with 32bit index type

Posted: Wed Apr 24, 2013 2:00 pm
by Nadro
You can also try shader-pipeline branch where you can easy convert indices type between 16 and 32.

Re: Loading obj mesh files with 32bit index type

Posted: Wed Apr 24, 2013 6:50 pm
by robmar
okay, which file is that in?

Re: Loading obj mesh files with 32bit index type

Posted: Thu Apr 25, 2013 3:20 pm
by Nadro
CIndexBuffer.h, method "void setType(video::E_INDEX_TYPE type)".

Re: Loading obj mesh files with 32bit index type

Posted: Thu Apr 25, 2013 10:20 pm
by robmar
thought that was just for the dynamic mesh... will take a look, thanks for the tip!

Re: Loading obj mesh files with 32bit index type

Posted: Fri Apr 26, 2013 7:05 pm
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.

Re: Loading obj mesh files with 32bit index type

Posted: Thu Nov 12, 2015 8:18 pm
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.

Re: Loading obj mesh files with 32bit index type

Posted: Thu Nov 12, 2015 8:28 pm
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.

Re: Loading obj mesh files with 32bit index type

Posted: Thu Nov 12, 2015 9:07 pm
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.

Re: Loading obj mesh files with 32bit index type

Posted: Fri Nov 13, 2015 9:00 am
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.