From b10141887f6c755f0f9897587b2489ebb72296f5 Mon Sep 17 00:00:00 2001 From: cutealien Date: Sat, 16 Mar 2024 16:32:50 +0000 Subject: [PATCH] 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 --- changes.txt | 1 + source/Irrlicht/COBJMeshFileLoader.cpp | 15 +++++++++++---- tests/tests-last-passed-at.txt | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/changes.txt b/changes.txt index e9aeb8a5..6087eb4e 100644 --- a/changes.txt +++ b/changes.txt @@ -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 diff --git a/source/Irrlicht/COBJMeshFileLoader.cpp b/source/Irrlicht/COBJMeshFileLoader.cpp index b7de81bd..ed1aaf48 100644 --- a/source/Irrlicht/COBJMeshFileLoader.cpp +++ b/source/Irrlicht/COBJMeshFileLoader.cpp @@ -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); diff --git a/tests/tests-last-passed-at.txt b/tests/tests-last-passed-at.txt index 1697fe69..57a930f3 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 Thu Feb 29 13:39:39 2024 +Test suite pass at GMT Sat Mar 16 16:24:16 2024