bool ACAMTLoader::LoadFromFile( const CHAR* path, AMT_MODEL* outModel) { // open the file mpFile = fopen( path, "rb" ); if( !mpFile ) return false; ReadHeader(outModel); ReadVertices(outModel); ReadFaces(outModel); ReadMesh(outModel); ReadMaterials(outModel); ReadJoints(outModel); ReadAnimations(outModel); return CloseFile( true ); };
/* ============= MD5Model::InitMD5ModelWithMesh Initializes MD5Model with the mesh at the path. ============= */ bool MD5Model::InitMD5ModelWithMesh( const char* path ) { if ( !ValidMD5MeshExtension( path ) ) { printf( "Not a valid MD5Mesh extension\n" ); return false; } char* fileData = FileOperations::ReadFileToCharBuffer( path ); if ( fileData == NULL ) { //File wasn't opened printf( "Mesh at path '%s' could not be opened\n", path ); return false; } else { printf( "Beginning load of: %s\n", path ); modelName = path; unsigned slash = modelName.find_last_of( "/" ) + 1; unsigned dot = modelName.find_last_of( "." ); modelName = modelName.substr( slash, dot - slash ); char* nextLineToken = NULL; char* currentLine = strtok_s( fileData, "\n", &nextLineToken ); while ( currentLine != NULL ) { char* nextParam = NULL; char* currentParam = strtok_s( currentLine, " ", &nextParam ); if ( STRINGS_ARE_EQUAL( currentParam, "MD5Version" ) ) { //Read the version nextParam[2] = '\0'; //Truncate to 2 chars if ( !STRINGS_ARE_EQUAL( nextParam, "10" ) ) { printf( "Only MD5Version 10 is supported\n" ); delete[] fileData; return false; } } else if ( STRINGS_ARE_EQUAL( currentParam, "numJoints" ) ) { //Read numjoints int numJoints = std::atoi( nextParam ); joints.resize( numJoints ); blendSkeleton.joints.resize( numJoints ); blendSkeleton.jointMatricies.resize( numJoints ); } else if ( STRINGS_ARE_EQUAL( currentParam, "numMeshes" ) ) { //Read nummeshes int numMeshes = std::atoi( nextParam ); meshes.reserve( numMeshes ); } else if ( STRINGS_ARE_EQUAL( currentParam, "joints" ) ) { //Read joints if ( joints.size() == 0 ) { printf( "numJoints was not specified\n" ); delete[] fileData; return false; } nextLineToken = ReadJoints( nextLineToken ); } else if ( STRINGS_ARE_EQUAL( currentParam, "mesh" ) ) { //Read a mesh nextLineToken = ReadMesh( nextLineToken ); } currentLine = strtok_s( NULL, "\n", &nextLineToken ); } GenerateBindPoseMatricies(); printf( " MD5Mesh file parsed\n" ); printf( " Joint count:\t%i\n", joints.size() ); printf( " Mesh count:\t%i\n", meshes.size() ); printf( "Successfully Loaded MD5Mesh: %s\n", path ); } delete[] fileData; return SetupMatrixTextureBuffer(); }