32 Bit OBJ File reading

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Wol101
Posts: 9
Joined: Sat Apr 23, 2016 6:39 am

32 Bit OBJ File reading

Post 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
 
 
CuteAlien
Admin
Posts: 9746
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: 32 Bit OBJ File reading

Post 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).
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
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: 32 Bit OBJ File reading

Post by mongoose7 »

Probably better to use more groups if the mesh is that big.
AReichl
Posts: 270
Joined: Wed Jul 13, 2011 2:34 pm

Re: 32 Bit OBJ File reading

Post 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.
CuteAlien
Admin
Posts: 9746
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: 32 Bit OBJ File reading

Post 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.
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
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Re: 32 Bit OBJ File reading

Post 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.
CuteAlien
Admin
Posts: 9746
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: 32 Bit OBJ File reading

Post by CuteAlien »

Sure post it and preferably also post a test-model so it's easy to check if it works.
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
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Re: 32 Bit OBJ File reading

Post by Foaly »

Last edited by Foaly on Sun Feb 11, 2018 9:28 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9746
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: 32 Bit OBJ File reading

Post by CuteAlien »

thanks!
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
CuteAlien
Admin
Posts: 9746
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: 32 Bit OBJ File reading

Post 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...)
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