32 Bit OBJ File reading
Posted: Tue Jul 05, 2016 9:48 am
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