Rename IMeshLoader::setPreferredIndexType to setIndexTypeHint and give it a new enum.

Giving the loader it's own enum allowed me to add more options. 
EITH_OPTIMAL which reduces buffers back to 16-bit if they don't need 32-bit.
Using that in obj loader.
Also 32-bit meshes with EMT_PARALLAX_MAP_SOLID material should now work in obj loader (untested as I got no test-case)


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6340 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2022-04-19 13:10:16 +00:00
parent d484711f2e
commit 24f2a1e9ab
4 changed files with 37 additions and 19 deletions

@ -2,9 +2,9 @@
Changes in 1.9 (not yet released) Changes in 1.9 (not yet released)
- Add IMeshBufffer::clone function to create buffer copies. CMeshManipulator::createMeshCopy uses that now and works now with all types of meshbuffers. - 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 writer can now write 32 bit buffers
- obj meshloader can now load 32 bit buffers when setPreferredIndexType is set to EIT_32BIT. - 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. 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 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 IMeshBuffer::getType to allow finding out which class type a meshbuffer has (similar to ISceneNode::getType).
- Add IGUIImage::flip to flip/mirror images - 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). - IBillboardSceneNode got functions to access meshbuffers. So uv-coordinates can now be modified directly (previously only possible via texture matrix).

@ -30,7 +30,7 @@ class IMeshLoader : public virtual IReferenceCounted
public: public:
//! Constructor //! Constructor
IMeshLoader() : TextureLoader(0), PreferredIndexType(video::EIT_16BIT) {} IMeshLoader() : TextureLoader(0), IndexTypeHint(EITH_16BIT) {}
//! Destructor //! Destructor
virtual ~IMeshLoader() virtual ~IMeshLoader()
@ -79,6 +79,20 @@ public:
return TextureLoader; return TextureLoader;
} }
enum E_INDEX_TYPE_HINT
{
//! Prefer to use 16-bit index buffers even if it breaks the mesh
EITH_16BIT,
//! Allow using 32-bit index buffers
EITH_32BIT,
//! Allow 32-bit, but copy back to 16-bit when 32 is not needed.
//! So tiny overhead on loading, but meshes are later more optimal
EITH_OPTIMAL
};
//! Give loader a hint if you would prefer 16 or 32 bit meshbuffers. //! Give loader a hint if you would prefer 16 or 32 bit meshbuffers.
/** /**
Generally Irrlicht works with 16-bit meshbuffers so far. Generally Irrlicht works with 16-bit meshbuffers so far.
@ -87,22 +101,22 @@ public:
NOTE: Most loaders will ignore this hint so far, but hopefully NOTE: Most loaders will ignore this hint so far, but hopefully
will care about it in the future. will care about it in the future.
*/ */
void setPreferredIndexType(irr::video::E_INDEX_TYPE typeHint) void setIndexTypeHint(E_INDEX_TYPE_HINT typeHint)
{ {
PreferredIndexType = typeHint; IndexTypeHint = typeHint;
} }
//! Return current preference user has for the index-size of meshbuffers //! Return current preference user has for the index type of meshbuffers
/** Note that this is _not_ necessarily the type used by the meshloader */ /** Note that this is _not_ necessarily the type used by the meshloader */
irr::video::E_INDEX_TYPE getPreferredIndexType() const E_INDEX_TYPE_HINT getIndexTypeHint() const
{ {
return PreferredIndexType; return IndexTypeHint;
} }
protected: protected:
IMeshTextureLoader* TextureLoader; IMeshTextureLoader* TextureLoader;
irr::video::E_INDEX_TYPE PreferredIndexType; E_INDEX_TYPE_HINT IndexTypeHint;
}; };

@ -82,7 +82,7 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
core::array<core::vector3df, core::irrAllocatorFast<core::vector3df> > normalsBuffer(1000); core::array<core::vector3df, core::irrAllocatorFast<core::vector3df> > normalsBuffer(1000);
core::array<core::vector2df, core::irrAllocatorFast<core::vector2df> > textureCoordBuffer(1000); core::array<core::vector2df, core::irrAllocatorFast<core::vector2df> > textureCoordBuffer(1000);
SObjMtl * currMtl = new SObjMtl(PreferredIndexType); SObjMtl * currMtl = new SObjMtl(getIndexTypeHint());
Materials.push_back(currMtl); Materials.push_back(currMtl);
u32 smoothingGroup=0; u32 smoothingGroup=0;
@ -330,19 +330,21 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
{ {
if ( Materials[m]->Meshbuffer->getIndexCount() > 0 ) if ( Materials[m]->Meshbuffer->getIndexCount() > 0 )
{ {
if ( getIndexTypeHint() == EITH_OPTIMAL
&& Materials[m]->Meshbuffer->getVertexCount() <= 65536 )
{
Materials[m]->Meshbuffer->getIndexBuffer().setType(video::EIT_16BIT);
}
Materials[m]->Meshbuffer->recalculateBoundingBox(); Materials[m]->Meshbuffer->recalculateBoundingBox();
if (Materials[m]->RecalculateNormals) if (Materials[m]->RecalculateNormals)
SceneManager->getMeshManipulator()->recalculateNormals(Materials[m]->Meshbuffer); SceneManager->getMeshManipulator()->recalculateNormals(Materials[m]->Meshbuffer);
if (Materials[m]->Meshbuffer->Material.MaterialType == video::EMT_PARALLAX_MAP_SOLID) if (Materials[m]->Meshbuffer->Material.MaterialType == video::EMT_PARALLAX_MAP_SOLID)
{ {
SMesh tmp; Materials[m]->Meshbuffer->getVertexBuffer().setType(video::EVT_TANGENTS);
tmp.addMeshBuffer(Materials[m]->Meshbuffer);
IMesh* tangentMesh = SceneManager->getMeshManipulator()->createMeshWithTangents(&tmp);
mesh->addMeshBuffer(tangentMesh->getMeshBuffer(0));
tangentMesh->drop();
} }
else mesh->addMeshBuffer( Materials[m]->Meshbuffer );
mesh->addMeshBuffer( Materials[m]->Meshbuffer );
} }
} }
@ -579,7 +581,7 @@ void COBJMeshFileLoader::readMTL(const c8* fileName, const io::path& relPath)
c8 mtlNameBuf[WORD_BUFFER_LENGTH]; c8 mtlNameBuf[WORD_BUFFER_LENGTH];
bufPtr = goAndCopyNextWord(mtlNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd); bufPtr = goAndCopyNextWord(mtlNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
currMaterial = new SObjMtl(PreferredIndexType); currMaterial = new SObjMtl(getIndexTypeHint());
currMaterial->Name = mtlNameBuf; currMaterial->Name = mtlNameBuf;
} }
break; break;

@ -42,7 +42,9 @@ private:
struct SObjMtl struct SObjMtl
{ {
SObjMtl(irr::video::E_INDEX_TYPE indexType) : IndexType(indexType), Meshbuffer(0), Bumpiness (1.0f), Illumination(0), SObjMtl(E_INDEX_TYPE_HINT typeHint)
: IndexType(typeHint == EITH_16BIT ? video::EIT_16BIT : video::EIT_32BIT)
, Meshbuffer(0), Bumpiness (1.0f), Illumination(0),
RecalculateNormals(false) RecalculateNormals(false)
{ {
Meshbuffer = new CDynamicMeshBuffer(irr::video::EVT_STANDARD, IndexType); Meshbuffer = new CDynamicMeshBuffer(irr::video::EVT_STANDARD, IndexType);