diff --git a/changes.txt b/changes.txt index 166e34a..1aa4b1d 100644 --- a/changes.txt +++ b/changes.txt @@ -1,5 +1,8 @@ -------------------------- Changes in 1.9 (not yet released) +- obj meshloader can now load 32-bit buffers when setPreferredIndexType is set to EIT_32BIT. + It's 16 bit meshes use now also an IDynamicMeshbuffer instead of an SMeshBuffer. +- Add IMeshLoader::setPreferredIndexType and getPreferredIndexType to allow setting hints for the loaders if users prefer 16 or 32 bit meshbuffers. - Add IMeshBuffer::getType to allow finding out which class type a meshbuffer has (similar to ISceneNode::getType). - Add IGUIImage::flip to flip/mirror images - IBillboardSceneNode got functions to access meshbuffers. So uv-coordinates can now be modified directly (previously only possible via texture matrix). diff --git a/include/IMeshLoader.h b/include/IMeshLoader.h index 25df3ef..065d76e 100644 --- a/include/IMeshLoader.h +++ b/include/IMeshLoader.h @@ -8,6 +8,7 @@ #include "IReferenceCounted.h" #include "path.h" #include "IMeshTextureLoader.h" +#include "SVertexIndex.h" namespace irr { @@ -29,7 +30,7 @@ class IMeshLoader : public virtual IReferenceCounted public: //! Constructor - IMeshLoader() : TextureLoader(0) {} + IMeshLoader() : TextureLoader(0), PreferredIndexType(video::EIT_16BIT) {} //! Destructor virtual ~IMeshLoader() @@ -78,8 +79,30 @@ public: return TextureLoader; } + //! Give loader a hint if you would prefer 16 or 32 bit meshbuffers. + /** + Generally Irrlicht works with 16-bit meshbuffers so far. + Rendering 32-bit meshbuffers works, other functions like + mesh-writing and mesh manipulation might not work yet. + NOTE: Most loaders will ignore this hint so far, but hopefully + will care about it in the future. + */ + void setPreferredIndexType(irr::video::E_INDEX_TYPE typeHint) + { + PreferredIndexType = typeHint; + } + + //! Return current preference user has for the index-size of meshbuffers + /** Note that this is _not_ necessarily the type used by the meshloader */ + irr::video::E_INDEX_TYPE getPreferredIndexType() const + { + return PreferredIndexType; + } + + protected: IMeshTextureLoader* TextureLoader; + irr::video::E_INDEX_TYPE PreferredIndexType; }; diff --git a/source/Irrlicht/COBJMeshFileLoader.cpp b/source/Irrlicht/COBJMeshFileLoader.cpp index 2efe70d..2249716 100644 --- a/source/Irrlicht/COBJMeshFileLoader.cpp +++ b/source/Irrlicht/COBJMeshFileLoader.cpp @@ -82,7 +82,7 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) core::array > normalsBuffer(1000); core::array > textureCoordBuffer(1000); - SObjMtl * currMtl = new SObjMtl(); + SObjMtl * currMtl = new SObjMtl(PreferredIndexType); Materials.push_back(currMtl); u32 smoothingGroup=0; @@ -224,6 +224,8 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) v.Color = currMtl->Meshbuffer->Material.DiffuseColor; // get all vertices data in this face (current line of obj file) + IVertexBuffer& mbVertexBuffer = currMtl->Meshbuffer->getVertexBuffer(); + IIndexBuffer& mbIndexBuffer = currMtl->Meshbuffer->getIndexBuffer(); const core::stringc wordBuffer = copyLine(bufPtr, bufEnd); const c8* linePtr = wordBuffer.c_str(); const c8* const endPtr = linePtr+wordBuffer.size(); @@ -272,8 +274,8 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) } else { - currMtl->Meshbuffer->Vertices.push_back(v); - vertLocation = currMtl->Meshbuffer->Vertices.size() -1; + mbVertexBuffer.push_back(v); + vertLocation = mbVertexBuffer.size() -1; currMtl->VertMap.insert(v, vertLocation); } @@ -292,9 +294,9 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) const int b = faceCorners[i]; if (a != b && a != c && b != c) // ignore degenerated faces. We can get them when we merge vertices above in the VertMap. { - currMtl->Meshbuffer->Indices.push_back(a); - currMtl->Meshbuffer->Indices.push_back(b); - currMtl->Meshbuffer->Indices.push_back(c); + mbIndexBuffer.push_back(a); + mbIndexBuffer.push_back(b); + mbIndexBuffer.push_back(c); } else { @@ -577,7 +579,7 @@ void COBJMeshFileLoader::readMTL(const c8* fileName, const io::path& relPath) c8 mtlNameBuf[WORD_BUFFER_LENGTH]; bufPtr = goAndCopyNextWord(mtlNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd); - currMaterial = new SObjMtl; + currMaterial = new SObjMtl(PreferredIndexType); currMaterial->Name = mtlNameBuf; } break; diff --git a/source/Irrlicht/COBJMeshFileLoader.h b/source/Irrlicht/COBJMeshFileLoader.h index e7c9fbf..2954056 100644 --- a/source/Irrlicht/COBJMeshFileLoader.h +++ b/source/Irrlicht/COBJMeshFileLoader.h @@ -9,7 +9,7 @@ #include "IFileSystem.h" #include "ISceneManager.h" #include "irrString.h" -#include "SMeshBuffer.h" +#include "CDynamicMeshBuffer.h" #include "irrMap.h" namespace irr @@ -42,10 +42,10 @@ private: struct SObjMtl { - SObjMtl() : Meshbuffer(0), Bumpiness (1.0f), Illumination(0), + SObjMtl(irr::video::E_INDEX_TYPE indexType) : IndexType(indexType), Meshbuffer(0), Bumpiness (1.0f), Illumination(0), RecalculateNormals(false) { - Meshbuffer = new SMeshBuffer(); + Meshbuffer = new CDynamicMeshBuffer(irr::video::EVT_STANDARD, IndexType); Meshbuffer->Material.Shininess = 0.0f; Meshbuffer->Material.AmbientColor = video::SColorf(0.2f, 0.2f, 0.2f, 1.0f).toSColor(); Meshbuffer->Material.DiffuseColor = video::SColorf(0.8f, 0.8f, 0.8f, 1.0f).toSColor(); @@ -53,16 +53,17 @@ private: } SObjMtl(const SObjMtl& o) - : Name(o.Name), Group(o.Group), + : IndexType(o.IndexType), Name(o.Name), Group(o.Group), Bumpiness(o.Bumpiness), Illumination(o.Illumination), RecalculateNormals(false) { - Meshbuffer = new SMeshBuffer(); + Meshbuffer = new CDynamicMeshBuffer(irr::video::EVT_STANDARD, IndexType); Meshbuffer->Material = o.Meshbuffer->Material; } core::map VertMap; - scene::SMeshBuffer *Meshbuffer; + irr::video::E_INDEX_TYPE IndexType; + scene::CDynamicMeshBuffer *Meshbuffer; core::stringc Name; core::stringc Group; f32 Bumpiness; diff --git a/tests/tests-last-passed-at.txt b/tests/tests-last-passed-at.txt index 8d385b7..28eb413 100644 --- a/tests/tests-last-passed-at.txt +++ b/tests/tests-last-passed-at.txt @@ -1,4 +1,4 @@ Tests finished. 72 tests of 72 passed. Compiled as DEBUG -Test suite pass at GMT Wed Apr 06 20:16:43 2022 +Test suite pass at GMT Thu Apr 14 13:52:29 2022