obj/mtl loader no longer messes up bump textures when the name starts with a number

Mtl loader was assuming bump textures starting with a number are always using that to scale the bump.
No idea if there are mtl files out there assuming that, but usually scaling parameter is -bm
But it always assumed real filename was following, so as compromise I still allow pure numbers (no other characters following) to be scaling parameters.

Also mtl file can now handle map_Bump on top of map_bump and bump (NASA model assets use that sometimes)


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6602 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2024-03-16 16:32:50 +00:00
parent ac341472d6
commit b10141887f
3 changed files with 13 additions and 5 deletions

View File

@ -1,6 +1,7 @@
--------------------------
Changes in 1.9 (not yet released)
- obj/mtl loader no longer messes up bump textures when the name starts with a number
- CImageLoaderBMP now supports loading 1-bit images with palette data
- Hardware meshbuffers are now deleted when they hold the last reference to a meshbuffer
- Variable order inside SMaterial and SMaterialLayer changed for better packing

View File

@ -387,9 +387,9 @@ const c8* COBJMeshFileLoader::readTextures(const c8* bufPtr, const c8* const buf
// map_Ks - specular color texture map
// map_Ka - ambient color texture map
// map_Ns - shininess texture map
if ((!strncmp(bufPtr,"map_bump",8)) || (!strncmp(bufPtr,"bump",4)))
if (!strncmp(bufPtr,"map_bump",8) || !strncmp(bufPtr,"map_Bump",8) || !strncmp(bufPtr,"bump",4))
type=1; // normal map
else if ((!strncmp(bufPtr,"map_d",5)) || (!strncmp(bufPtr,"map_opacity",11)))
else if (!strncmp(bufPtr,"map_d",5) || !strncmp(bufPtr,"map_opacity",11))
type=2; // opacity map
else if (!strncmp(bufPtr,"map_refl",8))
type=3; // reflection map
@ -487,8 +487,15 @@ const c8* COBJMeshFileLoader::readTextures(const c8* bufPtr, const c8* const buf
if ((type==1) && (core::isdigit(textureNameBuf[0])))
{
currMaterial->Meshbuffer->Material.MaterialTypeParam=core::fast_atof(textureNameBuf);
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
// Haven't found that in any official mtl description, usually bump parameter should only be after -bm
// But I'll leave it (with added checks in 1.9) as maybe there are some exporters doing this and likely can't be a valid filename
const char *out=0;
irr::f32 bumpScale = core::fast_atof(textureNameBuf, &out);
if ( *out == 0 ) // name is only a number
{
currMaterial->Meshbuffer->Material.MaterialTypeParam=bumpScale;
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
}
}
if (clamp)
currMaterial->Meshbuffer->Material.setFlag(video::EMF_TEXTURE_WRAP, video::ETC_CLAMP);

View File

@ -1,4 +1,4 @@
Tests finished. 72 tests of 72 passed.
Compiled as DEBUG
Test suite pass at GMT Thu Feb 29 13:39:39 2024
Test suite pass at GMT Sat Mar 16 16:24:16 2024