33 m_CurrentChunk =
new tChunk;
45 char strMessage[255] = {0};
48 m_FilePointer = fopen(strFileName,
"rb");
53 sprintf(strMessage,
"Unable to find the file: %s!", strFileName);
54 cout << strMessage << endl;
63 ReadChunk(m_CurrentChunk);
68 sprintf(strMessage,
"Unable to load PRIMARY chuck from file: %s!", strFileName);
69 cout << strMessage << endl;
76 ProcessNextChunk(pModel, m_CurrentChunk);
79 ComputeNormals(pModel);
93 void CLoad3DS::CleanUp()
96 fclose(m_FilePointer);
97 delete m_CurrentChunk;
116 newMaterial.
color[0] = 0;newMaterial.
color[1] = 0;newMaterial.
color[2] = 0;
123 unsigned int version = 0;
124 int buffer[50000] = {0};
126 m_CurrentChunk =
new tChunk;
138 ReadChunk(m_CurrentChunk);
141 switch(m_CurrentChunk->
ID)
154 cout <<
"This 3DS file is over version 3 so it may load incorrectly" << endl;
163 ReadChunk(m_TempChunk);
172 ProcessNextChunk(pModel, m_CurrentChunk);
189 ProcessNextMaterialChunk(pModel, m_CurrentChunk);
201 pModel->
pObject.push_back(newObject);
210 ProcessNextObjectChunk(pModel, &(pModel->
pObject[pModel->
numOfObjects - 1]), m_CurrentChunk);
238 delete m_CurrentChunk;
239 m_CurrentChunk = pPreviousChunk;
251 int buffer[50000] = {0};
254 m_CurrentChunk =
new tChunk;
260 ReadChunk(m_CurrentChunk);
263 switch(m_CurrentChunk->
ID)
268 ProcessNextObjectChunk(pModel, pObject, m_CurrentChunk);
272 ReadVertices(pObject, m_CurrentChunk);
276 ReadVertexIndices(pObject, m_CurrentChunk);
289 ReadObjectMaterial(pModel, pObject, m_CurrentChunk);
295 ReadUVCoordinates(pObject, m_CurrentChunk);
310 delete m_CurrentChunk;
311 m_CurrentChunk = pPreviousChunk;
321 void CLoad3DS::ProcessNextMaterialChunk(
mo3DSModel *pModel,
tChunk *pPreviousChunk)
323 int buffer[50000] = {0};
328 m_CurrentChunk =
new tChunk;
334 ReadChunk(m_CurrentChunk);
337 switch(m_CurrentChunk->
ID)
368 texMapInfo.
id = m_CurrentChunk->
ID;
370 ProcessNextMaterialChunk(pModel, m_CurrentChunk);
411 delete m_CurrentChunk;
412 m_CurrentChunk = pPreviousChunk;
421 void CLoad3DS::ReadChunk(
tChunk *pChunk)
426 pChunk->
bytesRead = fread(&pChunk->
ID, 1, 2, m_FilePointer);
439 int CLoad3DS::GetString(
char *pBuffer)
444 fread(pBuffer, 1, 1, m_FilePointer);
447 while(*(pBuffer + index++) != 0) {
450 fread(pBuffer + index, 1, 1, m_FilePointer);
454 return strlen(pBuffer) + 1;
467 ReadChunk(m_TempChunk);
499 unsigned short index = 0;
518 for(
int j = 0; j < 4; j++)
521 pPreviousChunk->
bytesRead += fread(&index, 1,
sizeof(index), m_FilePointer);
588 float fTempY = pObject->
pVerts[i].
y;
595 pObject->
pVerts[i].
z = -fTempY;
608 char strMaterial[255] = {0};
609 int buffer[50000] = {0};
617 pPreviousChunk->
bytesRead += GetString(strMaterial);
630 if(strcmp(strMaterial, pModel->
pMaterials[i].strName) == 0)
637 if( pModel->
pMaterials[i].texMaps.size() > 0 ) {
666 #define Mag(Normal)(sqrt(Normal.x*Normal.x + Normal.y*Normal.y + Normal.z*Normal.z))
673 vVector.
x = vPoint1.
x - vPoint2.
x;
674 vVector.
y = vPoint1.
y - vPoint2.
y;
675 vVector.
z = vPoint1.
z - vPoint2.
z;
685 vResult.
x = vVector2.
x + vVector1.
x;
686 vResult.
y = vVector2.
y + vVector1.
y;
687 vResult.
z = vVector2.
z + vVector1.
z;
697 vResult.
x = vVector1.
x / Scaler;
698 vResult.
y = vVector1.
y / Scaler;
699 vResult.
z = vVector1.
z / Scaler;
709 vCross.
x =((vVector1.
y * vVector2.
z) -(vVector1.
z * vVector2.
y));
711 vCross.
y =((vVector1.
z * vVector2.
x) -(vVector1.
x * vVector2.
z));
713 vCross.
z =((vVector1.
x * vVector2.
y) -(vVector1.
y * vVector2.
x));
723 Magnitude =
Mag(vNormal);
725 vNormal.
x /=(float)Magnitude;
726 vNormal.
y /=(float)Magnitude;
727 vNormal.
z /=(float)Magnitude;
738 void CLoad3DS::ComputeNormals(
mo3DSModel *pModel)
742 CVector3 vVector1, vVector2, vNormal, vPoly[3];
778 vVector1 = Vector(vPoly[0], vPoly[2]);
779 vVector2 = Vector(vPoly[2], vPoly[1]);
781 vNormal = Cross(vVector1, vVector2);
782 pTempNormals[i] = vNormal;
783 vNormal = Normalize(vNormal);
785 pNormals[i] = vNormal;
802 vSum = AddVector(vSum, pTempNormals[j]);
808 pObject->
pNormals[i] = DivideVectorByScaler(vSum,
float(-shared));
818 delete [] pTempNormals;
#define MAT_DIFFUSE_COLOR
#define MAT_SHININESS_MAP_CHUNK
#define MAT_OPACITY_MAP_CHUNK
#define MAT_SELF_ILLUM_MAP_CHUNK
#define MAT_TEXTURE_MAP2_CHUNK
#define MAT_TEXTURE_MAP1_CHUNK
#define MAT_AMBIENT_COLOR
#define MAT_SPECULAR_MAP_CHUNK
vector< mo3DSObject > pObject
#define MAT_SPECULAR_COLOR
bool Import3DS(mo3DSModel *pModel, char *strFileName)
#define MAT_REFLECTION_MAP_CHUNK
vector< mo3DSMaterialInfo > pMaterials
#define MAT_BUMP_MAP_CHUNK