From e7c7e3634784e5ec6ddb88965d3d848414da9e61 Mon Sep 17 00:00:00 2001 From: cutealien Date: Wed, 22 Dec 2021 16:19:59 +0000 Subject: [PATCH] obj file loader now allows using mtl files with spaces in the filename. mtllib commands previously used only the first word, now they use the rest of the line. Different obj format descriptions describe the mtllib command in 2 different ways: - http://paulbourke.net says it can load several mtl files separated by spaces - Wikipedia says it can load one mtl file (but there can be several mtllib commands) We previously loaded 1 file - using the name up to the first space character, so it basically was not correct for either solution. We now go with Wikipedia, because it allows using space in filenames and I tested several other tools and they all handled it like this. Also COBJMeshFileLoader::copyLine no longer copies the newline character (didn't do that always anyway and we don't need it) git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6275 dfc29bdd-3216-0410-991c-e03cc46cb475 --- changes.txt | 3 +++ source/Irrlicht/COBJMeshFileLoader.cpp | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) 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