Page 1 of 1

32 Bit OBJ File reading

Posted: Tue Jul 05, 2016 9:48 am
by Wol101
Here is a quick patch to allow the 1.9 COBJMeshFileLoader.cpp to cope with bigger meshes. All it does is replace the SMeshBuffer with a 32 bit CDynamicMeshBuffer as used in some of the other asset loaders. There will be a small performance hit in this simple implementation because it doesn't check the number of vertices and use the appropriate index size. I doubt it will make much difference in practice since if you are in a situation where you have large meshes to deal with you obviously have the hardware to cope! The OBJ loader is fairly slow anyway but it's not a high performance asset format (a binary format that tells you how many items there are before you try and read them would be much quicker). That's the cost of flexibility and simplicity.

Code: Select all

 
diff -r1.1.1.1 COBJMeshFileLoader.cpp
262,263c262,267
<                   currMtl->Meshbuffer->Vertices.push_back(v);
<                   vertLocation = currMtl->Meshbuffer->Vertices.size() -1;
---
>                   // patch - altered to allow bigger meshes
>                   currMtl->Meshbuffer->getVertexBuffer().push_back(v);
>                   vertLocation = currMtl->Meshbuffer->getVertexBuffer().size() -1;
>                   // currMtl->Meshbuffer->Vertices.push_back(v);
>                   // vertLocation = currMtl->Meshbuffer->Vertices.size() -1;
>                   // ~patch - altered to allow bigger meshes
277,279c281,288
<               currMtl->Meshbuffer->Indices.push_back( faceCorners[i+1] );
<               currMtl->Meshbuffer->Indices.push_back( faceCorners[i] );
<               currMtl->Meshbuffer->Indices.push_back( faceCorners[0] );
---
>               // patch - altered to allow bigger meshes
>               currMtl->Meshbuffer->getIndexBuffer().push_back( faceCorners[i+1] );
>               currMtl->Meshbuffer->getIndexBuffer().push_back( faceCorners[i] );
>               currMtl->Meshbuffer->getIndexBuffer().push_back( faceCorners[0] );
>               // currMtl->Meshbuffer->Indices.push_back( faceCorners[i+1] );
>               // currMtl->Meshbuffer->Indices.push_back( faceCorners[i] );
>               // currMtl->Meshbuffer->Indices.push_back( faceCorners[0] );
>               // ~patch - altered to allow bigger meshes
 
diff -r1.1.1.1 COBJMeshFileLoader.h
12c12,15
< #include "SMeshBuffer.h"
---
> // patch - altered to allow bigger meshes
> #include "CDynamicMeshBuffer.h"
> //#include "SMeshBuffer.h"
> // ~patch - altered to allow bigger meshes
48c51,54
<           Meshbuffer = new SMeshBuffer();
---
>           // patch - altered to allow bigger meshes
>           Meshbuffer = new CDynamicMeshBuffer(irr::video::EVT_STANDARD, irr::video::EIT_32BIT);
>           //Meshbuffer = new SMeshBuffer();
>           // ~patch - altered to allow bigger meshes
60c66,69
<           Meshbuffer = new SMeshBuffer();
---
>           // patch - altered to allow bigger meshes
>           Meshbuffer = new CDynamicMeshBuffer(irr::video::EVT_STANDARD, irr::video::EIT_32BIT);
>           //Meshbuffer = new SMeshBuffer();
>           // ~patch - altered to allow bigger meshes
65c74,77
<       scene::SMeshBuffer *Meshbuffer;
---
>       // patch - altered to allow bigger meshes
>       scene::CDynamicMeshBuffer *Meshbuffer;
>       // scene::SMeshBuffer *Meshbuffer;
>       // ~patch - altered to allow bigger meshes
 
 

Re: 32 Bit OBJ File reading

Posted: Tue Jul 05, 2016 10:56 am
by CuteAlien
Thanks. Do you have some test-model you could share for this? (not to include to Irrlicht, just for me to test the code)

edit: Hm, not good to always use a 32-bit meshbuffer. In general having 16-bit is still prefered (faster to transfer 16-bit meshes to gpu).

Re: 32 Bit OBJ File reading

Posted: Tue Jul 05, 2016 11:13 am
by mongoose7
Probably better to use more groups if the mesh is that big.

Re: 32 Bit OBJ File reading

Posted: Tue Jul 05, 2016 11:25 am
by AReichl
I once had changed the .stl loader to SWITCH to a 32-bit buffer if the number of loaded vertices was bigger than 65000.

Re: 32 Bit OBJ File reading

Posted: Tue Jul 05, 2016 12:00 pm
by CuteAlien
@AReichl: Hm, we didn't apply that yet I guess. Do you have the link to that? Or was it just a private thing? Btw - several of NASA recently release free models are STL!
@mongoose7: Generally aggreed. But won't hurt if Irrlicht can load larger meshes, just 16-bit should stay default.

Re: 32 Bit OBJ File reading

Posted: Tue Jul 05, 2016 6:52 pm
by Foaly
I also have a version of the stl loader which allows 32 bit indices, I can post it here if you need it.
But it's actually quite simple, because the stl format doesn't use indices at all, so they can be generated afterwards.

Re: 32 Bit OBJ File reading

Posted: Tue Jul 05, 2016 8:00 pm
by CuteAlien
Sure post it and preferably also post a test-model so it's easy to check if it works.

Re: 32 Bit OBJ File reading

Posted: Wed Jul 06, 2016 10:08 am
by Foaly

Re: 32 Bit OBJ File reading

Posted: Wed Jul 06, 2016 10:24 am
by CuteAlien
thanks!

Re: 32 Bit OBJ File reading

Posted: Tue Apr 19, 2022 9:50 pm
by CuteAlien
32-bit meshbuffer reading for .obj and .stl now both added. Since [r6343] it's even the new default. I modified both patches a bit. Especially .obj file now copies back to 16-bit when it doesn't need 32-bit buffers (cost for that was rather neglectable even with lots of meshbuffers).
Other loaders not yet updated - feed me more patches! (and I'll try to take less than half a decade next time...)