Beispiel #1
0
void CLoad3DS::ProcessNextObjectChunk(t3DModel *pModel, t3DObject *pObject, 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
		switch (currentChunk.ID)
		{
		case OBJECT_MESH:					// This lets us know that we are reading a new object
		
			// We found a new object, so let's read in it's info using recursion
			ProcessNextObjectChunk(pModel, pObject, &currentChunk);
			break;

		case OBJECT_VERTICES:				// This is the objects vertices
			ReadVertices(pObject, &currentChunk);
			break;

		case OBJECT_FACES:					// This is the objects face information
			ReadVertexIndices(pObject, &currentChunk);
			break;

		case OBJECT_MATERIAL:				// This holds the material name that the object has
			
			// This chunk holds the name of the material that the object has assigned to it.
			// This could either be just a color or a texture map.  This chunk also holds
			// the faces that the texture is assigned to (In the case that there is multiple
			// textures assigned to one object, or it just has a texture on a part of the object.
			// Since most of my game objects just have the texture around the whole object, and 
			// they aren't multitextured, I just want the material name.

			// We now will read the name of the material assigned to this object
			ReadObjectMaterial(pModel, pObject, &currentChunk);			
			break;

		case OBJECT_UV:						// This holds the UV texture coordinates for the object

			// This chunk holds all of the UV coordinates for our object.  Let's read them in.
			ReadUVCoordinates(pObject, &currentChunk);
			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;
	}
}
Beispiel #2
0
void ModelLoader::ProcessNextObjectChunk(Model3DS *pModel, Object3DS *pObject, 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
		switch (currentChunk.ID){
		case OBJECT_MESH:
		
			// This case means we hit a new object, so jump in again and read this next chunk
			ProcessNextObjectChunk(pModel, pObject, &currentChunk);
			break;

		case OBJECT_VERTICES:
			// Object vertices
			ReadVertices(pObject, &currentChunk);
			break;

		case OBJECT_FACES:
			// Object faces
			ReadVertexIndices(pObject, &currentChunk);
			break;

		case OBJECT_MATERIAL:

			// This chunk stores both texture information, or color information
			// depending on the object.  At the moment we'll just support textures
			// so we'll read in the name of the texture and build it later.  If there
			// is just color we'll not bother then.

			ReadObjectMaterial(pModel, pObject, &currentChunk);			
			break;

		case OBJECT_UV:
			// UV coordinates
			ReadUVCoordinates(pObject, &currentChunk);
			break;

		default:  

			// Ignored chunk, read past it.
			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;
	}
}
Beispiel #3
0
int Load3ds::ProcessNextObjectChunk(Chunk * aPreviousChunk)
{
	mCurrentChunk = new Chunk;
	size_t numberOfBytesRead;

	while (aPreviousChunk->mBytesRead < aPreviousChunk->mLength)
	{
		ReadChunk(mCurrentChunk);

		switch (mCurrentChunk->mID)
		{
		case OBJTRIMESH:
			// at this point, mBuffer will contain the name of the object being described
			ProcessNextObjectChunk(mCurrentChunk);
			ComputeNormals();

			break;

		case TRIVERT:
			FillVertexBuffer(mCurrentChunk);
			break;

		case TRIFACE:
			FillIndexBuffer(mCurrentChunk);
			break;

		case TRIFACEMAT:
			// your getting a list of triangles that belong to a certain material
			SortIndicesByMaterial(mCurrentChunk);
			break;

		case TRIUV:
			FillTexCoordBuffer(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;
}
Beispiel #4
0
void ProcessNextObjectChunk(Loader3ds *pt3ds,tChunk *pPreviousChunk) 
{
	tChunk currentChunk = {0}; 
 
	while (pPreviousChunk->bytesRead < pPreviousChunk->length) 
	{ 
		// Read the next chunk 
		ReadChunk(pt3ds,&currentChunk); 
		switch (currentChunk.ID) 
		{ 
		case OBJECT_MESH:
 
			// We found a new object so use recursion 
			ProcessNextObjectChunk(pt3ds,&currentChunk); 
			break; 
 
		case OBJECT_VERTICES:				// 4110This is the objects vertices 
 
			ReadVertices(pt3ds,&currentChunk); 
			break; 
 
		case OBJECT_FACES:					// 4120This is the objects face information 
 
			ReadVertexIndices(pt3ds,&currentChunk); 
			break; 
 
		case OBJECT_MATERIAL:		

			ReadObjectMaterial(pt3ds,&currentChunk);			 
			break; 
 
		case OBJECT_UV:						// 4140This holds the UV texture coordinates for the object 
 
			ReadUVCoordinates(pt3ds,&currentChunk); 
			break; 
 
		case OBJECT_TRANSF:					// 4160 
 
			ReadObjectTransf(pt3ds,&currentChunk); 
			break; 
 
		default:   
 
			currentChunk.bytesRead += fread(pt3ds->gBuffer, 1, currentChunk.length - currentChunk.bytesRead, pt3ds->FilePointer); 
			break; 
		} 
 
		pPreviousChunk->bytesRead += currentChunk.bytesRead; 
	} 
} 
void CLoad3DS::ProcessNextObjectChunk(t3DModel *pModel, t3DObject *pObject, tChunk *pPreviousChunk)
{
//	int buffer[50000] = {0};
//	int *buffer = new int[50000];

	m_CurrentChunk = new tChunk;

	while (pPreviousChunk->bytesRead < pPreviousChunk->length)
	{
	
		ReadChunk(m_CurrentChunk);

		switch (m_CurrentChunk->ID)
		{
		case OBJECT_MESH:				
			ProcessNextObjectChunk(pModel, pObject, m_CurrentChunk);
			break;

		case OBJECT_VERTICES:		
			ReadVertices(pObject, m_CurrentChunk);
			break;

		case OBJECT_FACES:				
			ReadVertexIndices(pObject, m_CurrentChunk);
			break;

		case OBJECT_MATERIAL:
			ReadObjectMaterial(pModel, pObject, m_CurrentChunk);			
			break;

		case OBJECT_UV:	
			ReadUVCoordinates(pObject, m_CurrentChunk);
			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;
//	delete []buffer;
}
Beispiel #6
0
void Loaders::t3DSLoader::ProcessNextObjectChunk(t3DModel *pModel, t3DObject *pObject, tChunk *pPreviousChunk)
{
    m_CurrentChunk = new tChunk;

    while (pPreviousChunk->bytesRead < pPreviousChunk->length)
    {
        ReadChunk(m_CurrentChunk);

        switch (m_CurrentChunk->ID)
        {
        case OBJECT_MESH:
            ProcessNextObjectChunk(pModel, pObject, m_CurrentChunk);
            break;
        case OBJECT_VERTICES:
            ReadVertices(pObject, m_CurrentChunk);
            break;
        case OBJECT_FACES:
            ReadVertexIndices(pObject, m_CurrentChunk);
            break;
        case OBJECT_MATERIAL:
            ReadObjectMaterial(pModel, pObject, m_CurrentChunk);
            break;
        case OBJECT_UV:
            ReadUVCoordinates(pObject, 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;
}
Beispiel #7
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;
	}
}
Beispiel #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;
}
Beispiel #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;
	}
}
Beispiel #11
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;
}
Beispiel #12
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; 
	} 
} 
Beispiel #13
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;
}