void C3DSLoader::ReadNextObjChunk(t3DModel *pModel, t3DObject *pObject, tChunk *pPreChunk)   
{      
	int buffer[50000] = {0};              
	m_CurrentChunk = new tChunk;   
  
	while (pPreChunk->bytesRead < pPreChunk->length)   
	{      
		ReadChunk(m_CurrentChunk);   
  
		switch (m_CurrentChunk->ID)   
		{   
		case OBJ_MESH:                   
			ReadNextObjChunk(pModel, pObject, m_CurrentChunk);   
			break;   
		case OBJ_VERTICES:             
			ReadVertices(pObject, m_CurrentChunk);   
			break;   
		case OBJ_FACES:                  
			ReadVertexIndices(pObject, m_CurrentChunk);   
			break;   
		case OBJ_MATERIAL:              
			ReadObjMat(pModel, pObject, m_CurrentChunk);               
			break;   
		case OBJ_UV:                      
			ReadUVCoordinates(pObject, m_CurrentChunk);   
			break;   
		default:     
			m_CurrentChunk->bytesRead += fread(buffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);   
			break;   
		}      
		pPreChunk->bytesRead += m_CurrentChunk->bytesRead;   
	}   
	delete m_CurrentChunk;   
	m_CurrentChunk = pPreChunk;   
}   
Exemple #2
0
void CLoad3DS::ProcessNextObjectChunk(t3DModel *pModel, t3DObject *pObject, tChunk *pPreviousChunk)
{
	// The current chunk to work with
	tChunk currentChunk = {0};

	// Continue to read these chunks until we read the end of this sub chunk
	while (pPreviousChunk->bytesRead < pPreviousChunk->length)
	{
		// Read the next chunk
		ReadChunk(&currentChunk);

		// Check which chunk we just read
		switch (currentChunk.ID)
		{
		case OBJECT_MESH:					// This lets us know that we are reading a new object
		
			// We found a new object, so let's read in it's info using recursion
			ProcessNextObjectChunk(pModel, pObject, &currentChunk);
			break;

		case OBJECT_VERTICES:				// This is the objects vertices
			ReadVertices(pObject, &currentChunk);
			break;

		case OBJECT_FACES:					// This is the objects face information
			ReadVertexIndices(pObject, &currentChunk);
			break;

		case OBJECT_MATERIAL:				// This holds the material name that the object has
			
			// This chunk holds the name of the material that the object has assigned to it.
			// This could either be just a color or a texture map.  This chunk also holds
			// the faces that the texture is assigned to (In the case that there is multiple
			// textures assigned to one object, or it just has a texture on a part of the object.
			// Since most of my game objects just have the texture around the whole object, and 
			// they aren't multitextured, I just want the material name.

			// We now will read the name of the material assigned to this object
			ReadObjectMaterial(pModel, pObject, &currentChunk);			
			break;

		case OBJECT_UV:						// This holds the UV texture coordinates for the object

			// This chunk holds all of the UV coordinates for our object.  Let's read them in.
			ReadUVCoordinates(pObject, &currentChunk);
			break;

		default:  

			// Read past the ignored or unknown chunks
			currentChunk.bytesRead += fread(gBuffer, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer);
			break;
		}

		// Add the bytes read from the last chunk to the previous chunk passed in.
		pPreviousChunk->bytesRead += currentChunk.bytesRead;
	}
}
Exemple #3
0
void ModelLoader::ProcessNextObjectChunk(Model3DS *pModel, Object3DS *pObject, Chunk *pPreviousChunk)
{
	// The current chunk to work with
	Chunk currentChunk = {0};

	// Continue to read these chunks until we read the end of this sub chunk
	while (pPreviousChunk->bytesRead < pPreviousChunk->length){
		// Read the next chunk
		ReadChunk(&currentChunk);

		// Check which chunk we just read
		switch (currentChunk.ID){
		case OBJECT_MESH:
		
			// This case means we hit a new object, so jump in again and read this next chunk
			ProcessNextObjectChunk(pModel, pObject, &currentChunk);
			break;

		case OBJECT_VERTICES:
			// Object vertices
			ReadVertices(pObject, &currentChunk);
			break;

		case OBJECT_FACES:
			// Object faces
			ReadVertexIndices(pObject, &currentChunk);
			break;

		case OBJECT_MATERIAL:

			// This chunk stores both texture information, or color information
			// depending on the object.  At the moment we'll just support textures
			// so we'll read in the name of the texture and build it later.  If there
			// is just color we'll not bother then.

			ReadObjectMaterial(pModel, pObject, &currentChunk);			
			break;

		case OBJECT_UV:
			// UV coordinates
			ReadUVCoordinates(pObject, &currentChunk);
			break;

		default:  

			// Ignored chunk, read past it.
			currentChunk.bytesRead += fread(m_Buffer, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer);
			break;
		}

		// Add the bytes read from the last chunk to the previous chunk passed in.
		pPreviousChunk->bytesRead += currentChunk.bytesRead;
	}
}
Exemple #4
0
void ProcessNextObjectChunk(Loader3ds *pt3ds,tChunk *pPreviousChunk) 
{
	tChunk currentChunk = {0}; 
 
	while (pPreviousChunk->bytesRead < pPreviousChunk->length) 
	{ 
		// Read the next chunk 
		ReadChunk(pt3ds,&currentChunk); 
		switch (currentChunk.ID) 
		{ 
		case OBJECT_MESH:
 
			// We found a new object so use recursion 
			ProcessNextObjectChunk(pt3ds,&currentChunk); 
			break; 
 
		case OBJECT_VERTICES:				// 4110This is the objects vertices 
 
			ReadVertices(pt3ds,&currentChunk); 
			break; 
 
		case OBJECT_FACES:					// 4120This is the objects face information 
 
			ReadVertexIndices(pt3ds,&currentChunk); 
			break; 
 
		case OBJECT_MATERIAL:		

			ReadObjectMaterial(pt3ds,&currentChunk);			 
			break; 
 
		case OBJECT_UV:						// 4140This holds the UV texture coordinates for the object 
 
			ReadUVCoordinates(pt3ds,&currentChunk); 
			break; 
 
		case OBJECT_TRANSF:					// 4160 
 
			ReadObjectTransf(pt3ds,&currentChunk); 
			break; 
 
		default:   
 
			currentChunk.bytesRead += fread(pt3ds->gBuffer, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); 
			break; 
		} 
 
		pPreviousChunk->bytesRead += currentChunk.bytesRead; 
	} 
} 
void CLoad3DS::ProcessNextObjectChunk(t3DModel *pModel, t3DObject *pObject, tChunk *pPreviousChunk)
{
//	int buffer[50000] = {0};
//	int *buffer = new int[50000];

	m_CurrentChunk = new tChunk;

	while (pPreviousChunk->bytesRead < pPreviousChunk->length)
	{
	
		ReadChunk(m_CurrentChunk);

		switch (m_CurrentChunk->ID)
		{
		case OBJECT_MESH:				
			ProcessNextObjectChunk(pModel, pObject, m_CurrentChunk);
			break;

		case OBJECT_VERTICES:		
			ReadVertices(pObject, m_CurrentChunk);
			break;

		case OBJECT_FACES:				
			ReadVertexIndices(pObject, m_CurrentChunk);
			break;

		case OBJECT_MATERIAL:
			ReadObjectMaterial(pModel, pObject, m_CurrentChunk);			
			break;

		case OBJECT_UV:	
			ReadUVCoordinates(pObject, m_CurrentChunk);
			break;

		default:  
//			m_CurrentChunk->bytesRead += ASSET_READ(buffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);
			ASSET_SEEK(m_FilePointer, m_CurrentChunk->length - m_CurrentChunk->bytesRead, SEEK_CUR);
			m_CurrentChunk->bytesRead += (m_CurrentChunk->length - m_CurrentChunk->bytesRead);
			break;
		}

		pPreviousChunk->bytesRead += m_CurrentChunk->bytesRead;
	}

	delete m_CurrentChunk;
	
	m_CurrentChunk = pPreviousChunk;
//	delete []buffer;
}
//  下面的函数处理所有的文件中对象的信息
void CLoad3DS::ReadNextObjChunk(t3DModel *pModel, t3DObject *pObject, tChunk *pPreChunk)
{ 
	int buffer[50000] = {0};     // 用于读入不需要的数据
	// 对新的块分配存储空间
	m_CurrentChunk = new tChunk;

	// 继续读入块的内容直至本子块结束
	while (pPreChunk->bytesRead < pPreChunk->length)
	{ // 读入下一个块
		ReadChunk(m_CurrentChunk);
		// 区别读入是哪种块
		switch (m_CurrentChunk->ID)
		{
		case OBJ_MESH:     // 正读入的是一个新块
			// 使用递归函数调用,处理该新块
			ReadNextObjChunk(pModel, pObject, m_CurrentChunk);
			break;
		case OBJ_VERTICES:    // 读入是对象顶点
			ReadVertices(pObject, m_CurrentChunk);
			break;
		case OBJ_FACES:     // 读入的是对象的面
			ReadVertexIndices(pObject, m_CurrentChunk);
			break;
		case OBJ_MATERIAL:    // 读入的是对象的材质名称
			// 该块保存了对象材质的名称,可能是一个颜色,也可能是一个纹理映射。同时在该块中也保存了
			// 纹理对象所赋予的面
			// 下面读入对象的材质名称
			ReadObjMat(pModel, pObject, m_CurrentChunk);   
			break;
		case OBJ_UV:      // 读入对象的UV纹理坐标
			// 读入对象的UV纹理坐标
			ReadUVCoordinates(pObject, m_CurrentChunk);
			break;
		default:  
			// 略过不需要读入的块
			m_CurrentChunk->bytesRead += fread(buffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);
			break;
		}
		// 添加从最后块中读入的字节数到前面的读入的字节中
		pPreChunk->bytesRead += m_CurrentChunk->bytesRead;
	}
	// 释放当前块的内存空间,并把当前块设置为前面块
	delete m_CurrentChunk;
	m_CurrentChunk = pPreChunk;
}
Exemple #7
0
void Loaders::t3DSLoader::ProcessNextObjectChunk(t3DModel *pModel, t3DObject *pObject, tChunk *pPreviousChunk)
{
    m_CurrentChunk = new tChunk;

    while (pPreviousChunk->bytesRead < pPreviousChunk->length)
    {
        ReadChunk(m_CurrentChunk);

        switch (m_CurrentChunk->ID)
        {
        case OBJECT_MESH:
            ProcessNextObjectChunk(pModel, pObject, m_CurrentChunk);
            break;
        case OBJECT_VERTICES:
            ReadVertices(pObject, m_CurrentChunk);
            break;
        case OBJECT_FACES:
            ReadVertexIndices(pObject, m_CurrentChunk);
            break;
        case OBJECT_MATERIAL:
            ReadObjectMaterial(pModel, pObject, m_CurrentChunk);
            break;
        case OBJECT_UV:
            ReadUVCoordinates(pObject, m_CurrentChunk);
            break;
        default:
            m_CurrentChunk->bytesRead += fread(gBuffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);
            break;
        }

        pPreviousChunk->bytesRead += m_CurrentChunk->bytesRead;
    }

    delete m_CurrentChunk;
    m_CurrentChunk = pPreviousChunk;
}
Exemple #8
0
//=================================================================================================================================
/// Loads a mesh from an OBJ file
/// \param strFileName   The file name to load from
/// \param rVerticesOut  A set of vertices that is created from the OBJ
/// \param rFacesOut     A set of faces that is created from the OBJ
//=================================================================================================================================
bool ObjLoader::LoadGeometry(const char* strFileName, std::vector<ObjVertexFinal>& rVerticesOut, std::vector<ObjFace>& rFacesOut)
{
    //----------------------------------------------------------------------
    // Data
    //----------------------------------------------------------------------
    std::vector<ObjVertex3D> vertices;
    std::vector<ObjVertex3D> normals;
    std::vector<ObjVertex2D> texCoords;

    bool bHasTexCoords = false;
    bool bHasNormals   = false;

    char cLine[256];    //A line of the obj file

    //----------------------------------------------------------------------
    // Read OBJ file
    //----------------------------------------------------------------------
    FILE* pFile = fopen(strFileName, "rt");

    // Check if the file was opened
    if (NULL == pFile)
    {
        // Open failed
        return (false);

    } // end if ( NULL == pFile )

    //Read until we hit the end of the file
    while (!feof(pFile))
    {
        //Check the first char in the line
        int iStart = fgetc(pFile);

        // skip blank lines
        while ((iStart == 10) && (!feof(pFile))) { iStart = fgetc(pFile); }

        if (feof(pFile))
        {
            break;
        }

        //If the first letter is v, it is either a vertex, a text coord, or a vertex normal
        if (iStart == 'v')
        {
            //get the second char
            int iNext = fgetc(pFile);

            //if its a space, its a vertex coordinate
            if (iNext == ' ' || iNext == '\t')
            {
                ObjVertex3D vertex;

                //get the line
                fgets(cLine, 256, pFile);

                //get the vertex coords
                sscanf(cLine, " %f %f %f", &vertex.x, &vertex.y, &vertex.z);

                //add to the vertex array
                vertices.push_back(vertex);
            } // End if

            //if its a t, its a texture coord
            else if (iNext == 't')
            {
                ObjVertex2D texCoord;

                //get the line
                fgets(cLine, 256, pFile);

                //get the vertex coords
                sscanf(cLine, " %f %f", &texCoord.x, &texCoord.y);

                //add to the vertex array
                texCoords.push_back(texCoord);

                bHasTexCoords = true;
            } // End else if

            //if its an n its a normal
            else if (iNext == 'n')
            {
                ObjVertex3D normal;

                //get the line
                fgets(cLine, 256, pFile);

                //get the vertex coords
                sscanf(cLine, " %f %f %f", &normal.x, &normal.y, &normal.z);

                //add to the vertex array
                normals.push_back(normal);

                bHasNormals = true;
            } // End else if

            //else its something we don't support
            else
            {
                //scan the line and discard it
                fgets(cLine, 256, pFile);
            } // End else
        } // End if

        //if the first letter is f, its a face
        else if (iStart == 'f')
        {
            //read in the line
            fgets(cLine, 256, pFile);

            int numVerts = GetNumberOfVerticesInLine(cLine);

            int vertexIndices[256];
            int texCoordIndices[256];
            int normalIndices[256];

            assert(numVerts < 256);
            assert(numVerts > 0);

            ReadVertexIndices(cLine, numVerts, bHasTexCoords, bHasNormals,
                              vertexIndices, texCoordIndices, normalIndices);

            int fCount; // face count

            // Create triangles.
            //
            // Make a triangle fan if more than 3 vertices are specified
            //
            // If there are 3 vertices, 1 triangle
            // If there are 4 vertices, 2 triangles
            // If there are 5 vertices, 3 triangles
            // :
            for (fCount = 0; fCount < numVerts - 2; fCount++)
            {
                ObjFace face;
                face.vertexIndices[0] = vertexIndices[0];
                face.vertexIndices[1] = vertexIndices[fCount + 1];
                face.vertexIndices[2] = vertexIndices[fCount + 2];

                face.texCoordIndices[0] = texCoordIndices[0];
                face.texCoordIndices[1] = texCoordIndices[fCount + 1];
                face.texCoordIndices[2] = texCoordIndices[fCount + 2];

                face.normalIndices[0] = normalIndices[0];
                face.normalIndices[1] = normalIndices[fCount + 1];
                face.normalIndices[2] = normalIndices[fCount + 2];

                rFacesOut.push_back(face);
            } // End for
        } // End else if

        //if it isn't any of those, we don't care about it
        else
        {
            //read the whole line to advance
            fgets(cLine, 256, pFile);
        } // End else
    } // End while

    fclose(pFile);

    BuildFinalVertices(vertices, normals, texCoords, rFacesOut, rVerticesOut);

    return true;
} // End of LoadGeometry for CRmObjLoaderPlugIn