Skip to content
Snippets Groups Projects
Commit 468672ea authored by Martin Schultz's avatar Martin Schultz
Browse files

fixes #2200

* tabs and spaces can be used to seperate objects
* emptylines dont cause warnigns anymore
parent a7340b9a
No related branches found
No related tags found
No related merge requests found
......@@ -65,20 +65,35 @@ namespace
return r;
}
void trim(const char*& _position)
{
while(*_position == ' ' || *_position == '\t')
_position ++;
}
const char * nextObject(const char* _position, const char* _end)
{
return std::find_if(_position,
_end,
[](char _value)
{
return (_value == ' ' || _value == '\t');
}
);
}
// Parses a string of space-separated numbers into a packed floating-point vector (_data) with a maximum number of _maxDimension elements
void parseVector(const char* _start , const char* _end, int _maxDimension, int& _dimension, float* _data)
{
const char* it = _start;
if (*it == ' ')
{
it++;
}
const char* end = _end;
const char* found;
_dimension = 0;
while (_dimension < _maxDimension && it < end)
{
found = std::find(it, end, ' ');
trim(it);
found = nextObject(it,end);
_data[_dimension++] = fastAtof(it,found-1);
it = found == end ? end : found + 1;
}
......@@ -92,8 +107,7 @@ namespace
indices.reserve(5);
const char* it = _start;
if (*it == ' ') //skip starting whitespace
it++;
trim(it);
const char* vsit;
const char* vsend;
const char* foundSlash;
......@@ -102,12 +116,13 @@ namespace
while (it < _end)
{
vsit = it;
vsend = std::find(it, _end, ' ');
vsend = nextObject(it, _end);
componentIndex = 0;
IndexTuple indexTuple;
//process the string now meaning we split by /
while (vsit < vsend)
{
trim(vsit);
foundSlash = std::find(vsit, vsend, '/');
index = std::atoi(vsit);
if (componentIndex == 0) indexTuple.position = index - 1;
......@@ -117,7 +132,8 @@ namespace
vsit = foundSlash == vsend ? vsend : foundSlash + 1;
}
indices.push_back(indexTuple);
it = vsend == _end ? _end : vsend + 1;
trim(vsend);
it = vsend;
}
return indices;
}
......@@ -160,21 +176,23 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c
const char* parameters[2];
while (pchBuf < pchEnd)
{
trim(pchBuf);
// Parse the current line
const char* pchEOL = std::find(pchBuf, pchEnd, '\n');
// If the line starts with a #, it is a comment
if (*pchBuf == '#')
// skip empty lines or lines starting with #
if (*pchBuf == '#' || pchBuf == pchEOL)
{
pchBuf = pchEOL + 1;
continue;
}
// Otherwise, extract the first word and the remainder
const char* pchKey = std::find(pchBuf, pchEnd, ' ');
const char* pchKey = nextObject(pchBuf, pchEnd);
keyword = pchBuf;
keywordLength = pchKey - pchBuf;//std::string(pchBuf, pchKey);
parameters[0] = pchKey + 1;
keywordLength = pchKey - pchBuf;
trim(pchKey);
parameters[0] = pchKey;
parameters[1] = pchEOL;
if(strncmp(keyword,"v",keywordLength) == 0) // vertex position
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment