Ejemplo n.º 1
0
// -------------------------------------------------------------------
//	File parsing method.
void ObjFileParser::parseFile()
{
	if (m_DataIt == m_DataItEnd)
		return;

	while (m_DataIt != m_DataItEnd)
	{
		switch (*m_DataIt)
		{
		case 'v': // Parse a vertex texture coordinate
			{
				++m_DataIt;
				if (*m_DataIt == ' ' || *m_DataIt == '\t') {
					// read in vertex definition
					getVector3(m_pModel->m_Vertices);
				} else if (*m_DataIt == 't') {
					// read in texture coordinate ( 2D or 3D )
                    ++m_DataIt;
                    getVector( m_pModel->m_TextureCoord );
				} else if (*m_DataIt == 'n') {
					// Read in normal vector definition
					++m_DataIt;
					getVector3( m_pModel->m_Normals );
				}
			}
			break;

		case 'p': // Parse a face, line or point statement
		case 'l':
		case 'f':
			{
				getFace(*m_DataIt == 'f' ? aiPrimitiveType_POLYGON : (*m_DataIt == 'l' 
					? aiPrimitiveType_LINE : aiPrimitiveType_POINT));
			}
			break;

		case '#': // Parse a comment
			{
				getComment();
			}
			break;

		case 'u': // Parse a material desc. setter
			{
				getMaterialDesc();
			}
			break;

		case 'm': // Parse a material library or merging group ('mg')
			{
				if (*(m_DataIt + 1) == 'g')
					getGroupNumberAndResolution();
				else
					getMaterialLib();
			}
			break;

		case 'g': // Parse group name
			{
				getGroupName();
			}
			break;

		case 's': // Parse group number
			{
				getGroupNumber();
			}
			break;

		case 'o': // Parse object name
			{
				getObjectName();
			}
			break;
		
		default:
			{
				m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
			}
			break;
		}
	}
}
Ejemplo n.º 2
0
// -------------------------------------------------------------------
//  File parsing method.
void ObjFileParser::parseFile()
{
    if (m_DataIt == m_DataItEnd)
        return;

    // only update every 100KB or it'll be too slow
    const unsigned int updateProgressEveryBytes = 100 * 1024;
    unsigned int progressCounter = 0;
    const unsigned int bytesToProcess = std::distance(m_DataIt, m_DataItEnd);
    const unsigned int progressTotal = 3 * bytesToProcess;
    const unsigned int progressOffset = bytesToProcess;
    unsigned int processed = 0;

    DataArrayIt lastDataIt = m_DataIt;

    while (m_DataIt != m_DataItEnd)
    {
        // Handle progress reporting
        processed += std::distance(lastDataIt, m_DataIt);
        lastDataIt = m_DataIt;
        if (processed > (progressCounter * updateProgressEveryBytes))
        {
            progressCounter++;
            m_progress->UpdateFileRead(progressOffset + processed*2, progressTotal);
        }

        // parse line
        switch (*m_DataIt)
        {
        case 'v': // Parse a vertex texture coordinate
            {
                ++m_DataIt;
                if (*m_DataIt == ' ' || *m_DataIt == '\t') {
                    size_t numComponents = getNumComponentsInLine();
                    if (numComponents == 3) {
                        // read in vertex definition
                        getVector3(m_pModel->m_Vertices);
                    } else if (numComponents == 6) {
                        // read vertex and vertex-color
                        getTwoVectors3(m_pModel->m_Vertices, m_pModel->m_VertexColors);
                    }
                } else if (*m_DataIt == 't') {
                    // read in texture coordinate ( 2D or 3D )
                                        ++m_DataIt;
                                        getVector( m_pModel->m_TextureCoord );
                } else if (*m_DataIt == 'n') {
                    // Read in normal vector definition
                    ++m_DataIt;
                    getVector3( m_pModel->m_Normals );
                }
            }
            break;

        case 'p': // Parse a face, line or point statement
        case 'l':
        case 'f':
            {
                getFace(*m_DataIt == 'f' ? aiPrimitiveType_POLYGON : (*m_DataIt == 'l'
                    ? aiPrimitiveType_LINE : aiPrimitiveType_POINT));
            }
            break;

        case '#': // Parse a comment
            {
                getComment();
            }
            break;

        case 'u': // Parse a material desc. setter
            {
                getMaterialDesc();
            }
            break;

        case 'm': // Parse a material library or merging group ('mg')
            {
                if (*(m_DataIt + 1) == 'g')
                    getGroupNumberAndResolution();
                else
                    getMaterialLib();
            }
            break;

        case 'g': // Parse group name
            {
                getGroupName();
            }
            break;

        case 's': // Parse group number
            {
                getGroupNumber();
            }
            break;

        case 'o': // Parse object name
            {
                getObjectName();
            }
            break;

        default:
            {
                m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
            }
            break;
        }
    }
}