stl meshloader can now load 32 bit buffers (with corresponding hint)

Thanks @Foaly for the patch (https://irrlicht.sourceforge.io/forum/viewtopic.php?f=9&t=51441)
Applied with some minor changes.
Also mesh-type in that loader now set to EAMT_STATIC (was EAMT_OBJ before, probably some copy-pasting going on).


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6342 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2022-04-19 21:32:11 +00:00
parent a2bb74096d
commit 3ce2f0c0dd
2 changed files with 28 additions and 12 deletions

View File

@ -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

View File

@ -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<SMeshBuffer*>(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; i<vertCount; ++i) //every vertex is unique, so we can just generate the indices
indexBuffer.push_back(i);
meshBuffer->recalculateBoundingBox();
mesh->recalculateBoundingBox();
pAM = new SAnimatedMesh();
pAM->Type = EAMT_OBJ;
pAM->Type = EAMT_STATIC;
pAM->addMesh(mesh);
pAM->recalculateBoundingBox();
}