void CLoad3DS::ProcessNextMaterialChunk(t3DModel *pModel, tChunk *pPreviousChunk) { int buffer[50000] = {0}; // This is used to read past unwanted data // Allocate a new chunk to work with m_CurrentChunk = new tChunk; // Continue to read these chunks until we read the end of this sub chunk while (pPreviousChunk->bytesRead < pPreviousChunk->length) { // Read the next chunk ReadChunk(m_CurrentChunk); // Check which chunk we just read in switch (m_CurrentChunk->ID) { case MATNAME: // This chunk holds the name of the material // Here we read in the material name m_CurrentChunk->bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strName, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; case MATDIFFUSE: // This holds the R G B color of our object ReadColorChunk(&(pModel->pMaterials[pModel->numOfMaterials - 1]), m_CurrentChunk); break; case MATMAP: // This is the header for the texture info // Proceed to read in the material information ProcessNextMaterialChunk(pModel, m_CurrentChunk); break; case MATMAPFILE: // This stores the file name of the material // Here we read in the material's file name m_CurrentChunk->bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strFile, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; default: // Read past the ignored or unknown chunks 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::ProcessNextMaterialChunk(t3DModel *pModel, 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(¤tChunk); // Check which chunk we just read in switch (currentChunk.ID) { case MATNAME: // This chunk holds the name of the material // Here we read in the material name currentChunk.bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strName, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer); break; case MATDIFFUSE: // This holds the R G B color of our object ReadColorChunk(&(pModel->pMaterials[pModel->numOfMaterials - 1]), ¤tChunk); break; case MATMAP: // This is the header for the texture info // Proceed to read in the material information ProcessNextMaterialChunk(pModel, ¤tChunk); break; case MATMAPFILE: // This stores the file name of the material // Here we read in the material's file name currentChunk.bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strFile, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer); 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; } }
void Loaders::t3DSLoader::ProcessNextMaterialChunk(t3DModel *pModel, tChunk *pPreviousChunk) { m_CurrentChunk = new tChunk; while (pPreviousChunk->bytesRead < pPreviousChunk->length) { ReadChunk(m_CurrentChunk); switch (pModel, m_CurrentChunk->ID) { case MATNAME: m_CurrentChunk->bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strName, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; case MATDIFFUSE: ReadColorChunk(&(pModel->pMaterials[pModel->numOfMaterials - 1]), m_CurrentChunk); break; case MATMAP: ProcessNextMaterialChunk(pModel, m_CurrentChunk); break; case MATMAPFILE: m_CurrentChunk->bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strFile, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; case MATSPECULAR: ReadColorChunkDest((uint8*)&(pModel->pMaterials[pModel->numOfMaterials - 1].specularcolor[0]), m_CurrentChunk); break; case MATSHININESS: ReadPercentageChunkDest((uint8*)&(pModel->pMaterials[pModel->numOfMaterials - 1].shininess.uShininess[0]), m_CurrentChunk); break; case MATSHININESSSTR: ReadPercentageChunkDest((uint8*)&(pModel->pMaterials[pModel->numOfMaterials - 1].shininess.uShininess[1]), m_CurrentChunk); break; case MATSHININESSSTR2: ReadPercentageChunkDest((uint8*)&(pModel->pMaterials[pModel->numOfMaterials - 1].shininess.uShininess[2]), 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; }
void ModelLoader::ProcessNextMaterialChunk(Model3DS *pModel, 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(¤tChunk); // Check which chunk we just read in switch (currentChunk.ID){ case MATNAME: // This is the name of the material we just read in currentChunk.bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strName, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer); break; case MATDIFFUSE: // RGB color of the object ReadColorChunk(&(pModel->pMaterials[pModel->numOfMaterials - 1]), ¤tChunk); break; case MATMAP: // Header containing material info ProcessNextMaterialChunk(pModel, ¤tChunk); break; case MATMAPFILE: // Filename of the material currentChunk.bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strFile, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer); break; default: // Read past the ignored or unknown chunks 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; } }
void CLoad3DS::ProcessNextMaterialChunk(t3DModel *pModel, tChunk *pPreviousChunk) { int buffer[50000] = {0}; m_CurrentChunk = new tChunk; while (pPreviousChunk->bytesRead < pPreviousChunk->length) { ReadChunk(m_CurrentChunk); switch (m_CurrentChunk->ID) { case MATNAME: m_CurrentChunk->bytesRead += ASSET_READ(pModel->pMaterials[pModel->numOfMaterials - 1].strName, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; case MATDIFFUSE: ReadColorChunk(&(pModel->pMaterials[pModel->numOfMaterials - 1]), m_CurrentChunk); break; case MATMAP: ProcessNextMaterialChunk(pModel, m_CurrentChunk); break; case MATMAPFILE: m_CurrentChunk->bytesRead += ASSET_READ(pModel->pMaterials[pModel->numOfMaterials - 1].strFile, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; default: m_CurrentChunk->bytesRead += ASSET_READ(buffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; } pPreviousChunk->bytesRead += m_CurrentChunk->bytesRead; } delete m_CurrentChunk; m_CurrentChunk = pPreviousChunk; }
void CLoad3DS::ProcessNextMaterialChunk(mo3DSModel *pModel, tChunk *pPreviousChunk) { int buffer[50000] = {0}; // This is used to read past unwanted data mo3DSTextureMapInfo texMapInfo; memset( &texMapInfo, 0, sizeof(mo3DSTextureMapInfo)); // Allocate a new chunk to work with m_CurrentChunk = new tChunk; // Continue to read these chunks until we read the end of this sub chunk while(pPreviousChunk->bytesRead < pPreviousChunk->length) { // Read the next chunk ReadChunk(m_CurrentChunk); // Check which chunk we just read in switch(m_CurrentChunk->ID) { case MATNAME: // This chunk holds the name of the material // Here we read in the material name m_CurrentChunk->bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strName, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; case MAT_DIFFUSE_COLOR: // This holds the R G B color of our object ReadColorChunk(&(pModel->pMaterials[pModel->numOfMaterials - 1]), m_CurrentChunk, MAT_DIFFUSE_COLOR); break; case MAT_AMBIENT_COLOR: ReadColorChunk(&(pModel->pMaterials[pModel->numOfMaterials - 1]), m_CurrentChunk, MAT_AMBIENT_COLOR); break; case MAT_SPECULAR_COLOR: ReadColorChunk(&(pModel->pMaterials[pModel->numOfMaterials - 1]), m_CurrentChunk, MAT_SPECULAR_COLOR); break; case MAT_TEXTURE_MAP1_CHUNK: case MAT_TEXTURE_MAP2_CHUNK: case MAT_OPACITY_MAP_CHUNK: case MAT_BUMP_MAP_CHUNK: case MAT_SHININESS_MAP_CHUNK: case MAT_SPECULAR_MAP_CHUNK: case MAT_SELF_ILLUM_MAP_CHUNK: case MAT_REFLECTION_MAP_CHUNK: // Proceed to read in the material information texMapInfo.id = m_CurrentChunk->ID; pModel->pMaterials[pModel->numOfMaterials - 1].texMaps.push_back(texMapInfo); ProcessNextMaterialChunk(pModel, m_CurrentChunk); break; case MAP_FILENAME: // This stores the file name of the material // Here we read in the material's file name m_CurrentChunk->bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].texMaps.back().strFile, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; case MAP_V_SCALE: m_CurrentChunk->bytesRead += fread( &pModel->pMaterials[pModel->numOfMaterials - 1].texMaps.back().vTile, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; case MAP_U_SCALE: m_CurrentChunk->bytesRead += fread( &pModel->pMaterials[pModel->numOfMaterials - 1].texMaps.back().uTile, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; case MAP_V_OFFSET: m_CurrentChunk->bytesRead += fread( &pModel->pMaterials[pModel->numOfMaterials - 1].texMaps.back().vOffset, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; case MAP_U_OFFSET: m_CurrentChunk->bytesRead += fread( &pModel->pMaterials[pModel->numOfMaterials - 1].texMaps.back().uOffset, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; case MAP_ROTATION: m_CurrentChunk->bytesRead += fread( &pModel->pMaterials[pModel->numOfMaterials - 1].texMaps.back().rotation, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer); break; default: // Read past the ignored or unknown chunks 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; }
int Load3ds::ProcessNextMaterialChunk(Chunk * aPreviousChunk) { mCurrentChunk = new Chunk; size_t numberOfBytesRead; while (aPreviousChunk->mBytesRead < aPreviousChunk->mLength) { ReadChunk(mCurrentChunk); switch (mCurrentChunk->mID) { case MATNAME: 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; case MATLUMINANCE: ReadColorChunk(mCurrentChunk, (float *) mBuffer); break; case MATDIFFUSE: ReadColorChunk(mCurrentChunk, (float *) mBuffer); break; case MATSPECULAR: ReadColorChunk(mCurrentChunk, (float *) mBuffer); break; case MATSHININESS: ReadColorChunk(mCurrentChunk, (float *) mBuffer); break; case MATMAP: // texture map chunk, proceed ProcessNextMaterialChunk(mCurrentChunk); break; case MATMAPFILE: mCurrentChunk->mBytesRead += numberOfBytesRead = fread((char *)mBuffer, 1, mCurrentChunk->mLength - mCurrentChunk->mBytesRead, mFile); // mBuffer now contains the filename of the next texture; load it if you wish 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 ProcessNextMaterialChunk(Loader3ds *pt3ds,tChunk *pPreviousChunk) { tChunk currentChunk = {0}; char chartemp; while (pPreviousChunk->bytesRead < pPreviousChunk->length) { // Read the next chunk ReadChunk(pt3ds,¤tChunk); switch (currentChunk.ID) { case MATNAME: // This chunk holds the name of the material currentChunk.bytesRead += fread(pt3ds->curmat->Name, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); pt3ds->curmat->uOffset=0.0; pt3ds->curmat->vOffset=0.0; pt3ds->curmat->uTile=1.0; pt3ds->curmat->vTile=1.0; break; case MATDIFFUSE: // This holds the R G B color of our object ReadColorChunk(pt3ds,¤tChunk); break; case MATMAP: // Proceed to read in the material information ProcessNextMaterialChunk(pt3ds,¤tChunk); break; case MATMAPFILE: // Here we read in the material's file name currentChunk.bytesRead += fread(pt3ds->curmat->strFile, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); break; case MATMAPVSCALE: // Here we read in the material's v Scale currentChunk.bytesRead += fread(&(pt3ds->curmat->vTile), 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); break; case MATMAPUSCALE: // Here we read in the material's u Scale currentChunk.bytesRead += fread(&(pt3ds->curmat->uTile), 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); break; case MATMAPUOFFSET: // Here we read in the material's u Offset currentChunk.bytesRead += fread(&(pt3ds->curmat->uOffset), 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); break; case MATMAPVOFFSET: // Here we read in the material's v Offset currentChunk.bytesRead += fread(&(pt3ds->curmat->vOffset), 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); break; case MATTRANSP: // Transparence 0= no transp; 100=full transp currentChunk.bytesRead += fread(pt3ds->gBuffer, 1, 6, pt3ds->FilePointer); currentChunk.bytesRead += fread(&chartemp, 1, 1, pt3ds->FilePointer); currentChunk.bytesRead += fread(pt3ds->gBuffer, 1, 1, pt3ds->FilePointer); pt3ds->curmat->transparence = 100-chartemp; break; default: currentChunk.bytesRead += fread(pt3ds->gBuffer, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); break; } pPreviousChunk->bytesRead += currentChunk.bytesRead; } }