void CMD5Model::LoadModel( const std::string& a_Path, const std::string& a_SubFolder ) { if ( CFile::FileExists( a_Path.c_str() ) == false ) { CLog::GetInstance()->OutMessage( "Model file does not exist (%s)", CLog::MESSAGETYPE_ERROR, a_Path.c_str() ); } m_SubFolder = a_SubFolder; CFlatFile modelFile; modelFile.Open( a_Path.c_str(), CFile::FILEMODE_READ, CFile::FILETYPE_PLAIN ); CFileHandler fileHandler; fileHandler.LinkFile( &modelFile ); std::string data; std::string dataTwo; Uint position = modelFile.GetPosition(); data = fileHandler.ReadString(); while ( ( position = modelFile.GetPosition() ) < modelFile.GetSize() ) { if ( data == "MD5Version" ) { dataTwo = fileHandler.ReadString(); Int versionNumber = atoi( dataTwo.c_str() ); assert( versionNumber == 10 && "Incorrect version number in MD5file" ); } else if ( data == "commandline" ) { //We don't need this so skip dataTwo = fileHandler.ReadString(); } else if ( data == "numJoints" ) { dataTwo = fileHandler.ReadString(); m_JointCount = atoi( dataTwo.c_str() ); } else if ( data == "numMeshes" ) { dataTwo = fileHandler.ReadString(); m_MeshCount = atoi( dataTwo.c_str() ); } else if ( data == "joints" ) { //Read out all the joint SJoint joint; data = fileHandler.ReadString(); data = fileHandler.ReadString(); for ( Uint i = 0; i < m_JointCount; ++i ) { joint.m_Name = fileHandler.ReadString(); joint.m_Name.pop_back(); joint.m_Name.erase( joint.m_Name.begin() ); data = fileHandler.ReadString(); joint.m_ParentID = atoi( data.c_str() ); data = fileHandler.ReadString(); for ( Uint j = 0; j < 3; ++j ) { data = fileHandler.ReadString(); joint.m_Position.Cell[j] = (Float)atof( data.c_str() ); } data = fileHandler.ReadString(); data = fileHandler.ReadString(); for ( Uint j = 0; j < 3; ++j ) { data = fileHandler.ReadString(); joint.m_Orientation.Cell[j] = (Float)atof( data.c_str() ); } joint.m_Orientation.ComputeW(); data = fileHandler.ReadString(); data = fileHandler.ReadString(); m_Joints.push_back( joint ); } //} data = fileHandler.ReadString(); } else if ( data == "mesh" ) { //Read the mesh SMesh* mesh = LoadMesh( fileHandler ); //Prepare the mesh and generate normals PrepareMesh( mesh ); PrepareNormals( mesh ); //Generate rendering buffers CreateBuffers( mesh ); CreateVAO( mesh ); m_Meshes.push_back( mesh ); } data = fileHandler.ReadString(); } }
const Bool CWAVFile::LoadFromFile( const Char* a_FilePath ) { m_FilePath += a_FilePath; CFlatFile file; CFileHandler fileHandler; //Open the file file.Open( a_FilePath, CFile::FILEMODE_READ, CFile::FILETYPE_BINARY ); //Link the file to the filehandler fileHandler.LinkFile( &file ); //Read out the header ( yay for templates ) fileHandler.Read<CWAVFile::SWaveHeader>( &m_Header ); CLog* log = CLog::GetInstance(); //Check chunkID Char* chunkID = (Char*)&m_Header.m_ChunkID; if ( strncmp( chunkID, "RIFF", 4 ) != 0 ) { log->OutMessage( "ChunkID does not correspond to RIFF", CLog::MESSAGETYPE_WARNING ); return false; } //Check chunkSize if ( m_Header.m_ChunkSize != file.GetSize() - 8 ) { log->OutMessage( "Filesize does not match size defined in the header", CLog::MESSAGETYPE_WARNING ); return false; } Char* formatString = (Char*)&m_Header.m_Format; //Check format if ( strncmp( "WAVE", formatString, 4 ) != 0 ) { log->OutMessage( "Format does not correspond to WAVE", CLog::MESSAGETYPE_WARNING ); return false; } const Char* subChunkOneID = (Char*)&m_Header.m_SubChunkOneID; //Check subchunk ID if ( strncmp( "fmt", subChunkOneID, 3 ) != 0 ) { log->OutMessage( "ChunkOne ID does not match fmt", CLog::MESSAGETYPE_WARNING ); return false; } //Check subchunk size if ( m_Header.m_SubChunkOneSize != 16 ) { log->OutMessage( "ChunkOne size does not match the PCM value ( 16 ), others are not supported", CLog::MESSAGETYPE_WARNING ); return false; } //Check audio format if ( m_Header.m_AudioFormat != 1 ) { log->OutMessage( "Audio format not match the PCM value ( 1 ), others are not supported", CLog::MESSAGETYPE_WARNING ); return false; } //Check Channel count if ( m_Header.m_ChannelCount == 0 ) { log->OutMessage( "No audio channels found in the header", CLog::MESSAGETYPE_WARNING ); return false; } Int bytesPerSample = m_Header.m_BitsPerSample / 8; //Check if byterate matches other values if ( m_Header.m_ByteRate != ( m_Header.m_SampleRate * m_Header.m_ChannelCount * bytesPerSample ) ) { log->OutMessage( "Byterate does not match other values in header", CLog::MESSAGETYPE_WARNING ); return false; } //Block allignment if ( m_Header.m_BlockAllignment != ( m_Header.m_ChannelCount * bytesPerSample ) ) { log->OutMessage( "Block allignment does not match other values in header", CLog::MESSAGETYPE_WARNING ); return false; } //Check for valid bbp if ( bytesPerSample != 1 && bytesPerSample != 2 ) { log->OutMessage( "BBp value is not support only 8;16 are supported", CLog::MESSAGETYPE_WARNING ); return false; } //Reading of chunks const Char* subChunkID = (Char*)&m_Header.m_SubChunkTwoID; while ( strncmp( subChunkID, "data", 4 ) != 0 ) { int currentPosition = file.GetPosition(); file.Skip( m_Header.m_SubChunkTwoSize ); fileHandler.Read<Int>( m_Header.m_SubChunkTwoID, 1 ); fileHandler.Read<Int>( m_Header.m_SubChunkTwoSize, 1 ); } ////Check subchunk ID //if ( m_Header.m_SubChunkTwoID != _byteswap_ulong( 0x64617461 ) ) //{ // //log->OutMessage( "ChunkTwo ID does not match data", CLog::MESSAGETYPE_WARNING ); // //return false; //} ////Check subchunk size //if ( m_Header.m_SubChunkTwoSize != ( file.GetSize() - sizeof( SWaveHeader ) ) ) //{ // log->OutMessage( "ChunkTwo size does not match the filesize", CLog::MESSAGETYPE_WARNING ); //} //Everything is correct so now read out the data m_Data = new Char[m_Header.m_SubChunkTwoSize]; fileHandler.Read<Char>( m_Data, m_Header.m_SubChunkTwoSize ); //Check if we reached the end of the file if ( file.GetPosition() == file.GetSize() ) { file.Close(); } else { log->OutMessage( "End of file not reached", CLog::MESSAGETYPE_WARNING ); file.Close(); } //Calculate samplecount m_SampleCount = m_Header.m_SubChunkTwoSize / ( m_Header.m_ChannelCount * bytesPerSample ); m_DataSize = m_Header.m_SubChunkTwoSize; return true; }