00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ExCModel3DS.h"
00025
00026 ExCModel3DS::ExCModel3DS(void)
00027 {
00028 Guard(ExCModel3DS::ExCModel3DS(void))
00029 ExCModel::ExCModel();
00030 SetName("ExCModel3DS");
00031 SetType(typeid(this).name());
00032 m_ListId=-1;
00033 m_CollisionGizmo=new ExCGizmoRectangle;
00034 m_CollisionCounter=0;
00035 HasList=false;
00036 HasArray=false;
00037 m_AlwaysDraw=false;
00038 SetVisibleState(true);
00039
00040 m_RenderMode=RENDER_VERTEX_ARRAY;
00041 UnGuard
00042 }
00043
00044 ExCModel3DS::~ExCModel3DS(void)
00045 {
00046 Guard(ExCModel3DS::~ExCModel3DS(void))
00047 UnGuard
00048 }
00049 void ExCModel3DS::BuildArray(int Rendu)
00050 {
00051 Guard(void ExCModel3DS::BuildArray(int Rendu))
00052 ExCVec3D VecAB,VecBC,VecCA,VecFace;
00053 ExCVec3D VecX,VecY,VecZ;
00054 ExCVec2D VecTAB,VecTBC,VecTCA;
00055
00056 for(unsigned int i=0;i<m_VecObject->size();i++)
00057 {
00058
00059 m_VecObject->at(i).TabVertices= new float[m_VecObject->at(i).Faces.size()*9];
00060 m_VecObject->at(i).TabTextures= new float[m_VecObject->at(i).Faces.size()*6];
00061
00062 for(unsigned int j=0;j<m_VecObject->at(i).Faces.size();j++)
00063 {
00064 VecFace.SetX(m_VecObject->at(i).Faces.at(j).vertIndex[0]);
00065 VecFace.SetY(m_VecObject->at(i).Faces.at(j).vertIndex[1]);
00066 VecFace.SetZ(m_VecObject->at(i).Faces.at(j).vertIndex[2]);
00067
00068
00069
00070 VecTAB.SetX(m_VecObject->at(i).TexVerts.at(VecFace.GetX()).GetX());
00071 VecTAB.SetY(m_VecObject->at(i).TexVerts.at(VecFace.GetX()).GetY());
00072
00073 VecTBC.SetX(m_VecObject->at(i).TexVerts.at(VecFace.GetY()).GetX());
00074 VecTBC.SetY(m_VecObject->at(i).TexVerts.at(VecFace.GetY()).GetY());
00075
00076 VecTCA.SetX(m_VecObject->at(i).TexVerts.at(VecFace.GetZ()).GetX());
00077 VecTCA.SetY(m_VecObject->at(i).TexVerts.at(VecFace.GetZ()).GetY());
00078
00079 m_VecObject->at(i).TabTextures[0+j*6]=VecTAB.GetX();
00080 m_VecObject->at(i).TabTextures[1+j*6]=VecTAB.GetY();
00081 m_VecObject->at(i).TabTextures[2+j*6]=VecTBC.GetX();
00082 m_VecObject->at(i).TabTextures[3+j*6]=VecTBC.GetY();
00083 m_VecObject->at(i).TabTextures[4+j*6]=VecTCA.GetX();
00084 m_VecObject->at(i).TabTextures[5+j*6]=VecTCA.GetY();
00085
00086
00087
00088 VecX.SetX(m_VecObject->at(i).Verts.at(VecFace.GetX()).GetX());
00089 VecX.SetY(m_VecObject->at(i).Verts.at(VecFace.GetX()).GetY());
00090 VecX.SetZ(m_VecObject->at(i).Verts.at(VecFace.GetX()).GetZ());
00091
00092 VecY.SetX(m_VecObject->at(i).Verts.at(VecFace.GetY()).GetX());
00093 VecY.SetY(m_VecObject->at(i).Verts.at(VecFace.GetY()).GetY());
00094 VecY.SetZ(m_VecObject->at(i).Verts.at(VecFace.GetY()).GetZ());
00095
00096 VecZ.SetX(m_VecObject->at(i).Verts.at(VecFace.GetZ()).GetX());
00097 VecZ.SetY(m_VecObject->at(i).Verts.at(VecFace.GetZ()).GetY());
00098 VecZ.SetZ(m_VecObject->at(i).Verts.at(VecFace.GetZ()).GetZ());
00099
00100 m_VecObject->at(i).TabVertices[0+j*9]=VecX.GetX();
00101 m_VecObject->at(i).TabVertices[1+j*9]=VecX.GetY();
00102 m_VecObject->at(i).TabVertices[2+j*9]=VecX.GetZ();
00103 m_VecObject->at(i).TabVertices[3+j*9]=VecY.GetX();
00104 m_VecObject->at(i).TabVertices[4+j*9]=VecY.GetY();
00105 m_VecObject->at(i).TabVertices[5+j*9]=VecY.GetZ();
00106 m_VecObject->at(i).TabVertices[6+j*9]=VecZ.GetX();
00107 m_VecObject->at(i).TabVertices[7+j*9]=VecZ.GetY();
00108 m_VecObject->at(i).TabVertices[8+j*9]=VecZ.GetZ();
00109 }
00110 }
00111 HasArray=true;
00112 UnGuard
00113 }
00114
00115 void ExCModel3DS::Draw(void)
00116 {
00117 Guard(void ExCModel3DS::Draw(void))
00118 try
00119 {
00120 ExCVec3D VecAB,VecBC,VecCA,VecFace;
00121 ExCVec3D VecX,VecY,VecZ;
00122 bool DrawIt=false;
00123 ProcessAllAction();
00124 if(!m_Visible)return;
00125 if(HasList==false)BuildList(RENDER_TEXTURES);
00126 if(HasArray==false)BuildArray(RENDER_TEXTURES);
00127 glPushMatrix();
00128
00129
00130 glRotatef(-90,1,0,0);
00131 if(m_AlwaysDraw)
00132 {
00133 switch(m_RenderMode)
00134 {
00135 case RENDER_VERTEX_ARRAY:CallAllArray();break;
00136 case RENDER_DISPLAY_LIST:CallAllList();break;
00137 }
00138
00139
00140 }else
00141 {
00142
00143 ExCFrustum Frustrum;
00144 Frustrum.CalculateFrustum();
00145 for(unsigned int i=0;i<m_VecObject->size();i++)
00146 {
00147 DrawIt=false;
00148 for(unsigned int j=0;j<m_VecObject->at(i).Faces.size();j++)
00149 {
00150 VecFace.SetX(m_VecObject->at(i).Faces.at(j).vertIndex[0]);
00151 VecFace.SetY(m_VecObject->at(i).Faces.at(j).vertIndex[1]);
00152 VecFace.SetZ(m_VecObject->at(i).Faces.at(j).vertIndex[2]);
00153
00154
00155
00156 VecX.SetX(m_VecObject->at(i).Verts.at(VecFace.GetX()).GetX());
00157 VecX.SetY(m_VecObject->at(i).Verts.at(VecFace.GetX()).GetY());
00158 VecX.SetZ(m_VecObject->at(i).Verts.at(VecFace.GetX()).GetZ());
00159 VecY.SetX(m_VecObject->at(i).Verts.at(VecFace.GetY()).GetX());
00160 VecY.SetY(m_VecObject->at(i).Verts.at(VecFace.GetY()).GetY());
00161 VecY.SetZ(m_VecObject->at(i).Verts.at(VecFace.GetY()).GetZ());
00162 VecZ.SetX(m_VecObject->at(i).Verts.at(VecFace.GetZ()).GetX());
00163 VecZ.SetY(m_VecObject->at(i).Verts.at(VecFace.GetZ()).GetY());
00164 VecZ.SetZ(m_VecObject->at(i).Verts.at(VecFace.GetZ()).GetZ());
00165 VecX=VecX+m_Position;
00166 VecY=VecY+m_Position;
00167 VecZ=VecZ+m_Position;
00168 if(Frustrum.PointInFrustum(VecX.GetX(),VecX.GetY(),VecX.GetZ())){DrawIt=true;}
00169 if(Frustrum.PointInFrustum(VecY.GetX(),VecY.GetY(),VecY.GetZ())){DrawIt=true;}
00170 if(Frustrum.PointInFrustum(VecZ.GetX(),VecZ.GetY(),VecZ.GetZ())){DrawIt=true;}
00171 }
00172 if(DrawIt)
00173 {
00174 switch(m_RenderMode)
00175 {
00176 case RENDER_VERTEX_ARRAY:
00177
00178 glDisable(GL_LIGHTING);
00179 glColor3f(1.0f,1.0f,1.0f);
00180 ManagerTexture->SetTexture(0,m_VecObject->at(i).Material);
00181 glTexCoordPointer(2,GL_FLOAT,0,m_VecObject->at(i).TabTextures);
00182 glEnableClientState(GL_VERTEX_ARRAY);
00183 glVertexPointer(3,GL_FLOAT,0,m_VecObject->at(i).TabVertices);
00184 glDrawArrays( GL_TRIANGLES, 0, m_VecObject->at(i).Faces.size()*3 );
00185 ManagerTexture->ResetMultitexture();
00186 break;
00187 case RENDER_DISPLAY_LIST:
00188
00189 glCallList(m_VecObject->at(i).m_ListId);
00190 break;
00191 }
00192 }
00193 }
00194 }
00195
00196 glPopMatrix();
00197 }catch (...)
00198 {
00199 std::cout<<"probleme"<<std::endl;
00200 }
00201 UnGuard
00202 }
00203
00204 void ExCModel3DS::CallAllList(void)
00205 {
00206 Guard(void ExCModel3DS::CallAllList(void))
00207 for(unsigned int i=0;i<m_VecObject->size();i++)
00208 {
00209 glCallList(m_VecObject->at(i).m_ListId);
00210 }
00211 UnGuard
00212 }
00213
00214 void ExCModel3DS::CallAllArray(void)
00215 {
00216 Guard(void ExCModel3DS::CallAllArray(void))
00217 for(unsigned int i=0;i<m_VecObject->size();i++)
00218 {
00219 glDisable(GL_LIGHTING);
00220 glColor3f(1.0f,1.0f,1.0f);
00221 ManagerTexture->SetTexture(0,m_VecObject->at(i).Material);
00222 glTexCoordPointer(2,GL_FLOAT,0,m_VecObject->at(i).TabTextures);
00223 glEnableClientState(GL_VERTEX_ARRAY);
00224 glVertexPointer(3,GL_FLOAT,0,m_VecObject->at(i).TabVertices);
00225 glDrawArrays( GL_TRIANGLES, 0, m_VecObject->at(i).Faces.size()*3 );
00226 ManagerTexture->ResetMultitexture();
00227 }
00228 UnGuard
00229 }
00230
00231
00232 void ExCModel3DS::BuildList(int Rendu)
00233 {
00234 Guard(void ExCModel3DS::BuildList(int Rendu))
00235
00236
00237 ExCVec3D VecAB,VecBC,VecCA,VecFace;
00238 ExCVec3D VecX,VecY,VecZ;
00239 ExCVec2D VecTAB,VecTBC,VecTCA;
00240 glPushMatrix();
00241
00242 glDisable(GL_LIGHTING);
00243 for(unsigned int i=0;i<m_VecObject->size();i++)
00244 {
00245 try
00246 {
00247 glDeleteLists(m_VecObject->at(i).m_ListId,1);
00248 m_VecObject->at(i).m_ListId=glGenLists(1);
00249 glNewList(m_VecObject->at(i).m_ListId,GL_COMPILE);
00250 for(unsigned int j=0;j<m_VecObject->at(i).Faces.size();j++)
00251 {
00252 VecFace.SetX(m_VecObject->at(i).Faces.at(j).vertIndex[0]);
00253 VecFace.SetY(m_VecObject->at(i).Faces.at(j).vertIndex[1]);
00254 VecFace.SetZ(m_VecObject->at(i).Faces.at(j).vertIndex[2]);
00255
00256
00257
00258 VecTAB.SetX(m_VecObject->at(i).TexVerts.at(VecFace.GetX()).GetX());
00259 VecTAB.SetY(m_VecObject->at(i).TexVerts.at(VecFace.GetX()).GetY());
00260
00261 VecTBC.SetX(m_VecObject->at(i).TexVerts.at(VecFace.GetY()).GetX());
00262 VecTBC.SetY(m_VecObject->at(i).TexVerts.at(VecFace.GetY()).GetY());
00263
00264 VecTCA.SetX(m_VecObject->at(i).TexVerts.at(VecFace.GetZ()).GetX());
00265 VecTCA.SetY(m_VecObject->at(i).TexVerts.at(VecFace.GetZ()).GetY());
00266
00267
00268
00269
00270 VecX.SetX(m_VecObject->at(i).Verts.at(VecFace.GetX()).GetX());
00271 VecX.SetY(m_VecObject->at(i).Verts.at(VecFace.GetX()).GetY());
00272 VecX.SetZ(m_VecObject->at(i).Verts.at(VecFace.GetX()).GetZ());
00273
00274 VecY.SetX(m_VecObject->at(i).Verts.at(VecFace.GetY()).GetX());
00275 VecY.SetY(m_VecObject->at(i).Verts.at(VecFace.GetY()).GetY());
00276 VecY.SetZ(m_VecObject->at(i).Verts.at(VecFace.GetY()).GetZ());
00277
00278 VecZ.SetX(m_VecObject->at(i).Verts.at(VecFace.GetZ()).GetX());
00279 VecZ.SetY(m_VecObject->at(i).Verts.at(VecFace.GetZ()).GetY());
00280 VecZ.SetZ(m_VecObject->at(i).Verts.at(VecFace.GetZ()).GetZ());
00281
00282 ManagerTexture->SetCurrentObject(m_VecObject->at(i).Material);
00283
00284 glColor3f(1.0f,1.0f,1.0f);
00285 glEnable(GL_TEXTURE_2D);
00286 glBegin(GL_TRIANGLES);
00287 glTexCoord2f(VecTAB.GetX(),VecTAB.GetY());
00288 glVertex3fv(VecX.m_Vector);
00289 glTexCoord2f(VecTBC.GetX(),VecTBC.GetY());
00290 glVertex3fv(VecY.m_Vector);
00291 glTexCoord2f(VecTCA.GetX(),VecTCA.GetY());
00292 glVertex3fv(VecZ.m_Vector);
00293 glEnd();
00294 glDisable(GL_TEXTURE_2D);
00295
00296 }
00297 glEndList();
00298 }catch (...)
00299 {
00300 std::cout<<"error building list"<<std::endl;
00301 }
00302
00303 }
00304 glPopMatrix();
00305
00306
00307 HasList=true;
00308
00309 UnGuard
00310 }
00311
00312 ExCAction ExCModel3DS::InputAction(ExCAction Action)
00313 {
00314
00315 switch(Action.m_Action)
00316 {
00317 case NEXT_FRAME:
00318 NextFrame();
00319 break;
00320 case PREVIOUS_FRAME:
00321 break;
00322 case SET_CURENT_FRAME:
00323 break;
00324 case START_ACTION:
00325 StartAction(Action.m_Param);
00326 break;
00327 case STOP_ACTION:
00328 StopAction(Action.m_Param);
00329 break;
00330 case TURN_LEFT:
00331 StartAction("TURN_LEFT");
00332 break;
00333 case TURN_RIGHT:
00334 StartAction("TURN_RIGHT");
00335 case LOOK_UP:
00336 StartAction(Action.m_Param);
00337 break;
00338 case LOOK_DOWN:
00339 StartAction(Action.m_Param);
00340 break;
00341 case MODEL_SET_POS_X:
00342 std::cout<<"MODEL"<<Action<<atof(Action.m_Param.data());
00343 m_Position.SetX(atof(Action.m_Param.data()));
00344 break;
00345 case MODEL_SET_POS_Y:
00346 m_Position.SetY(atof(Action.m_Param.data()));
00347 break;
00348 case MODEL_SET_POS_Z:
00349 m_Position.SetZ(atof(Action.m_Param.data()));
00350 break;
00351 case MODEL_SET_ANGLE_X:
00352 m_Angle.SetX(atof(Action.m_Param.data()));
00353 break;
00354 case MODEL_SET_ANGLE_Y:
00355 m_Angle.SetY(atof(Action.m_Param.data()));
00356 break;
00357 case MODEL_SET_ANGLE_Z:
00358 m_Angle.SetZ(atof(Action.m_Param.data()));
00359 break;
00360 case MODEL_START_ROTATE_Y_DOWN:
00361 StartAction("TURN_RIGHT");
00362 break;
00363 case MODEL_STOP_ROTATE_Y_DOWN:
00364 StopAction("TURN_RIGHT");
00365 if(!IsAction("RUN")){StartAction("IDLE");}
00366 break;
00367 case MODEL_START_ROTATE_Y_UP:
00368 StartAction("TURN_LEFT");
00369 break;
00370 case MODEL_STOP_ROTATE_Y_UP:
00371 StopAction("TURN_LEFT");
00372 if(!IsAction("RUN")){StartAction("IDLE");}
00373 break;
00374 case MODEL_START_ROTATE_Z_DOWN:
00375 StartAction("LOOK_UP");
00376 break;
00377 case MODEL_STOP_ROTATE_Z_DOWN:
00378 StopAction("LOOK_UP");
00379 break;
00380 case MODEL_START_ROTATE_Z_UP:
00381 StartAction("LOOK_DOWN");
00382 break;
00383 case MODEL_STOP_ROTATE_Z_UP:
00384 StopAction("LOOK_DOWN");
00385 break;
00386 case MODEL_START_ROTATE_X_DOWN:
00387 StartAction("X_DOWN");
00388 break;
00389 case MODEL_STOP_ROTATE_X_DOWN:
00390 StopAction("X_DOWN");
00391 break;
00392 case MODEL_START_ROTATE_X_UP:
00393 StartAction("X_UP");
00394 break;
00395 case MODEL_STOP_ROTATE_X_UP:
00396 StopAction("X_UP");
00397 break;
00398 case MODEL_START_MOVE_FORWARD:
00399 StartAction("RUN");
00400 m_Acceleration=m_Acceleration+0.01;
00401 break;
00402 case MODEL_STOP_MOVE_FORWARD:
00403 StopAction("RUN");
00404 StartAction("IDLE");
00405 m_Acceleration.SetValue(0.0f,0.0f,0.0f);
00406 break;
00407 case MODEL_JUMP:
00408 StartAction("JUMP");
00409 break;
00410 case MODEL_SET_ACTION:
00411 break;
00412 case MODEL_STOP_ALL:
00413 m_VecAction.clear();
00414 m_Velocity.SetValue(0.0f,0.0f,0.0f);
00415 m_Acceleration.SetValue(0.0f,0.0f,0.0f);
00416 break;
00417 case MODEL_SHOW_COLLISION_SPHERE:
00418
00419 break;
00420 case MODEL_START_STRAFE_LEFT:
00421 StartAction("STRAFE_LEFT");
00422 break;
00423 case MODEL_STOP_STRAFE_LEFT :
00424 StopAction("STRAFE_LEFT");
00425 break;
00426 case MODEL_START_STRAFE_RIGHT:
00427 StartAction("STRAFE_RIGHT");
00428 break;
00429 case MODEL_STOP_STREFA_RIGHT:
00430 StopAction("STRAFE_RIGHT");
00431 break;
00432 case MODEL_TOGGLE_VISIBLESTATE:
00433 SetVisibleState(!GetVisibleState());
00434
00435 break;
00436 case MODEL_HIDE:
00437 SetVisibleState(false);
00438
00439 break;
00440 case MODEL_SHOW:
00441 SetVisibleState(true);
00442
00443 break;
00444 case MODEL_TOGGLE_ALWAYS_DRAW:
00445 m_AlwaysDraw=!m_AlwaysDraw;
00446 break;
00447 case MODEL_ALWAYS_DRAW_ON:
00448 m_AlwaysDraw=true;
00449 break;
00450 case MODEL_ALWAYS_DRAW_OFF:
00451 m_AlwaysDraw=false;
00452 break;
00453 case MODEL_SET_RENDER_MODE:
00454 m_RenderMode=atoi(Action.m_Param.data());
00455 break;
00456 }
00457 return NOTHING;
00458 }
00459
00460 void ExCModel3DS::Process(std::string Action)
00461 {
00462 Guard(void ExCModel3DS::Process(std::string Action))
00463 if(m_Angle.GetX()<0)m_Angle.SetX(359);
00464 if(m_Angle.GetX()>359)m_Angle.SetX(0);
00465 if(m_Angle.GetY()<0)m_Angle.SetY(359);
00466 if(m_Angle.GetY()>359)m_Angle.SetY(0);
00467 if(m_Angle.GetZ()<0)m_Angle.SetZ(359);
00468 if(m_Angle.GetZ()>359)m_Angle.SetZ(0);
00469
00470 if(Action=="RUN")
00471 {
00472
00473
00474
00475 }
00476 if(Action=="STRAFE_LEFT")
00477 {
00478 float angle;
00479 angle=m_Angle.GetY()+90;
00480 if(angle>360)angle=angle-360;
00481 m_Position=m_Position+ExCVec3D(Cos[(int)angle],0.0f,Sin[(int)angle]);
00482 return;
00483 }
00484 if(Action=="STRAFE_RIGHT")
00485 {
00486 float angle;
00487 angle=m_Angle.GetY()+90;
00488 if(angle>360)angle=angle-360;
00489 m_Position=m_Position-ExCVec3D(Cos[(int)angle],0.0f,Sin[(int)angle]);
00490 return;
00491 }
00492
00493 if(Action=="TURN_LEFT"){m_Angle.DecY(2);return;}
00494 if(Action=="TURN_RIGHT"){m_Angle.IncY(2);return;}
00495 if(Action=="LOOK_UP"){m_Angle.IncZ(2);return;}
00496 if(Action=="LOOK_DOWN"){m_Angle.DecZ(2);return;}
00497 if(Action=="X_UP"){m_Angle.IncX(2);return;}
00498 if(Action=="X_DOWN"){m_Angle.DecX(2);return;}
00499 if(Action=="JUMP")
00500 {
00501 if(m_CurrentFrames=72)
00502 {
00503 StopAction("JUMP");
00504 if(!IsAction("RUN")){StartAction("IDLE");}
00505 }
00506 }
00507 UnGuard
00508 }
00509 void ExCModel3DS::ProcessAllAction(void)
00510 {
00511 Guard(void ExCModel3DS::ProcessAllAction(void))
00512 for(unsigned int i=0;i< m_VecAction.size();i++)
00513 {
00514 Process(m_VecAction.at(i));
00515 }
00516 UnGuard
00517 }
00518
00519 void ExCModel3DS::StopAction(std::string Action)
00520 {
00521 Guard(void ExCModel3DS::StopAction(std::string Action))
00522 for(m_IVecAction= m_VecAction.begin();m_IVecAction!= m_VecAction.end();m_IVecAction++)
00523 {
00524 if(strcmp(m_IVecAction->data(),Action.data())==0)
00525 {
00526 m_VecAction.erase(m_IVecAction);
00527 return;
00528 }
00529 }
00530 UnGuard
00531 }
00532
00533 bool ExCModel3DS::IsAction(std::string Action)
00534 {
00535 Guard(bool ExCModel3DS::IsAction(std::string Action))
00536 for(m_IVecAction= m_VecAction.begin();m_IVecAction!= m_VecAction.end();m_IVecAction++)
00537 {
00538 if(strcmp(m_IVecAction->data(),Action.data())==0)
00539 {
00540 return true;
00541 }
00542 }
00543 return false;
00544 UnGuard
00545 }
00546 void ExCModel3DS::StartAction(std::string Action)
00547 {
00548 Guard(void ExCModel3DS::StartAction(std::string Action))
00549 m_VecAction.push_back(Action);
00550 m_CurrentAction=Action;
00551 UnGuard
00552 }
00553
00554
00555 bool ExCModel3DS::Load(std::string FileName)
00556 {
00557 Guard(bool ExCModel3DS::Load(std::string FileName))
00558
00559 m_VecObject= new std::vector<t3DObject> ;
00560 numOfObjects=0;
00561 numOfMaterials=0;
00562 m_VecMaterials.clear();
00563 m_VecObject->clear();
00564 HasList=false;
00565 unsigned int version=0;
00566 int buffer[50000] = {0};
00567 char bufferc[255];memset(bufferc,0,255);
00568
00569
00570 m_filePtr = fopen(FileName.data(), "rb");
00571 if (m_filePtr == NULL)
00572 {
00573 throw ExCExpFileNotFound();
00574 return false;
00575 }
00576 tChunk *chunk;
00577 chunk = new tChunk;
00578 ReadChunk(chunk);
00579
00580 if(chunk->ID==PRIMARY)
00581 {
00582
00583 m_CurrentChunk = new tChunk;
00584 while (chunk->bytesRead < chunk->length)
00585 {
00586 ReadChunk(m_CurrentChunk);
00587 switch(m_CurrentChunk->ID)
00588 {
00589 case FILEVERSION:
00590 m_CurrentChunk->bytesRead += fread(&version, 1,m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_filePtr);
00591
00592 break;
00593 case OBJECTINFO:
00594
00595 ReadObjectInfo(m_CurrentChunk);
00596 break;
00597 case EDITKEYFRAME:
00598
00599 Skip(m_CurrentChunk);
00600 break;
00601 default:
00602
00603 Skip(m_CurrentChunk);
00604 break;
00605 }
00606 chunk->bytesRead += m_CurrentChunk->bytesRead;
00607 }
00608 delete m_CurrentChunk;
00609 m_CurrentChunk = chunk;
00610 }
00611
00612 fclose(m_filePtr);
00613
00614 return true;
00615 UnGuard
00616 }
00617
00618 void ExCModel3DS::ReadObjectInfo(tChunk *chunk)
00619 {
00620 Guard(void ExCModel3DS::ReadObjectInfo(tChunk *chunk))
00621 int buffer[50000] = {0};
00622 char bufferc[255],b;
00623 std::string BuffObject;
00624 m_CurrentChunk = new tChunk;
00625 while (chunk->bytesRead < chunk->length)
00626 {
00627 ReadChunk(m_CurrentChunk);
00628 switch(m_CurrentChunk->ID)
00629 {
00630 case MATERIAL:
00631
00632 ReadObjectMaterial(m_CurrentChunk);
00633 break;
00634 case OBJECT:
00635 memset(bufferc,0,255);
00636
00637
00639 BuffObject.erase(BuffObject.begin(),BuffObject.end());
00640 do
00641 {
00642 m_CurrentChunk->bytesRead += fread(&b, 1, sizeof(char), m_filePtr);
00643 if(b!=0)BuffObject=BuffObject+b;
00644 }while(b!=0);
00645
00646 ReadObject(m_CurrentChunk);
00647 break;
00648 case MESH_VERSION:
00649
00650 Skip(m_CurrentChunk);
00651 break;
00652 case MASTER_SCALE:
00653
00654 Skip(m_CurrentChunk);
00655 break;
00656 default:
00657
00658 Skip(m_CurrentChunk);
00659 break;
00660 }
00661 chunk->bytesRead += m_CurrentChunk->bytesRead;
00662 }
00663 delete m_CurrentChunk;
00664 m_CurrentChunk = chunk;
00665 UnGuard
00666 }
00667 void ExCModel3DS::ReadObject(tChunk *chunk)
00668 {
00669 Guard(void ExCModel3DS::ReadObject(tChunk *chunk))
00670 int buffer[50000] = {0};
00671 t3DObject *pObject;
00672 pObject = new t3DObject;
00673 m_CurrentChunk = new tChunk;
00674 while (chunk->bytesRead < chunk->length)
00675 {
00676 ReadChunk(m_CurrentChunk);
00677 switch(m_CurrentChunk->ID)
00678 {
00679 case OBJECT_MESH:
00680
00681 ReadObject(m_CurrentChunk);
00682 break;
00683 case OBJECT_VERTICES:
00684
00685
00686 ReadVertices(pObject,m_CurrentChunk);
00687 break;
00688 case OBJECT_FACES:
00689
00690 ReadFace(pObject,m_CurrentChunk);
00691 break;
00692 case OBJECT_MATERIAL:
00693
00694
00695 ReadObjectMaterial(pObject,m_CurrentChunk);
00696 break;
00697 case OBJECT_UV:
00698
00699 ReadUVCoordinates(pObject,m_CurrentChunk);
00700 break;
00701 case OBJECT_MESH_MATRIX:
00702
00703 Skip(m_CurrentChunk);
00704 break;
00705 default:
00706
00707 Skip(m_CurrentChunk);
00708 break;
00709 }
00710 chunk->bytesRead += m_CurrentChunk->bytesRead;
00711 }
00712
00713 m_VecObject->push_back(*pObject);
00714 delete m_CurrentChunk;
00715 m_CurrentChunk = chunk;
00716 UnGuard
00717 }
00718
00719 void ExCModel3DS::ReadObjectMaterial(tChunk *chunk)
00720 {
00721 Guard(void ExCModel3DS::ReadObjectMaterial(tChunk *chunk))
00722 int buffer[50000] = {0};
00723 char bufferc[255];
00724 m_CurrentChunk = new tChunk;
00725 while (chunk->bytesRead < chunk->length)
00726 {
00727 ReadChunk(m_CurrentChunk);
00728 switch(m_CurrentChunk->ID)
00729 {
00730 case MATNAME:
00731 memset(bufferc,0,255);
00732 m_CurrentChunk->bytesRead += fread(bufferc, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_filePtr);
00733
00734 break;
00735 case MATAMBIENTCOLOR:
00736
00737 Skip(m_CurrentChunk);
00738 break;
00739 case MATDIFFUSE:
00740
00741 Skip(m_CurrentChunk);
00742 break;
00743 case MATSPECULAR:
00744
00745 Skip(m_CurrentChunk);
00746 break;
00747 case MATSHININESS:
00748
00749 Skip(m_CurrentChunk);
00750 break;
00751 case MATSHININESSSTR:
00752
00753 Skip(m_CurrentChunk);
00754 break;
00755 case MATTRANSPARENCY:
00756
00757 Skip(m_CurrentChunk);
00758 break;
00759 case MATTRANSFALLOFF:
00760
00761 Skip(m_CurrentChunk);
00762 break;
00763 case MATREFLECTBLUR:
00764
00765 Skip(m_CurrentChunk);
00766 break;
00767 case MATTWOSIDED:
00768
00769 Skip(m_CurrentChunk);
00770 break;
00771 case MATTRANSPARENCYADD:
00772
00773 Skip(m_CurrentChunk);
00774 break;
00775 case MATSELFILUM:
00776
00777 Skip(m_CurrentChunk);
00778 break;
00779 case MATWIREON:
00780
00781 Skip(m_CurrentChunk);
00782 break;
00783 case MATWIRETHICKNESS:
00784
00785 Skip(m_CurrentChunk);
00786 break;
00787 case MATFACEMAP:
00788
00789 Skip(m_CurrentChunk);
00790 break;
00791 case MATTRANSFALLOFFIN:
00792
00793 Skip(m_CurrentChunk);
00794 break;
00795 case MATSOFTEN:
00796
00797 Skip(m_CurrentChunk);
00798 break;
00799 case MAT3DWIRETHICKNESS:
00800
00801 Skip(m_CurrentChunk);
00802 break;
00803 case MATTYPE:
00804
00805 Skip(m_CurrentChunk);
00806 break;
00807 case MATMAP:
00808
00809 ReadObjectMaterial(m_CurrentChunk);
00810 break;
00811 case MATMAPFILE:
00812
00813 Skip(m_CurrentChunk);
00814 break;
00815 case MATMAPOPTION:
00816
00817 Skip(m_CurrentChunk);
00818 break;
00819 case MATMAPFILTERINGBLUR:
00820
00821
00822 Skip(m_CurrentChunk);
00823 break;
00824 default:
00825
00826 Skip(m_CurrentChunk);
00827 break;
00828 }
00829 chunk->bytesRead += m_CurrentChunk->bytesRead;
00830 }
00831 delete m_CurrentChunk;
00832 m_CurrentChunk = chunk;
00833 UnGuard
00834 }
00835
00836
00837
00838 void ExCModel3DS::ReadChunk(tChunk *chunk)
00839 {
00840 Guard(void ExCModel3DS::tChunk ReadChunk(tChunk *chunk))
00842 chunk->bytesRead = fread(&chunk->ID, 1, 2, m_filePtr);
00843 chunk->bytesRead += fread(&chunk->length, 1, 4, m_filePtr);
00847 UnGuard
00848 }
00849
00850 void ExCModel3DS::Skip(tChunk *chunk)
00851 {
00852 Guard(void ExCModel3DS::tChunk Skip(tChunk *chunk))
00853 int buffer[50000] = {0};
00855 chunk->bytesRead += fread(buffer, 1, chunk->length - chunk->bytesRead, m_filePtr);
00856 UnGuard
00857 }
00858
00859 void ExCModel3DS::ReadVertices(t3DObject *pObject,tChunk *chunk)
00860 {
00861 Guard(void ExCModel3DS::ReadVertices(t3DObject *pObject,tChunk *chunk))
00862 int buffer[50000] = {0};
00863
00864 unsigned short vert;
00865 chunk->bytesRead += fread(&vert, 1,sizeof(unsigned short), m_filePtr);
00866 pObject->numOfVerts=vert;
00868 float fl;
00869 ExCVec3D vec;
00870 for(int i=0;i<vert;i++)
00871 {
00872 chunk->bytesRead += fread(&fl, 1,sizeof(float), m_filePtr);
00873 vec.SetX(fl);
00874 chunk->bytesRead += fread(&fl, 1,sizeof(float), m_filePtr);
00875 vec.SetY(fl);
00876 chunk->bytesRead += fread(&fl, 1,sizeof(float), m_filePtr);
00877 vec.SetZ(fl);
00879 pObject->Verts.push_back(vec);
00880 }
00881 Skip(chunk);
00882 UnGuard
00883 }
00884
00885 void ExCModel3DS::ReadFace(t3DObject *pObject,tChunk *chunk)
00886 {
00887 Guard(void ExCModel3DS::ReadFace(t3DObject *pObject,tChunk *chunk))
00888 int buffer[50000] = {0};
00889
00890 tFace stFace;
00891 unsigned short face,index;
00892 chunk->bytesRead += fread(&face, 1,sizeof(unsigned short), m_filePtr);
00893 pObject->numOfFaces=face;
00895
00896
00897 for(int i = 0; i <face; i++)
00898 {
00899
00900
00901 for(int j = 0; j < 4; j++)
00902 {
00903
00904 chunk->bytesRead += fread(&index, 1, sizeof(unsigned short), m_filePtr);
00905
00906 if(j < 3)
00907 {
00908
00909
00910 stFace.vertIndex[j]=index;
00911 }
00912 }
00914 pObject->Faces.push_back(stFace);
00915 }
00916 char b=0;
00917 std::string Material;
00918 m_CurrentChunk = new tChunk;
00919 while (chunk->bytesRead < chunk->length)
00920 {
00921 ReadChunk(m_CurrentChunk);
00922 switch(m_CurrentChunk->ID)
00923 {
00924 case OBJECT_MATERIAL:
00925
00926 do
00927 {
00928 m_CurrentChunk->bytesRead += fread(&b, 1, sizeof(char), m_filePtr);
00929 if(b!=0)Material=Material+b;
00930 }while(b!=0);
00932 pObject->Material=Material;
00933
00934 ManagerTexture->Load(Material);
00935 Skip(m_CurrentChunk);
00936 break;
00937 case OBJECT_SMOOTH_GROUP:
00938
00939 Skip(m_CurrentChunk);
00940 break;
00941 default:
00942
00943 Skip(m_CurrentChunk);
00944 break;
00945 }
00946 chunk->bytesRead += m_CurrentChunk->bytesRead;
00947 }
00948 delete m_CurrentChunk;
00949 m_CurrentChunk = chunk;
00950
00951
00952
00953 UnGuard
00954 }
00955
00956 void ExCModel3DS::ReadUVCoordinates(t3DObject *pObject,tChunk *chunk)
00957 {
00958 Guard(void ExCModel3DS::ReadUVCoordinates(t3DObject *pObject,tChunk *chunk))
00959 int buffer[50000] = {0};
00960
00961 unsigned short vert;
00962 chunk->bytesRead += fread(&vert, 1,sizeof(unsigned short), m_filePtr);
00963 pObject->numTexVertex=vert;
00965 float fl;
00966 ExCVec2D vec;
00967 for(int i=0;i<vert;i++)
00968 {
00969 chunk->bytesRead += fread(&fl, 1,sizeof(float), m_filePtr);
00970 vec.SetX(fl);
00971 chunk->bytesRead += fread(&fl, 1,sizeof(float), m_filePtr);
00972 vec.SetY(fl);
00974 pObject->TexVerts.push_back(vec);
00975 }
00976 Skip(chunk);
00977 UnGuard
00978 }
00979
00980 void ExCModel3DS::ReadObjectMaterial(t3DObject *pObject,tChunk *chunk)
00981 {
00982 Guard(void ExCModel3DS::ReadObjectMaterial(tChunk *chunk))
00983 char b=0;
00984 std::string Material;
00985 do
00986 {
00987 chunk->bytesRead += fread(&b, 1, sizeof(char), m_filePtr);
00988 Material=Material+b;
00989 }while(b!=0);
00990
00991 Skip(chunk);
00992 UnGuard
00993 }