Example #1
0
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;
}
Example #2
0
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(&currentChunk);

		// 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]), &currentChunk);
			break;
		
		case MATMAP:							// This is the header for the texture info
			
			// Proceed to read in the material information
			ProcessNextMaterialChunk(pModel, &currentChunk);
			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;
	}
}
Example #3
0
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;
}
Example #4
0
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(&currentChunk);

		// 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]), &currentChunk);
			break;
		
		case MATMAP:
			// Header containing material info
			ProcessNextMaterialChunk(pModel, &currentChunk);
			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;
}
Example #6
0
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(&currentChunk);

		// 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, &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(newTexture);

			// Proceed to the material loading function
			ProcessNextMaterialChunk(pModel, &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(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]), &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, 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;
	}
}
Example #7
0
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;
}
Example #8
0
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;
}
Example #10
0
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(&currentChunk);

		// 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, &currentChunk);
			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, &currentChunk);
			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]), &currentChunk);
			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;
	}
}
Example #11
0
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;
}
Example #12
0
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;
}
Example #13
0
void ProcessNextMaterialChunk(Loader3ds *pt3ds,tChunk *pPreviousChunk) 
{ 
	tChunk currentChunk = {0}; 
	char chartemp; 
 
	while (pPreviousChunk->bytesRead < pPreviousChunk->length) 
	{ 
		// Read the next chunk 
		ReadChunk(pt3ds,&currentChunk); 
		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,&currentChunk); 
		break; 
		 
		case MATMAP:
			 
			// Proceed to read in the material information 
			ProcessNextMaterialChunk(pt3ds,&currentChunk); 
			 
			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; 
	} 
} 
Example #14
0
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,&currentChunk); 
		// 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,&currentChunk); 
			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,&currentChunk); 
			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,&currentChunk); 
			break; 
 
/*		case EDITKEYFRAME: 
			pt3ds->curobj=objects; 
			ProcessNextChunk(pt3ds,&currentChunk); 
			break; 
 
		case 0xB002: 
			ProcessNextChunk(pt3ds,&currentChunk); 
			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; 
	} 
} 
Example #15
0
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;
}