|
From: julien r. <jul...@us...> - 2004-11-02 15:32:28
|
Update of /cvsroot/epfl/tgengine-0.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25269 Modified Files: Makefile Makefile.Linux Makefile.OSX camera.cc glrenderer.cc md5instance.cc md5instance.h md5mesh10.cc md5mesh10.h quaternion.cc quaternion.h scenemanager.cc Log Message: animations md5 Index: quaternion.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/quaternion.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** quaternion.h 28 Oct 2004 21:10:16 -0000 1.3 --- quaternion.h 2 Nov 2004 15:32:16 -0000 1.4 *************** *** 25,29 **** Quaternion operator + (const Quaternion& q); Quaternion operator - (const Quaternion& q); ! Quaternion operator * (Quaternion q); Quaternion operator / (Quaternion q); Quaternion operator += (const Quaternion& q); --- 25,29 ---- Quaternion operator + (const Quaternion& q); Quaternion operator - (const Quaternion& q); ! Quaternion operator * (Quaternion q) const; Quaternion operator / (Quaternion q); Quaternion operator += (const Quaternion& q); Index: quaternion.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/quaternion.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** quaternion.cc 28 Oct 2004 21:10:16 -0000 1.2 --- quaternion.cc 2 Nov 2004 15:32:16 -0000 1.3 *************** *** 24,28 **** } ! Quaternion Quaternion::operator * (Quaternion q) { return Quaternion (r*q.r - x*q.x - y*q.y - z*q.z, --- 24,28 ---- } ! Quaternion Quaternion::operator * (Quaternion q) const { return Quaternion (r*q.r - x*q.x - y*q.y - z*q.z, Index: camera.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/camera.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** camera.cc 30 Oct 2004 17:43:27 -0000 1.7 --- camera.cc 2 Nov 2004 15:32:15 -0000 1.8 *************** *** 142,147 **** //glRotatef(vEuler.x, 1.0f, 0.0f, 0.0f); //glRotatef(vEuler.y, 0.0f, 1.0f, 0.0f); ! Vector3 axis = qRotation.GetRotationAxis (); ! float a = RADTODEG*qRotation.GetRotationAngle (); //std::cout << "camera : " << qRotation << std::endl; float matrix[16]; --- 142,147 ---- //glRotatef(vEuler.x, 1.0f, 0.0f, 0.0f); //glRotatef(vEuler.y, 0.0f, 1.0f, 0.0f); ! //Vector3 axis = qRotation.GetRotationAxis (); ! //float a = RADTODEG*qRotation.GetRotationAngle (); //std::cout << "camera : " << qRotation << std::endl; float matrix[16]; Index: scenemanager.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenemanager.cc,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** scenemanager.cc 28 Oct 2004 21:10:16 -0000 1.11 --- scenemanager.cc 2 Nov 2004 15:32:16 -0000 1.12 *************** *** 186,190 **** } while((p=p->GetNext()) != NULL); } - //TODO: enlever ca #ifdef DEBUG Engine::pRenderer->Render (); --- 186,189 ---- Index: md5mesh10.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5mesh10.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** md5mesh10.h 30 Sep 2004 09:23:16 -0000 1.3 --- md5mesh10.h 2 Nov 2004 15:32:16 -0000 1.4 *************** *** 7,10 **** --- 7,11 ---- #include "base.h" #include "quaternion.h" + #include "material.h" namespace tg *************** *** 30,33 **** --- 31,40 ---- bool LoadAnim(char* str); + //Material + inline Material* GetMaterial (int imesh) { return pMeshes[imesh].pMaterial; } + + //Animations informations + int GetAnimIndex(const std::string& name); + //Joint informations inline int GetNumJoints() { return iNumJoints; } *************** *** 149,152 **** --- 156,163 ---- unsigned int* pIndexes; + + Material* pMaterial; + std::string sColor; + std::string sNormal; }; Index: glrenderer.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/glrenderer.cc,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** glrenderer.cc 28 Oct 2004 21:10:16 -0000 1.11 --- glrenderer.cc 2 Nov 2004 15:32:15 -0000 1.12 *************** *** 1106,1111 **** (*_glClientActiveTextureARB) (GL_TEXTURE0); glEnable (GL_TEXTURE_2D); - if (mesh->GetMaterial() && mesh->GetMaterial()->HasPrimary()) - glBindTexture (GL_TEXTURE_2D, mesh->GetMaterial()->GetFirstTexture()->iId); glEnableClientState(GL_TEXTURE_COORD_ARRAY); --- 1106,1109 ---- *************** *** 1127,1130 **** --- 1125,1129 ---- if (mesh->GetMaterial(j) && mesh->GetMaterial(j)->HasPrimary()) glBindTexture (GL_TEXTURE_2D, mesh->GetMaterial(j)->GetFirstTexture()->iId); + glVertexPointer(3, GL_FLOAT, sizeof(Vertice) , &pVerts[0].vPosition); glTexCoordPointer(2, GL_FLOAT, sizeof(Vertice), &pVerts[0].s); *************** *** 1132,1135 **** --- 1131,1135 ---- glDrawElements(GL_TRIANGLES, mesh->GetTrianglesCount(j)*3, GL_UNSIGNED_INT, pIndexes); + /*glBegin (GL_TRIANGLES); for (unsigned int i=0; i<mesh->GetTrianglesCount(j)*3; i++) Index: Makefile =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/Makefile,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Makefile 1 Nov 2004 08:57:10 -0000 1.12 --- Makefile 2 Nov 2004 15:32:15 -0000 1.13 *************** *** 11,15 **** linux: ! make -f Makefile.Linux --- 11,15 ---- linux: ! make -f Makefile.Linux "CFLAGS = -O3 -DTGLINUX" Index: Makefile.Linux =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/Makefile.Linux,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile.Linux 27 Sep 2004 21:34:05 -0000 1.3 --- Makefile.Linux 2 Nov 2004 15:32:15 -0000 1.4 *************** *** 13,17 **** all : $(OBJS) ! gcc -shared -o out/libtgengine.so $(OBJS) clean : --- 13,17 ---- all : $(OBJS) ! $(CC) -shared -o out/libtgengine.so $(OBJS) clean : Index: md5instance.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5instance.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** md5instance.cc 28 Oct 2004 21:10:16 -0000 1.6 --- md5instance.cc 2 Nov 2004 15:32:15 -0000 1.7 *************** *** 153,156 **** --- 153,160 ---- { pVerticesListTab[i][j].vPosition.Null(); + //assignation des texcoords. + //FIXME: On pourrait éviter ça et ne le faire qu'une seule fois nan ? + pVerticesListTab[i][j].s = pData->vert_GetTexCoords(i,j)[0]; + pVerticesListTab[i][j].t = pData->vert_GetTexCoords(i,j)[1]; for (int k=0; k<pData->vert_GetNumWeights(i, j); k++) *************** *** 250,254 **** pJoint->vPosition = q.Rotate(animatedPosition); pJoint->vPosition += v; ! pJoint->qOrientation = animatedOrientation*q; } --- 254,258 ---- pJoint->vPosition = q.Rotate(animatedPosition); pJoint->vPosition += v; ! pJoint->qOrientation = q*animatedOrientation; } *************** *** 261,264 **** --- 265,273 ---- //glPopMatrix (); } + void MD5Instance::SetAnimation (const std::string& name) + { + iCurrentAnimation = pData->GetAnimIndex(name); + } + #if 0 void MD5Mesh::BuildBone (int frame, _MD5Bone* b) Index: Makefile.OSX =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/Makefile.OSX,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile.OSX 16 Oct 2004 14:01:34 -0000 1.7 --- Makefile.OSX 2 Nov 2004 15:32:15 -0000 1.8 *************** *** 14,18 **** all : $(OBJS) ! g++ -dynamiclib $(LIBS) -o out/libtgengine.dylib $(OBJS) clean : --- 14,18 ---- all : $(OBJS) ! $(CC) -dynamiclib $(LIBS) -o out/libtgengine.dylib $(OBJS) clean : Index: md5instance.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5instance.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** md5instance.h 28 Oct 2004 21:10:16 -0000 1.5 --- md5instance.h 2 Nov 2004 15:32:16 -0000 1.6 *************** *** 26,36 **** ~MD5Instance (); ! void SetAnimation (std::string name); void PreRender (float); unsigned int GetMeshesCount () { return iNumMeshes; } unsigned int GetTrianglesCount (int imesh=0) { return pData->mesh_GetNumTris(imesh); } - Material* GetMaterial (int imesh=0) { return NULL; } Vertice* GetVertexList (int imesh=0) { return pVerticesListTab[imesh]; } unsigned int GetVerticesCount(int imesh=0) { return pData->mesh_GetNumVerts(imesh); } --- 26,36 ---- ~MD5Instance (); ! void SetAnimation (const std::string& name); void PreRender (float); + inline Material* GetMaterial (int imesh) { return pData->GetMaterial(imesh); } unsigned int GetMeshesCount () { return iNumMeshes; } unsigned int GetTrianglesCount (int imesh=0) { return pData->mesh_GetNumTris(imesh); } Vertice* GetVertexList (int imesh=0) { return pVerticesListTab[imesh]; } unsigned int GetVerticesCount(int imesh=0) { return pData->mesh_GetNumVerts(imesh); } Index: md5mesh10.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5mesh10.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** md5mesh10.cc 21 Oct 2004 21:18:28 -0000 1.4 --- md5mesh10.cc 2 Nov 2004 15:32:16 -0000 1.5 *************** *** 1,250 **** ! #include "md5mesh10.h" ! #include "quaternion.h" ! ! namespace tg ! { ! ! MD5Mesh10::MD5Mesh10 () ! { ! pAnimations.clear(); ! } ! ! MD5Mesh10::~ MD5Mesh10() ! { ! delete [] pJoints; ! for (int i=0; i<iNumMeshes; i++) ! { ! delete [] pMeshes[i].pVerts; ! delete [] pMeshes[i].pTriangles; ! delete [] pMeshes[i].pIndexes; ! delete [] pMeshes[i].pWeights; ! } ! delete [] pMeshes; ! for (unsigned int i=0; i<pAnimations.size(); i++) ! { ! for (int j=0; j<pAnimations[i].iNumJoints; j++) ! delete [] pAnimations[i].pBaseFrame[j]; ! delete [] pAnimations[i].pBaseFrame; ! delete [] pAnimations[i].pJointInfos; ! ! for (int j=0; j<pAnimations[i].iNumFrames; j++) ! delete [] pAnimations[i].pFrames[j]; ! delete [] pAnimations[i].pFrames; ! ! } ! pAnimations.clear(); ! } ! ! #define NEXT(str) while(buffer.find(str)==std::string::npos) \ ! pFD >> buffer; ! ! bool MD5Mesh10::LoadMesh(char* str) ! { ! std::ifstream pFD; ! std::string buffer; ! int version; ! ! std::cout << "[TGE] Chargement de " << str << std::endl; ! ! pFD.open(str, std::ios::in); ! ! if (pFD.fail()) ! { ! std::cerr << "[TGE] Erreur lors de l'ouverture de " << str << std::endl; ! return false; ! } ! ! pFD >> buffer; ! pFD >> version; ! ! if (version != 10) ! { ! std::cerr << "[TGE] Mauvaise version : " << version << std::endl; ! return false; ! } ! ! NEXT("numJoints") ! pFD >> iNumJoints; ! ! NEXT("numMeshes") ! pFD >> iNumMeshes; ! ! iNumBaseJoints = 0; ! pJoints = new _MD5Joint[iNumJoints]; ! ! for (int i=0; i<iNumJoints; i++) ! { ! NEXT("\"") ! pJoints[i].sName = buffer; ! //std::cout << pJoints[i].sName << std::endl; ! Quaternion q; ! //pFD >> pJoints[i].iNumber; ! pFD >> pJoints[i].iParent; ! if (pJoints[i].iParent < 0) ! iNumBaseJoints++; ! NEXT("(") ! pFD >> pJoints[i].vPosition.x >> pJoints[i].vPosition.y >> pJoints[i].vPosition.z; ! ! Util::ChangeCoords(pJoints[i].vPosition); ! //ChangeCoords(pJoints[i].vPosition); ! ! NEXT(")") ! NEXT("(") ! pFD >> q.x >> q.y >> q.z; ! Util::ChangeCoords(q.x, q.y, q.z); ! ! q.ComputeR(); ! ! pJoints[i].qOrientation = q; ! //Util::QuaternionToMatrix33(q,pJoints[i].mOrientation); ! } ! pMeshes = new _MD5Mesh[iNumMeshes]; ! for (int i=0; i<iNumMeshes; i++) ! { ! NEXT("numverts") ! pFD >> pMeshes[i].iNumVerts; ! pFD >> buffer; //sans ca, le NEXT("vert") ne va pas bouger car vert est deja dans numverts ! ! pMeshes[i].pVerts = new _MD5Vert[pMeshes[i].iNumVerts]; ! for (int j=0; j<pMeshes[i].iNumVerts; j++) ! { ! _MD5Vert& vert = pMeshes[i].pVerts[j]; ! NEXT("vert") ! NEXT("(") ! pFD >> vert.pTexCoords[0] >>vert.pTexCoords[1]; ! NEXT(")") ! pFD >> vert.iWeightIndex >> vert.iNumWeights; ! ! } ! NEXT("numtris") ! pFD >> pMeshes[i].iNumTris; ! ! pMeshes[i].pTriangles = new _MD5Triangle[pMeshes[i].iNumTris]; ! pMeshes[i].pIndexes = new unsigned int[pMeshes[i].iNumTris*3]; ! int iC = 0; ! pFD >> buffer; //sans ca, le NEXT("tri") ne va pas bouger car tri est deja dans numtris ! for (int j=0; j<pMeshes[i].iNumTris; j++) ! { ! _MD5Triangle& tri = pMeshes[i].pTriangles[j]; ! NEXT("tri") ! pFD >> buffer; ! pFD >> tri.pIndex[0] >> tri.pIndex[1] >> tri.pIndex[2]; ! ! pMeshes[i].pIndexes[iC] = pMeshes[i].pTriangles[j].pIndex[0]; ! iC++; ! pMeshes[i].pIndexes[iC] = pMeshes[i].pTriangles[j].pIndex[1]; ! iC++; ! pMeshes[i].pIndexes[iC] = pMeshes[i].pTriangles[j].pIndex[2]; ! iC++; ! } ! ! NEXT("numweights") ! pFD >> pMeshes[i].iNumWeights; ! pFD >> buffer; // sans ca, le NEXT("weight") foire ! pMeshes[i].pWeights = new _MD5Weight[pMeshes[i].iNumWeights]; ! for (int j=0; j<pMeshes[i].iNumWeights; j++) ! { ! _MD5Weight& w = pMeshes[i].pWeights[j]; ! NEXT("weight") ! pFD >> buffer; ! pFD >> w.iBoneIndex >> w.fBias; ! NEXT("(") ! pFD >> w.vWeights.x >> w.vWeights.y >> w.vWeights.z; ! Util::ChangeCoords(w.vWeights); ! } ! } ! ! std::cout << "[TGE] Chargement de " << str << " termine" << std::endl; ! return true; ! ! } ! ! bool MD5Mesh10::LoadAnim(char* str) ! { ! _MD5Anim anim; ! anim.sName = std::string(str); ! //std::string animname(str); ! //_MD5Anim& anim = mAnimations[animname]; ! ! std::ifstream pFD; ! std::string buffer; ! int version; ! ! std::cout << "Chargement de " << str << std::endl; ! ! pFD.open(str, std::ios::in); ! ! if (pFD.fail()) ! { ! std::cerr << "[TGE] Erreur lors de l'ouverture de " << str << std::endl; ! return false; ! } ! ! pFD >> buffer; ! pFD >> version; ! ! if (version != 10) ! { ! std::cerr << "[TGE] Mauvaise version : " << version << std::endl; ! return false; ! } ! ! NEXT("numFrames") ! pFD >> anim.iNumFrames; ! NEXT("numJoints") ! pFD >> anim.iNumJoints; ! NEXT("frameRate") ! pFD >> anim.iFrameRate; ! NEXT("numAnimatedComponents") ! pFD >> anim.iNumAnimatedComponents; ! ! anim.pFrames = new float*[anim.iNumFrames]; ! for (int i=0; i<anim.iNumFrames; i++) ! anim.pFrames[i] = new float[anim.iNumAnimatedComponents]; ! ! anim.pJointInfos = new _MD5Anim::_MD5JointInfos[anim.iNumJoints]; ! ! anim.pBaseFrame = new float*[anim.iNumJoints]; ! ! //FIXME: a priori, il n'y a pas de md5mesh ou la hierarchie de l'anim est different du md5mesh. Ceci dit, on peut peut-etre utiliser ca pour demembrer ou autre ! NEXT("hierarchy") ! for (int i=0; i<anim.iNumJoints; i++) ! { ! NEXT("\"") ! buffer = ""; ! pFD >> anim.pJointInfos[i].iParent; ! pFD >> anim.pJointInfos[i].iFlags; ! pFD >> anim.pJointInfos[i].iStartIndex; ! } ! ! //chargement de baseframe ! NEXT("baseframe") ! for (int i=0; i<anim.iNumJoints; i++) ! { ! anim.pBaseFrame[i] = new float[6]; ! NEXT("(") ! pFD >> anim.pBaseFrame[i][0]; ! pFD >> anim.pBaseFrame[i][1]; ! pFD >> anim.pBaseFrame[i][2]; ! NEXT(")") ! NEXT("(") ! pFD >> anim.pBaseFrame[i][3]; ! pFD >> anim.pBaseFrame[i][4]; ! pFD >> anim.pBaseFrame[i][5]; ! NEXT(")") ! } ! //chargement des frames ! for (int i=0; i<anim.iNumFrames; i++) ! { ! NEXT("frame") ! NEXT("{") ! for (int j=0; j<anim.iNumAnimatedComponents; j++) ! pFD >> anim.pFrames[i][j]; ! NEXT("}") ! } ! pAnimations.push_back(anim); ! std::cout << "Chargement de " << str << " termine" << std::endl; ! return true; ! } ! ! } --- 1 ---- ! #include "md5mesh10.h" #include "quaternion.h" namespace tg { MD5Mesh10::MD5Mesh10 () { pAnimations.clear(); } MD5Mesh10::~ MD5Mesh10() { delete [] pJoints; for (int i=0; i<iNumMeshes; i++) { delete [] pMeshes[i].pVerts; delete [] pMeshes[i].pTriangles; delete [] pMeshes[i].pIndexes; delete [] pMeshes[i].pWeights; } delete [] pMeshes; for (unsigned int i=0; i<pAnimations.size(); i++) { for (int j=0; j<pAnimations[i].iNumJoints; j++) delete [] pAnimations[i].pBaseFrame[j]; delete [] pAnimations[i].pBaseFrame; delete [] pAnimations[i].pJointInfos; for (int j=0; j<pAnimations[i].iNumFrames; j++) delete [] pAnimations[i].pFrames[j]; delete [] pAnimations[i].pFrames; } pAnimations.clear(); } #define NEXT(str) while(buffer.find(str)==std::string::npos) \ pFD >> buffer; bool MD5Mesh10::LoadMesh(char* str) { std::ifstream pFD; std::string buffer; int version; std::cout << "[TGE] Chargement de " << str << std::endl; pFD.open(str, std::ios::in); if (pFD.fail()) { std::cerr << "[TGE] Erreur lors de l'ouverture de " << str << std::endl; return false; } pFD >> buffer; pFD >> version; if (version != 10) { std::cerr << "[TGE] Mauvaise version : " << version << std::endl; return false; } NEXT("numJoints") pFD >> iNumJoints; NEXT("numMeshes") pFD >> iNumMeshes; iNumBaseJoints = 0; pJoints = new _MD5Joint[iNumJoints]; for (int i=0; i<iNumJoints; i++) { NEXT("\"") pJoints[i].sName = buffer; //std::cout << pJoints[i].sName << std::endl; Quaternion q; //pFD >> pJoints[i].iNumber; pFD >> pJoints[i].iParent; if (pJoints[i].iParent < 0) iNumBaseJoints++; NEXT("(") pFD >> pJoints[i].vPosition.x >> pJoints[i].vPosition.y >> pJoints[i].vPosition.z; //Util::ChangeCoords(pJoints[i].vPosition); //ChangeCoords(pJoints[i].vPosition); NEXT(")") NEXT("(") pFD >> q.x >> q.y >> q.z; //Util::ChangeCoords(q.x, q.y, q.z); q.ComputeR(); pJoints[i].qOrientation = q; //Util::QuaternionToMatrix33(q,pJoints[i].mOrientation); } pMeshes = new _MD5Mesh[iNumMeshes]; for (int i=0; i<iNumMeshes; i++) { NEXT("shader") std::string sTmp; pFD >> sTmp; int iLastSlash = sTmp.find_last_of("/"); int iLastQuote = sTmp.find_last_of("\""); iLastSlash += 1; //on veut le caractere juste apres le dernier slash sTmp.erase(iLastQuote); pMeshes[i].sNormal = "data/textures/models/"+sTmp.substr(iLastSlash); pMeshes[i].sColor = pMeshes[i].sNormal+"_color.bmp"; pMeshes[i].sNormal += ".bmp"; //pMeshes[i].sNormal = "data/notexture.bmp"; //pMeshes[i].sColor = "data/notexture.bmp"; pMeshes[i].pMaterial = new Material (); Texture* tmpTex = new Texture (); tmpTex->LoadBMP((char*)pMeshes[i].sNormal.data(), TG_TEXTURE_2D); pMeshes[i].pMaterial->SetNormalTexture(tmpTex); tmpTex = new Texture(); tmpTex->LoadBMP((char*)pMeshes[i].sColor.data(), TG_TEXTURE_2D); pMeshes[i].pMaterial->SetFirstTexture(tmpTex); NEXT("numverts") pFD >> pMeshes[i].iNumVerts; pFD >> buffer; //sans ca, le NEXT("vert") ne va pas bouger car vert est deja dans numverts pMeshes[i].pVerts = new _MD5Vert[pMeshes[i].iNumVerts]; for (int j=0; j<pMeshes[i].iNumVerts; j++) { _MD5Vert& vert = pMeshes[i].pVerts[j]; NEXT("vert") NEXT("(") pFD >> vert.pTexCoords[0] >>vert.pTexCoords[1]; vert.pTexCoords[1] = 1 - vert.pTexCoords[1]; NEXT(")") pFD >> vert.iWeightIndex >> vert.iNumWeights; } NEXT("numtris") pFD >> pMeshes[i].iNumTris; pMeshes[i].pTriangles = new _MD5Triangle[pMeshes[i].iNumTris]; pMeshes[i].pIndexes = new unsigned int[pMeshes[i].iNumTris*3]; int iC = 0; pFD >> buffer; //sans ca, le NEXT("tri") ne va pas bouger car tri est deja dans numtris for (int j=0; j<pMeshes[i].iNumTris; j++) { _MD5Triangle& tri = pMeshes[i].pTriangles[j]; NEXT("tri") pFD >> buffer; pFD >> tri.pIndex[0] >> tri.pIndex[1] >> tri.pIndex[2]; pMeshes[i].pIndexes[iC] = pMeshes[i].pTriangles[j].pIndex[0]; iC++; pMeshes[i].pIndexes[iC] = pMeshes[i].pTriangles[j].pIndex[1]; iC++; pMeshes[i].pIndexes[iC] = pMeshes[i].pTriangles[j].pIndex[2]; iC++; } NEXT("numweights") pFD >> pMeshes[i].iNumWeights; pFD >> buffer; // sans ca, le NEXT("weight") foire pMeshes[i].pWeights = new _MD5Weight[pMeshes[i].iNumWeights]; for (int j=0; j<pMeshes[i].iNumWeights; j++) { _MD5Weight& w = pMeshes[i].pWeights[j]; NEXT("weight") pFD >> buffer; pFD >> w.iBoneIndex >> w.fBias; NEXT("(") pFD >> w.vWeights.x >> w.vWeights.y >> w.vWeights.z; //Util::ChangeCoords(w.vWeights); } } std::cout << "[TGE] Chargement de " << str << " termine" << std::endl; return true; } bool MD5Mesh10::LoadAnim(char* str) { _MD5Anim anim; //on garde juste le nom de l'animation std::string sTemp = std::string(str); int iLastSlash = sTemp.find_last_of("/"); int iLastPoint = sTemp.find_last_of("."); sTemp.erase(iLastPoint); anim.sName = sTemp.substr(iLastSlash+1); std::cout << "[TGE] anim name : " << anim.sName << std::endl; std::ifstream pFD; std::string buffer; int version; std::cout << "[TGE] Chargement de " << str << std::endl; pFD.open(str, std::ios::in); if (pFD.fail()) { std::cerr << "[TGE] Erreur lors de l'ouverture de " << str << std::endl; return false; } pFD >> buffer; pFD >> version; if (version != 10) { std::cerr << "[TGE] Mauvaise version : " << version << std::endl; return false; } NEXT("numFrames") pFD >> anim.iNumFrames; NEXT("numJoints") pFD >> anim.iNumJoints; NEXT("frameRate") pFD >> anim.iFrameRate; NEXT("numAnimatedComponents") pFD >> anim.iNumAnimatedComponents; anim.pFrames = new float*[anim.iNumFrames]; for (int i=0; i<anim.iNumFrames; i++) anim.pFrames[i] = new float[anim.iNumAnimatedComponents]; anim.pJointInfos = new _MD5Anim::_MD5JointInfos[anim.iNumJoints]; anim.pBaseFrame = new float*[anim.iNumJoints]; //FIXME: a priori, il n'y a pas de md5mesh ou la hierarchie de l'anim est different du md5mesh. Ceci dit, on peut peut-etre utiliser ca pour demembrer ou autre NEXT("hierarchy") for (int i=0; i<anim.iNumJoints; i++) { NEXT("\"") buffer = ""; pFD >> anim.pJointInfos[i].iParent; pFD >> anim.pJointInfos[i].iFlags; pFD >> anim.pJointInfos[i].iStartIndex; } //chargement de baseframe NEXT("baseframe") for (int i=0; i<anim.iNumJoints; i++) { anim.pBaseFrame[i] = new float[6]; NEXT("(") pFD >> anim.pBaseFrame[i][0]; pFD >> anim.pBaseFrame[i][1]; pFD >> anim.pBaseFrame[i][2]; NEXT(")") NEXT("(") pFD >> anim.pBaseFrame[i][3]; pFD >> anim.pBaseFrame[i][4]; pFD >> anim.pBaseFrame[i][5]; NEXT(")") } //chargement des frames for (int i=0; i<anim.iNumFrames; i++) { NEXT("frame") NEXT("{") for (int j=0; j<anim.iNumAnimatedComponents; j++) pFD >> anim.pFrames[i][j]; NEXT("}") } pAnimations.push_back(anim); std::cout << "[TGE] Chargement de " << str << " termine" << std::endl; return true; } int MD5Mesh10::GetAnimIndex(const std::string& name) { int size = pAnimations.size(); for (int i=0; i<size; i++) { if (pAnimations[i].sName == name) return i; } return -1; } } \ No newline at end of file |