From 62c9347985eb38cbbb68f31c0e636ac9f02691be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20P=C5=99ibyl?= Date: Tue, 22 Feb 2022 01:32:41 +0100 Subject: [PATCH] fixed obj parsing with cstype --- code/AssetLib/Obj/ObjFileParser.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/code/AssetLib/Obj/ObjFileParser.cpp b/code/AssetLib/Obj/ObjFileParser.cpp index 2e998a815..f819f326a 100644 --- a/code/AssetLib/Obj/ObjFileParser.cpp +++ b/code/AssetLib/Obj/ObjFileParser.cpp @@ -117,6 +117,7 @@ void ObjFileParser::parseFile(IOStreamBuffer &streamBuffer) { unsigned int processed = 0; size_t lastFilePos(0); + bool insideCstype = false; std::vector buffer; while (streamBuffer.getNextDataLine(buffer, '\\')) { m_DataIt = buffer.begin(); @@ -131,6 +132,23 @@ void ObjFileParser::parseFile(IOStreamBuffer &streamBuffer) { m_progress->UpdateFileRead(processed, progressTotal); } + // handle cstype (http://paulbourke.net/dataformats/obj/) which contains parm property which is handled by the parser as fase, but is not + // cstype bspline + // deg 1 + // curv 0 4.4342367553943109 468085 ... + // parm u 0 0 0.39203731404307385 ... + // end + if (insideCstype) { + switch (*m_DataIt) { + case 'e': { + std::string name; + getNameNoSpace(m_DataIt, m_DataItEnd, name); + insideCstype = name != "end"; + } break; + } + goto pf_skip_line; + } + // parse line switch (*m_DataIt) { case 'v': // Parse a vertex texture coordinate @@ -219,6 +237,14 @@ void ObjFileParser::parseFile(IOStreamBuffer &streamBuffer) { getObjectName(); } break; + case 'c': + { + std::string name; + getNameNoSpace(m_DataIt, m_DataItEnd, name); + insideCstype = name == "cstype"; + goto pf_skip_line; + } break; + default: { pf_skip_line: m_DataIt = skipLine(m_DataIt, m_DataItEnd, m_uiLine);