void ObjLoader::LoadFile(const std::string& filename, RigidBodyGeometry* geom) { geom->Reset(); ifstream objFileP; objFileP.open(filename.c_str()); if(!objFileP) { assert(0 && "File could not be opened"); return; } string str; while (getline(objFileP,str)) { // objFileP >> output; stringstream iss(str); char type[2]; type[0] = 0; type[1] = 0; iss >> type; if((type[0] == 'v') && (type[1] == 0)) { Vertex v = geom->MakeVertex(); real x,y,z; iss >> x >> y >> z; Point3 p(x,y,z); v.SetPos(p); geom->AddVertex(v); } else if((type[0] == 'f') && (type[1] == 0))
void Mesh::ReadMesh(string filename){ FILE *in=NULL; const char* file; file=filename.c_str(); errno_t err; err = fopen_s( &in, file, "r" ); if( err == 0 ) cout<<"The file '"<<filename<<"' was opened"<<endl; else cout<<"The file '"<<filename<<"' was not opened"<<endl; char ext[5]; int dV=0; int dF=0; int dE=0; int i=0; int temp(0); //for assert fscanf_s(in,"%s",ext,_countof(ext)); fscanf_s(in,"%d",&dV); fscanf_s(in,"%d",&dF); fscanf_s(in,"%d",&dE); strcpy_s(m_Mesh_format,ext); cout<<"MeshFile Format: " <<ext<<endl; //read vertex Vertex dvetex; double dx=0.0; double dy=0.0; double dz=0.0; for(i=0;i<dV;i++){ fscanf_s(in,"%lf%lf%lf",&dx,&dy,&dz); dvetex.SetPos(dx,dy,dz); m_Mesh_vetexs.push_back(dvetex); } temp=m_Mesh_vetexs.size(); assert( temp == dV ); cout<<"Vetex Num: "<<dV<<endl; //read faces int val; int di; int dj; int dk; Face dface; for(i=0;i<dF;i++){ fscanf_s(in,"%d%d%d%d",&val,&di,&dj,&dk); dface.SetVextexIndex(di,dj,dk); m_Mesh_faces.push_back(dface); } assert(m_Mesh_faces.size()==dF); cout<<"Face Num: "<<dF<<endl; //Read Edgs: fclose(in); }