This commit is contained in:
Kim Kulling
2017-05-31 21:37:42 +02:00
7 changed files with 115 additions and 47 deletions

View File

@@ -109,7 +109,7 @@ ObjFile::Model *ObjFileParser::GetModel() const {
return m_pModel;
}
void ignoreNewLines(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer)
/*void ignoreNewLines(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer)
{
auto curPosition = buffer.begin();
do
@@ -123,13 +123,13 @@ void ignoreNewLines(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffe
std::vector<char> tempBuf;
do
{
streamBuffer.getNextLine(tempBuf);
streamBuffer.getNextDataLine(tempBuf, '\\' );
} while (tempBuf[0]=='\n');
*curPosition = ' ';
std::copy(tempBuf.cbegin(), tempBuf.cend(), ++curPosition);
}
} while (*curPosition!='\n');
}
}*/
void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
// only update every 100KB or it'll be too slow
@@ -142,7 +142,7 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
size_t lastFilePos( 0 );
std::vector<char> buffer;
while ( streamBuffer.getNextLine( buffer ) ) {
while ( streamBuffer.getNextDataLine( buffer, '\\' ) ) {
m_DataIt = buffer.begin();
m_DataItEnd = buffer.end();
@@ -161,7 +161,7 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
{
++m_DataIt;
if (*m_DataIt == ' ' || *m_DataIt == '\t') {
size_t numComponents = getNumComponentsInLine();
size_t numComponents = getNumComponentsInDataDefinition();
if (numComponents == 3) {
// read in vertex definition
getVector3(m_pModel->m_Vertices);
@@ -245,7 +245,6 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
default:
{
pf_skip_line:
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
break;
@@ -274,21 +273,45 @@ void ObjFileParser::copyNextWord(char *pBuffer, size_t length) {
pBuffer[index] = '\0';
}
size_t ObjFileParser::getNumComponentsInLine() {
static bool isDataDefinitionEnd( const char *tmp ) {
if ( *tmp == '\\' ) {
tmp++;
if ( IsLineEnd( *tmp ) ) {
tmp++;
return true;
}
}
return false;
}
size_t ObjFileParser::getNumComponentsInDataDefinition() {
size_t numComponents( 0 );
const char* tmp( &m_DataIt[0] );
while( !IsLineEnd( *tmp ) ) {
bool end_of_definition = false;
while ( !end_of_definition ) {
//while( !IsLineEnd( *tmp ) ) {
if ( isDataDefinitionEnd( tmp ) ) {
tmp += 2;
} else if ( IsLineEnd( *tmp ) ) {
end_of_definition = true;
}
if ( !SkipSpaces( &tmp ) ) {
break;
}
const bool isNum( IsNumeric( *tmp ) );
SkipToken( tmp );
++numComponents;
if ( isNum ) {
++numComponents;
}
if ( !SkipSpaces( &tmp ) ) {
break;
}
}
return numComponents;
}
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
size_t numComponents = getNumComponentsInLine();
size_t numComponents = getNumComponentsInDataDefinition();
ai_real x, y, z;
if( 2 == numComponents ) {
copyNextWord( m_buffer, Buffersize );
@@ -571,14 +594,16 @@ void ObjFileParser::getMaterialDesc() {
// -------------------------------------------------------------------
// Get a comment, values will be skipped
void ObjFileParser::getComment() {
while (m_DataIt != m_DataItEnd) {
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
/* while (m_DataIt != m_DataItEnd) {
if ( '\n' == (*m_DataIt)) {
++m_DataIt;
break;
} else {
++m_DataIt;
}
}
}*/
}
// -------------------------------------------------------------------