diff --git a/changes.txt b/changes.txt index cc289229..cab876bc 100644 --- a/changes.txt +++ b/changes.txt @@ -1,9 +1,12 @@ -------------------------- Changes in 1.9 (not yet released) +- stl meshloader can now load 32 bit buffers. + Thanks @Foaly for the patch (https://irrlicht.sourceforge.io/forum/viewtopic.php?f=9&t=51441) - Add IMeshBufffer::clone function to create buffer copies. CMeshManipulator::createMeshCopy uses that now and works now with all types of meshbuffers. - obj writer can now write 32 bit buffers - obj meshloader can now load 32 bit buffers when setIndexTypeHint is set correspondingly It's 16 bit meshes use now also an IDynamicMeshbuffer instead of an SMeshBuffer. + Thanks @Wol101 for original patch proposal (https://irrlicht.sourceforge.io/forum/viewtopic.php?f=9&t=51441) - Add IMeshLoader::setIndexTypeHint and getIndexTypeHint 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 diff --git a/source/Irrlicht/CSTLMeshFileLoader.cpp b/source/Irrlicht/CSTLMeshFileLoader.cpp index bf9ffb30..bd65703b 100644 --- a/source/Irrlicht/CSTLMeshFileLoader.cpp +++ b/source/Irrlicht/CSTLMeshFileLoader.cpp @@ -8,7 +8,7 @@ #include "CSTLMeshFileLoader.h" #include "SMesh.h" -#include "SMeshBuffer.h" +#include "CDynamicMeshBuffer.h" #include "SAnimatedMesh.h" #include "IReadFile.h" #include "fast_atof.h" @@ -41,7 +41,8 @@ IAnimatedMesh* CSTLMeshFileLoader::createMesh(io::IReadFile* file) return 0; SMesh* mesh = new SMesh(); - SMeshBuffer* meshBuffer = new SMeshBuffer(); + CDynamicMeshBuffer* meshBuffer = new CDynamicMeshBuffer(video::EVT_STANDARD, video::EIT_16BIT); + IVertexBuffer& vertBuffer = meshBuffer->getVertexBuffer(); mesh->addMeshBuffer(meshBuffer); meshBuffer->drop(); @@ -132,29 +133,41 @@ IAnimatedMesh* CSTLMeshFileLoader::createMesh(io::IReadFile* file) #endif } - SMeshBuffer* mb = reinterpret_cast(mesh->getMeshBuffer(mesh->getMeshBufferCount()-1)); - u32 vCount = mb->getVertexCount(); video::SColor color(0xffffffff); if (attrib & 0x8000) color = video::A1R5G5B5toA8R8G8B8(attrib); if (normal==core::vector3df()) normal=core::plane3df(vertex[2],vertex[1],vertex[0]).Normal; - mb->Vertices.push_back(video::S3DVertex(vertex[2],normal,color, core::vector2df())); - mb->Vertices.push_back(video::S3DVertex(vertex[1],normal,color, core::vector2df())); - mb->Vertices.push_back(video::S3DVertex(vertex[0],normal,color, core::vector2df())); - mb->Indices.push_back(vCount); - mb->Indices.push_back(vCount+1); - mb->Indices.push_back(vCount+2); + vertBuffer.push_back(video::S3DVertex(vertex[2],normal,color, core::vector2df())); + vertBuffer.push_back(video::S3DVertex(vertex[1],normal,color, core::vector2df())); + vertBuffer.push_back(video::S3DVertex(vertex[0],normal,color, core::vector2df())); } // end while (file->getPos() < filesize) - mesh->getMeshBuffer(0)->recalculateBoundingBox(); // Create the Animated mesh if there's anything in the mesh SAnimatedMesh* pAM = 0; if ( 0 != mesh->getMeshBufferCount() ) { + IIndexBuffer& indexBuffer = meshBuffer->getIndexBuffer(); + u32 vertCount = vertBuffer.size(); + if (vertCount > 65535 ) // Note 65535 instead of 65536 as it divides by 3 + { + if ( getIndexTypeHint() != EITH_16BIT ) + indexBuffer.setType(video::EIT_32BIT); + else + { + // Could split buffer, but probably no one really needs this anymore now with 32-bit support and necessary buffer manipulation functions are not there yet + vertCount = 65535; + } + } + + indexBuffer.reallocate(vertCount); + for (u32 i=0; irecalculateBoundingBox(); mesh->recalculateBoundingBox(); pAM = new SAnimatedMesh(); - pAM->Type = EAMT_OBJ; + pAM->Type = EAMT_STATIC; pAM->addMesh(mesh); pAM->recalculateBoundingBox(); }