CMesh* Load3ds::Create(char * aFilename) { mCurrentChunk = new Chunk; // initialize any other members you choose to add mModelData = new ModelData; // create the mesh that will store the 3d model information mMesh = new CMesh; mFile = fopen(aFilename, "rb"); ReadChunk(mCurrentChunk); if (mCurrentChunk->mID != PRIMARY) exit(1107); // Largest possible buffer we'd need is MAX_INDICES * sizeof(triangle) mBuffer = new unsigned char[65536 * 3 * sizeof(float)]; // Begin loading objects, by calling recursive function ProcessNextChunk(mCurrentChunk); // All data read, compile them into a friendly format CompileObjects(); // Clean up after everything, to prepare for next time CleanUp(); return this->mMesh; }
bool CLoad3DS::Import3DS(t3DModel *pModel, char *strFileName) { char strMessage[255] = {0}; //FILE**m_FilePointer; // Open the 3DS file //m_FilePointer = fopen_s(strFileName, "rb"); m_FilePointer = fopen(strFileName, "rb"); // Make sure we have a valid file pointer (we found the file) if(!m_FilePointer) { sprintf(strMessage, "Unable to find the file: %s!", strFileName); // MessageBox(NULL, strMessage, "Error", MB_OK); return false; } // Once we have the file open, we need to read the very first data chunk // to see if it's a 3DS file. That way we don't read an invalid file. // If it is a 3DS file, then the first chunk ID will be equal to PRIMARY (some hex num) // Read the first chuck of the file to see if it's a 3DS file ReadChunk(m_CurrentChunk); // Make sure this is a 3DS file if (m_CurrentChunk->ID != PRIMARY) { sprintf(strMessage, "Unable to load PRIMARY chuck from file: %s!", strFileName); //MessageBox(NULL, strMessage, "Error", MB_OK); return false; } // Now we actually start reading in the data. ProcessNextChunk() is recursive // Begin loading objects, by calling this recursive function ProcessNextChunk(pModel, m_CurrentChunk); // After we have read the whole 3DS file, we want to calculate our own vertex normals. ComputeNormals(pModel); // Clean up after everything CleanUp(); return true; }
bool CLoad3DS::Import3DS(t3DModel *pModel, const wchar_t *strFileName) { char strMessage[255] = {0}; tChunk currentChunk = {0}; // Open the 3DS file m_FilePointer = _wfopen(strFileName, L"rb"); // Make sure we have a valid file pointer (we found the file) if(!m_FilePointer) { XEVOL_LOG(eXL_DEBUG_HIGH, L"Unable to find the file: %S!\n", strFileName); return false; } // Once we have the file open, we need to read the very first data chunk // to see if it's a 3DS file. That way we don't read an invalid file. // If it is a 3DS file, then the first chunk ID will be equal to PRIMARY (some hex num) // Read the first chuck of the file to see if it's a 3DS file ReadChunk(¤tChunk); // Make sure this is a 3DS file if (currentChunk.ID != PRIMARY) { XEVOL_LOG(eXL_DEBUG_HIGH, "Unable to load PRIMARY chuck from file: %s!", strFileName); return false; } // Now we actually start reading in the data. ProcessNextChunk() is recursive // Begin loading objects, by calling this recursive function ProcessNextChunk(pModel, ¤tChunk); // After we have read the whole 3DS file, we want to calculate our own vertex normals. ComputeNormals(pModel); // Clean up after everything CleanUp(); return true; }
bool ModelLoader::Import3DS(const char *strFileName) { char strMessage[255] = {0}; Chunk currentChunk = {0}; // Open the 3DS file fopen_s(&m_FilePointer, strFileName, "rb"); // Make sure we have a valid file pointer if(!m_FilePointer){ sprintf_s(strMessage, "Unable to find the file: %s!", strFileName); MessageBox(NULL, strMessage, "Error", MB_OK); return false; } // First thing to do is to open the first chunk which is sort of the header // of the 3DS file. If it is a 3DS file, the first chunk will be labeled as // PRIMARY // Read the first chuck of the file to see if it's a 3DS file ReadChunk(¤tChunk); // Make sure this is a 3DS file if (currentChunk.ID != PRIMARY){ sprintf_s(strMessage, "Unable to load PRIMARY chuck from file: %s!", strFileName); MessageBox(NULL, strMessage, "Error", MB_OK); return false; } // Next we begin to read in the data. The function ProcessNextChunk is recursive // and will move through all the data. ProcessNextChunk(&m_3DModel, ¤tChunk); // Close the file after we have read everything in if (m_FilePointer){ fclose(m_FilePointer); m_FilePointer = NULL; } return true; }
bool Loaders::t3DSLoader::Import3DS(t3DModel *pModel, char *strFileName) { char strMessage[255] = {0}; m_FilePointer = fopen(strFileName, "rb"); if(!m_FilePointer) { sprintf(strMessage, "Unable to find the file: %s!", strFileName); MessageBox(NULL, strMessage, "Error", MB_OK); return false; } ReadChunk(m_CurrentChunk); if (m_CurrentChunk->ID != PRIMARY) { sprintf(strMessage, "Unable to load PRIMARY chuck from file: %s!", strFileName); MessageBox(NULL, strMessage, "Error", MB_OK); return false; } ProcessNextChunk(pModel, m_CurrentChunk); ResizeObjects(pModel); pModel->customScale.clear(); pModel->customScale.resize(pModel->numberOfFrames); for (int i = 0; i < pModel->numberOfFrames; i++) pModel->customScale[i] = 1.0f; ComputeNormals(pModel); StoreMaximumMinimum(pModel); CleanUp(); return true; }
int Import3DS(Loader3ds *pt3ds,char *strFileName) { char strMessage[255] = {0}; tChunk currentChunk = {0}; // Open the 3DS file pt3ds->FilePointer = fopen(strFileName, "rb"); // Make sure we have a valid file pointer if(!pt3ds->FilePointer) { sprintf(strMessage, "Unable to find the file: %s!", strFileName); printf("%s\n",strMessage); return 0; } // Read the first chuck of the file to see if it's a 3DS file ReadChunk(pt3ds,¤tChunk); // Make sure this is a 3DS file if (currentChunk.ID != PRIMARY) { sprintf(strMessage, "Unable to load PRIMARY chuck from file: %s!", strFileName); printf("%s\n",strMessage); return 0; } //ProcessNextChunk() is recursive ProcessNextChunk(pt3ds,¤tChunk); // calculate vertex normals. ComputeNormals(pt3ds); if (pt3ds->FilePointer != NULL) fclose(pt3ds->FilePointer); return 1; }
bool CLoad3DS::Import3DS(t3DModel *pModel, const char *strFileName) { char strMessage[255] = {0}; m_FilePointer = ASSET_OPEN(strFileName, "rb"); if(!m_FilePointer) { LOGI("%s does not exist", strFileName); return false; } ReadChunk(m_CurrentChunk); if (m_CurrentChunk->ID != PRIMARY) { return false; } ProcessNextChunk(pModel, m_CurrentChunk); ComputeNormals(pModel); CleanUp(); return true; }
void CLoad3DS::ProcessNextChunk(t3DModel *pModel, tChunk *pPreviousChunk) { t3DObject newObject = {0}; // This is used to add to our object list tMaterialInfo newTexture = {0}; // This is used to add to our material list tChunk currentChunk = {0}; // The current chunk to load tChunk tempChunk = {0}; // A temp chunk for holding data // Below we check our chunk ID each time we read a new chunk. Then, if // we want to extract the information from that chunk, we do so. // If we don't want a chunk, we just read past it. // Continue to read the sub chunks until we have reached the length. // After we read ANYTHING we add the bytes read to the chunk and then check // check against the length. while (pPreviousChunk->bytesRead < pPreviousChunk->length) { // Read next Chunk ReadChunk(¤tChunk); // Check the chunk ID switch (currentChunk.ID) { case VERSION: // This holds the version of the file // If the file was made in 3D Studio Max, this chunk has an int that // holds the file version. Since there might be new additions to the 3DS file // format in 4.0, we give a warning to that problem. // However, if the file wasn't made by 3D Studio Max, we don't 100% what the // version length will be so we'll simply ignore the value // Read the file version and add the bytes read to our bytesRead variable currentChunk.bytesRead += fread(gBuffer, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer); // If the file version is over 3, give a warning that there could be a problem if ((currentChunk.length - currentChunk.bytesRead == 4) && (gBuffer[0] > 0x03)) { MessageBox(NULL, "This 3DS file is over version 3 so it may load incorrectly", "Warning", MB_OK); } break; case OBJECTINFO: // This holds the version of the mesh { // This chunk holds the version of the mesh. It is also the head of the MATERIAL // and OBJECT chunks. From here on we start reading in the material and object info. // Read the next chunk ReadChunk(&tempChunk); // Get the version of the mesh tempChunk.bytesRead += fread(gBuffer, 1, tempChunk.length - tempChunk.bytesRead, m_FilePointer); // Increase the bytesRead by the bytes read from the last chunk currentChunk.bytesRead += tempChunk.bytesRead; // Go to the next chunk, which is the object has a texture, it should be MATERIAL, then OBJECT. ProcessNextChunk(pModel, ¤tChunk); break; } case MATERIAL: // This holds the material information // This chunk is the header for the material info chunks // Increase the number of materials pModel->numOfMaterials++; // Add a empty texture structure to our texture list. // If you are unfamiliar with STL's "vector" class, all push_back() // does is add a new node onto the list. I used the vector class // so I didn't need to write my own link list functions. pModel->pMaterials.push_back(newTexture); // Proceed to the material loading function ProcessNextMaterialChunk(pModel, ¤tChunk); break; case OBJECT: // This holds the name of the object being read // This chunk is the header for the object info chunks. It also // holds the name of the object. // Increase the object count pModel->numOfObjects++; // Add a new tObject node to our list of objects (like a link list) pModel->pObject.push_back(newObject); // Initialize the object and all it's data members memset(&(pModel->pObject[pModel->numOfObjects - 1]), 0, sizeof(t3DObject)); // Get the name of the object and store it, then add the read bytes to our byte counter. currentChunk.bytesRead += GetString(pModel->pObject[pModel->numOfObjects - 1].strName); // Now proceed to read in the rest of the object information ProcessNextObjectChunk(pModel, &(pModel->pObject[pModel->numOfObjects - 1]), ¤tChunk); break; case EDITKEYFRAME: // Because I wanted to make this a SIMPLE tutorial as possible, I did not include // the key frame information. This chunk is the header for all the animation info. // In a later tutorial this will be the subject and explained thoroughly. //ProcessNextKeyFrameChunk(pModel, currentChunk); // Read past this chunk and add the bytes read to the byte counter currentChunk.bytesRead += fread(gBuffer, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer); break; default: // If we didn't care about a chunk, then we get here. We still need // to read past the unknown or ignored chunk and add the bytes read to the byte counter. 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; } }
void CLoad3DS::ProcessNextChunk(mo3DSModel *pModel, tChunk *pPreviousChunk) { mo3DSObject newObject; memset( &newObject, 0, sizeof(mo3DSObject)); // This is used to add to our object list mo3DSMaterialInfo newMaterial; // This is used to add to our material list newMaterial.color[0] = 0;newMaterial.color[1] = 0;newMaterial.color[2] = 0; newMaterial.colorAmbient[0] = 0;newMaterial.colorAmbient[1] = 0;newMaterial.colorAmbient[2] = 0; newMaterial.colorSpecular[0] = 0;newMaterial.colorSpecular[1] = 0;newMaterial.colorSpecular[2] = 0; newMaterial.colorDiffuse[0] = 0;newMaterial.colorDiffuse[1] = 0;newMaterial.colorDiffuse[2] = 0; unsigned int version = 0; // This will hold the file version int buffer[50000] = {0}; // This is used to read past unwanted data m_CurrentChunk = new tChunk; // Allocate a new chunk // Below we check our chunk ID each time we read a new chunk. Then, if // we want to extract the information from that chunk, we do so. // If we don't want a chunk, we just read past it. // Continue to read the sub chunks until we have reached the length. // After we read ANYTHING we add the bytes read to the chunk and then check // check against the length. while(pPreviousChunk->bytesRead < pPreviousChunk->length) { // Read next Chunk ReadChunk(m_CurrentChunk); // Check the chunk ID switch(m_CurrentChunk->ID) { case VERSION: // This holds the version of the file // This chunk has an unsigned short that holds the file version. // Since there might be new additions to the 3DS file format in 4.0, // we give a warning to that problem. // Read the file version and add the bytes read to our bytesRead variable m_CurrentChunk->bytesRead += fread(&version, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); // If the file version is over 3, give a warning that there could be a problem if(version > 0x03) cout << "This 3DS file is over version 3 so it may load incorrectly" << endl; break; case OBJECTINFO: // This holds the version of the mesh // This chunk holds the version of the mesh. It is also the head of the MATERIAL // and OBJECT chunks. From here on we start reading in the material and object info. // Read the next chunk ReadChunk(m_TempChunk); // Get the version of the mesh m_TempChunk->bytesRead += fread(&version, 1, m_TempChunk->length - m_TempChunk->bytesRead, m_FilePointer); // Increase the bytesRead by the bytes read from the last chunk m_CurrentChunk->bytesRead += m_TempChunk->bytesRead; // Go to the next chunk, which is the object has a texture, it should be MATERIAL, then OBJECT. ProcessNextChunk(pModel, m_CurrentChunk); break; case MATERIAL: // This holds the material information // This chunk is the header for the material info chunks // Increase the number of materials pModel->numOfMaterials++; // Add a empty texture structure to our texture list. // If you are unfamiliar with STL's "vector" class, all push_back() // does is add a new node onto the list. I used the vector class // so I didn't need to write my own link list functions. pModel->pMaterials.push_back(newMaterial); // Proceed to the material loading function ProcessNextMaterialChunk(pModel, m_CurrentChunk); break; case OBJECT: // This holds the name of the object being read // This chunk is the header for the object info chunks. It also // holds the name of the object. // Increase the object count pModel->numOfObjects++; // Add a new tObject node to our list of objects(like a link list) pModel->pObject.push_back(newObject); // Initialize the object and all it's data members memset(&(pModel->pObject[pModel->numOfObjects - 1]), 0, sizeof(mo3DSObject)); // Get the name of the object and store it, then add the read bytes to our byte counter. m_CurrentChunk->bytesRead += GetString(pModel->pObject[pModel->numOfObjects - 1].strName); // Now proceed to read in the rest of the object information ProcessNextObjectChunk(pModel, &(pModel->pObject[pModel->numOfObjects - 1]), m_CurrentChunk); break; case EDITKEYFRAME: // Because I wanted to make this a SIMPLE tutorial as possible, I did not include // the key frame information. This chunk is the header for all the animation info. // In a later tutorial this will be the subject and explained thoroughly. //ProcessNextKeyFrameChunk(pModel, m_CurrentChunk); // Read past this chunk and add the bytes read to the byte counter m_CurrentChunk->bytesRead += fread(buffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; default: // If we didn't care about a chunk, then we get here. We still need // to read past the unknown or ignored chunk and add the bytes read to the byte counter. m_CurrentChunk->bytesRead += fread(buffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; } // Add the bytes read from the last chunk to the previous chunk passed in. pPreviousChunk->bytesRead += m_CurrentChunk->bytesRead; } // Free the current chunk and set it back to the previous chunk(since it started that way) delete m_CurrentChunk; m_CurrentChunk = pPreviousChunk; }
void CLoad3DS::ProcessNextChunk(t3DModel *pModel, tChunk *pPreviousChunk) { t3DObject newObject = {0}; tMaterialInfo newTexture = {0}; unsigned int version = 0; // int buffer[50000] = {0}; m_CurrentChunk = new tChunk; while (pPreviousChunk->bytesRead < pPreviousChunk->length) { ReadChunk(m_CurrentChunk); switch (m_CurrentChunk->ID) { case VERSION: m_CurrentChunk->bytesRead += ASSET_READ(&version, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); if (version > 0x03) { } // Assert(0); // MessageBox(NULL, "This 3DS file is over version 3 so it may load incorrectly", "Warning", MB_OK); break; case OBJECTINFO: ReadChunk(m_TempChunk); m_TempChunk->bytesRead += ASSET_READ(&version, 1, m_TempChunk->length - m_TempChunk->bytesRead, m_FilePointer); m_CurrentChunk->bytesRead += m_TempChunk->bytesRead; ProcessNextChunk(pModel, m_CurrentChunk); break; case MATERIAL: pModel->numOfMaterials++; pModel->pMaterials.push_back(newTexture); ProcessNextMaterialChunk(pModel, m_CurrentChunk); break; case OBJECT: pModel->numOfObjects++; pModel->pObject.push_back(newObject); memset(&(pModel->pObject[pModel->numOfObjects - 1]), 0, sizeof(t3DObject)); m_CurrentChunk->bytesRead += GetString(pModel->pObject[pModel->numOfObjects - 1].strName); ProcessNextObjectChunk(pModel, &(pModel->pObject[pModel->numOfObjects - 1]), m_CurrentChunk); break; case EDITKEYFRAME: // 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; 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; }
void ModelLoader::ProcessNextChunk(Model3DS *pModel, Chunk *pPreviousChunk) { Object3DS newObject = {0}; MaterialInfo newTexture = {0}; Chunk currentChunk = {0}; Chunk tempChunk = {0}; // To read in the data, first we read in the chunk ID. If it is something // we want, we go through and handle it, otherwise we just keep tracking the bytes // and move over it until we hit the end of the chunk. while (pPreviousChunk->bytesRead < pPreviousChunk->length){ // Read next Chunk ReadChunk(¤tChunk); // Check the chunk ID switch (currentChunk.ID){ case VERSION: // This stores the version of the file format from 3DS. We want to support just // version 3.0. So if we are beyond that, we'll pop out a warning. currentChunk.bytesRead += fread(m_Buffer, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer); // If the file version is over 3, give a warning that there could be a problem if ((currentChunk.length - currentChunk.bytesRead == 4) && (m_Buffer[0] > 0x03)){ MessageBox(NULL, "This 3DS file is over version 3 so it may load incorrectly", "Warning", MB_OK); } break; case OBJECTINFO: // This stores the version of the mesh, and is also the head of Object and materials // chunks tempChunk.bytesRead += fread(m_Buffer, 1, tempChunk.length - tempChunk.bytesRead, m_FilePointer); // Go to the next chunk, which is the object has a texture, it should be MATERIAL, then OBJECT. ProcessNextChunk(pModel, ¤tChunk); break; case MATERIAL: // Header for material info chunks // Increase the number of materials pModel->numOfMaterials++; // Going to add a blank texture to our list and fill the data in later. pModel->pMaterials.push_back(newTexture); // Proceed to the material loading function ProcessNextMaterialChunk(pModel, ¤tChunk); break; case OBJECT: // This chunk is the header for the object info chunks. It also // holds the name of the object. // Increase the object count pModel->numOfObjects++; // Adding a blank object to be filled in later. pModel->pObject.push_back(newObject); // Initialize the object and all it's data members memset(&(pModel->pObject[pModel->numOfObjects - 1]), 0, sizeof(Object3DS)); // Get the name of the object and store it, then add the read bytes to our byte counter. currentChunk.bytesRead += GetString(pModel->pObject[pModel->numOfObjects - 1].strName); // Now proceed to read in the rest of the object information ProcessNextObjectChunk(pModel, &(pModel->pObject[pModel->numOfObjects - 1]), ¤tChunk); break; case EDITKEYFRAME: // This is the chunk that stores animation info, currently not supported, so just // read past it currentChunk.bytesRead += fread(m_Buffer, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer); break; default: // This is for chunks we don't care about, just read past them and move on. 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; } }
int Load3ds::ProcessNextChunk(Chunk * aPreviousChunk) { mCurrentChunk = new Chunk; size_t numberOfBytesRead; while (aPreviousChunk->mBytesRead < aPreviousChunk->mLength) { // Read next chunk ReadChunk(mCurrentChunk); switch (mCurrentChunk->mID) { case VERSION: // Check version (must be 3 or less) mCurrentChunk->mBytesRead += numberOfBytesRead = fread(mBuffer, 1, mCurrentChunk->mLength - mCurrentChunk->mBytesRead, mFile); #ifdef __BIG_ENDIAN__ for (int i = 0; i < numberOfBytesRead; i++) { static_cast<short *>(mBuffer)[i] = OSReadSwapInt16(&static_cast<short*>(mBuffer)[i],0); } #endif if (*(unsigned short *) mBuffer > 0x03) exit(1107); break; case EDITMATERIAL: // Proceed to material loading function ProcessNextMaterialChunk(mCurrentChunk); break; case EDIT3DS: // Check mesh version, then proceed to mesh loading function ReadChunk(mTempChunk); mTempChunk->mBytesRead += numberOfBytesRead = fread(mBuffer, 1, mTempChunk->mLength - mTempChunk->mBytesRead, mFile); #ifdef __BIG_ENDIAN__ for (int i = 0; i < numberOfBytesRead; i++) { static_cast<short *>(mBuffer)[i] = OSReadSwapInt16(&static_cast<short*>(mBuffer)[i],0); } #endif mCurrentChunk->mBytesRead += mTempChunk->mBytesRead; if (mTempChunk->mID != MESHVERSION || *(unsigned short *)mBuffer > 0x03) exit(1107); ProcessNextChunk(mCurrentChunk); break; case EDITOBJECT: mCurrentChunk->mBytesRead += GetString((char *)mBuffer); // mBuffer now contains name of the object to be edited ProcessNextObjectChunk(mCurrentChunk); break; case EDITKEYFRAME: ProcessNextKeyFrameChunk(mCurrentChunk); break; default: // unrecognized/unsupported chunk mCurrentChunk->mBytesRead += numberOfBytesRead = fread(mBuffer, 1, mCurrentChunk->mLength - mCurrentChunk->mBytesRead, mFile); #ifdef __BIG_ENDIAN__ for (int i = 0; i < numberOfBytesRead; i++) { static_cast<short *>(mBuffer)[i] = OSReadSwapInt16(&static_cast<short*>(mBuffer)[i],0); } #endif break; } aPreviousChunk->mBytesRead += mCurrentChunk->mBytesRead; } delete mCurrentChunk; mCurrentChunk = aPreviousChunk; return 1; }
void ProcessNextChunk(Loader3ds *pt3ds,tChunk *pPreviousChunk) { tChunk currentChunk = {0}; // The current chunk to load tChunk tempChunk = {0}; // A temp chunk for holding data while (pPreviousChunk->bytesRead < pPreviousChunk->length) { // Read next Chunk ReadChunk(pt3ds,¤tChunk); // Check the chunk ID switch (currentChunk.ID) { case VERSION: // Read the file version currentChunk.bytesRead += fread(pt3ds->gBuffer, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); if ((currentChunk.length - currentChunk.bytesRead == 4) && (pt3ds->gBuffer[0] > 0x03)) { printf("This 3DS file is over version 3 so it may load incorrectly\n"); } break; case OBJECTINFO: { // This chunk holds the version of the mesh. // Read the next chunk ReadChunk(pt3ds,&tempChunk); // Get the version of the mesh tempChunk.bytesRead += fread(pt3ds->gBuffer, 1, tempChunk.length - tempChunk.bytesRead, pt3ds->FilePointer); // Increase the bytesRead by the bytes read from the last chunk currentChunk.bytesRead += tempChunk.bytesRead; // Go to the next chunk, which is the object has a texture, it should be MATERIAL, then OBJECT. ProcessNextChunk(pt3ds,¤tChunk); break; } case MATERIAL: // This chunk is the header for the material info chunks // Increase the number of materials pt3ds->NBmaterials++; PrepareAddMaterial(pt3ds); // Proceed to the material loading function ProcessNextMaterialChunk(pt3ds,¤tChunk); break; case OBJECT: // This chunk is the header for the object info chunks. // Increase the object count pt3ds->NBobjects++; PrepareAddObject(pt3ds); // Get the name of the object currentChunk.bytesRead += GetString(pt3ds,pt3ds->curobj->Name); // Now proceed to read in the rest of the object information ProcessNextObjectChunk(pt3ds,¤tChunk); break; /* case EDITKEYFRAME: pt3ds->curobj=objects; ProcessNextChunk(pt3ds,¤tChunk); break; case 0xB002: ProcessNextChunk(pt3ds,¤tChunk); if (pt3ds->curobj!=NULL) pt3ds->curobj = pt3ds->curobj->next; break; case 0xB030: float tempf[9];int y; short tempshort; currentChunk.bytesRead += fread(&tempshort, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); break; case 0xB010: currentChunk.bytesRead += fread(gBuffer, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); break; case 0xB013: currentChunk.bytesRead += fread(tempf, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); break; case 0xB020: currentChunk.bytesRead += fread(tempf, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); break; case 0xB021: currentChunk.bytesRead += fread(tempf, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); pt3ds->curobj->rotation[0]=tempf[5]*(180.0/PI); pt3ds->curobj->rotation[1]=tempf[6]*(180.0/PI); pt3ds->curobj->rotation[2]=tempf[8]*(180.0/PI); break; case 0xB022: // INFO ROTATION SCALE ??? ->5,6 and 7 currentChunk.bytesRead += fread(tempf, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); if (tempf[5]==-1.0) pt3ds->curobj->scale[0]=-1.0; else pt3ds->curobj->scale[0]=1.0; if (tempf[7]==-1.0) pt3ds->curobj->scale[1]=-1.0; else pt3ds->curobj->scale[1]=1.0; if (tempf[6]==-1.0) pt3ds->curobj->scale[2]=-1.0; else pt3ds->curobj->scale[2]=1.0; break; */ default: currentChunk.bytesRead += fread(pt3ds->gBuffer, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); break; } pPreviousChunk->bytesRead += currentChunk.bytesRead; } }
void Loaders::t3DSLoader::ProcessNextChunk(t3DModel *pModel, tChunk *pPreviousChunk) { t3DObject newObject; tMaterialInfo newTexture = {0}; int version = 0; m_CurrentChunk = new tChunk; while (pPreviousChunk->bytesRead < pPreviousChunk->length) { ReadChunk(m_CurrentChunk); switch (m_CurrentChunk->ID) { case VERSION: m_CurrentChunk->bytesRead += fread(&version, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); if (version > 0x03) MessageBox(NULL, "This 3DS file is over version 3 so it may load incorrectly", "Warning", MB_OK); break; case OBJECTINFO: ReadChunk(m_TempChunk); m_TempChunk->bytesRead += fread(&version, 1, m_TempChunk->length - m_TempChunk->bytesRead, m_FilePointer); m_CurrentChunk->bytesRead += m_TempChunk->bytesRead; ProcessNextChunk(pModel, m_CurrentChunk); break; case MATERIAL: pModel->numOfMaterials++; pModel->pMaterials.push_back(newTexture); ProcessNextMaterialChunk(pModel, m_CurrentChunk); break; case OBJECT: pModel->numOfObjects++; pModel->pObject.push_back(newObject); memset(&(pModel->pObject[pModel->numOfObjects - 1]), 0, sizeof(t3DObject)); m_CurrentChunk->bytesRead += GetString(pModel->pObject[pModel->numOfObjects - 1].strName); ProcessNextObjectChunk(pModel, &(pModel->pObject[pModel->numOfObjects - 1]), m_CurrentChunk); break; case KEYFRAME: ProcessNextKeyFrameChunk(pModel, m_CurrentChunk); m_CurrentChunk->bytesRead += fread(gBuffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); 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; }