diff --git a/changes.txt b/changes.txt index c5cd5630..65fff1b7 100644 --- a/changes.txt +++ b/changes.txt @@ -1,5 +1,8 @@ -------------------------- Changes in 1.9 (not yet released) +- obj file loader now allows using mtl files with spaces in the filename. + Note that this means it no longer handles obj files which have multiple mtl files behind the mtllib command. + But Irrlicht ignored all but the first name anyway and this way of handling mtllib commands seems to be more common. - Many defines changed because they were using names which are reserved identifiers in c++. Mostly it's about replacing __IRRxxx or _IRRxxx identifiers by versions without underscores Sometimes underscores at end also got removed. diff --git a/source/Irrlicht/COBJMeshFileLoader.cpp b/source/Irrlicht/COBJMeshFileLoader.cpp index 2d9ac9c8..2efe70dc 100644 --- a/source/Irrlicht/COBJMeshFileLoader.cpp +++ b/source/Irrlicht/COBJMeshFileLoader.cpp @@ -114,12 +114,18 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) { if (useMaterials) { - c8 name[WORD_BUFFER_LENGTH]; - bufPtr = goAndCopyNextWord(name, bufPtr, WORD_BUFFER_LENGTH, bufEnd); + // Bit fuzzy definition. Some doc (http://paulbourke.net) says there can be more then one file and they are separated by spaces + // Other doc (Wikipedia) says it's one file. Which does allow loading mtl files with spaces in the name. + // Other tools I tested seem to go with the Wikipedia definition + // Irrlicht did just use first word in Irrlicht 1.8, but with 1.9 we switch to allowing filenames with spaces + // If this turns out to cause troubles we can maybe try to catch those cases by looking for ".mtl " inside the string + const c8 * inBuf = goNextWord(bufPtr, bufEnd, false); + core::stringc name = copyLine(inBuf, bufEnd); + #ifdef _IRR_DEBUG_OBJ_LOADER_ os::Printer::log("Reading material file",name); #endif - readMTL(name, relPath); + readMTL(name.c_str(), relPath); } } break; @@ -545,7 +551,7 @@ void COBJMeshFileLoader::readMTL(const c8* fileName, const io::path& relPath) const long filesize = mtlReader->getSize(); if (!filesize) { - os::Printer::log("Skipping empty material file", realFile, ELL_WARNING); + os::Printer::log("Skipping empty material file", realFile, ELL_INFORMATION); // it's fine some tools export empty mtl files mtlReader->drop(); return; } @@ -871,12 +877,11 @@ core::stringc COBJMeshFileLoader::copyLine(const c8* inBuf, const c8* bufEnd) const c8* ptr = inBuf; while (ptr