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;   
}   
Exemplo n.º 2
0
//  下面的函数处理所有的文件中对象的信息
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;
}