Commit 468672ea authored by Martin Schultz's avatar Martin Schultz

fixes #2200

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