Merge pull request #316 from tgnottingham/master

Allow numbers starting with decimal in fast_atof. Allow several spaces between numbers in OBJ files.
pull/321/head
Alexander Gessler 2014-07-23 16:10:07 +02:00
commit b7d46b29ad
4 changed files with 55 additions and 8 deletions

View File

@ -113,8 +113,8 @@ void ObjFileParser::parseFile()
getVector3(m_pModel->m_Vertices); getVector3(m_pModel->m_Vertices);
} else if (*m_DataIt == 't') { } else if (*m_DataIt == 't') {
// read in texture coordinate ( 2D or 3D ) // read in texture coordinate ( 2D or 3D )
++m_DataIt; ++m_DataIt;
getVector( m_pModel->m_TextureCoord ); getVector( m_pModel->m_TextureCoord );
} else if (*m_DataIt == 'n') { } else if (*m_DataIt == 'n') {
// Read in normal vector definition // Read in normal vector definition
++m_DataIt; ++m_DataIt;
@ -233,12 +233,13 @@ void ObjFileParser::copyNextLine(char *pBuffer, size_t length)
// ------------------------------------------------------------------- // -------------------------------------------------------------------
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) { void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
size_t numComponents( 0 ); size_t numComponents( 0 );
DataArrayIt tmp( m_DataIt ); const char* tmp( &m_DataIt[0] );
while( !IsLineEnd( *tmp ) ) { while( !IsLineEnd( *tmp ) ) {
if( *tmp == ' ' ) { if ( !SkipSpaces( &tmp ) ) {
++numComponents; break;
} }
tmp++; SkipToken( tmp );
++numComponents;
} }
float x, y, z; float x, y, z;
if( 2 == numComponents ) { if( 2 == numComponents ) {

View File

@ -229,14 +229,26 @@ inline uint64_t strtoul10_64( const char* in, const char** out=0, unsigned int*
template <typename Real> template <typename Real>
inline const char* fast_atoreal_move( const char* c, Real& out, bool check_comma = true) inline const char* fast_atoreal_move( const char* c, Real& out, bool check_comma = true)
{ {
Real f; Real f = 0;
bool inv = (*c == '-'); bool inv = (*c == '-');
if (inv || *c == '+') { if (inv || *c == '+') {
++c; ++c;
} }
f = static_cast<Real>( strtoul10_64 ( c, &c) ); if (!(c[0] >= '0' && c[0] <= '9') &&
!(c[0] == '.' && c[1] >= '0' && c[1] <= '9'))
{
throw std::invalid_argument("Cannot parse string "
"as real number: does not start with digit "
"or decimal point followed by digit.");
}
if (*c != '.')
{
f = static_cast<Real>( strtoul10_64 ( c, &c) );
}
if ((*c == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9') if ((*c == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9')
{ {
++c; ++c;

View File

@ -0,0 +1,11 @@
v 1.0 2.0 3.0
v 2.0 3.0 1.0
v 3.0 1.0 2.0
v 1.0 2.0 3.0
vt 1.0 2.0 3.0
vt 2.0 3.0 1.0
vt 3.0 1.0 2.0
vt 1.0 2.0 3.0
f 1 2 3

View File

@ -0,0 +1,23 @@
v 0 0 0
v 1 2. 3.0
v +1 +2. +3.0
v -1 -2. -3.0
v 1e2 2.e1 3.1e2
v +1e2 +2.e1 +3.1e2
v -1e2 -2.e1 -3.1e2
v 1e+2 2.e+1 3.1+e2
v +1e+2 +2.e+1 +3.1+e2
v -1e+2 -2.e+1 -3.1+e2
v 1e-2 2.e-1 3.1-e2
v +1e-2 +2.e-1 +3.1-e2
v -1e-2 -2.e-1 -3.1-e2
v 1e10 2.e01 3.1e10
v 1E2 2.E1 3.1E2
f 1 2 4