iphone - Fastest way to load arrays of vertices and face indices into OpenGL-ES? -


i'm trying load .obj files i've formatted into:

vertexx vertexy vertexz normalx normaly normalz 

and:

index1 index2 index3 

format vector , vector arrays, directly render in opengl-es. problem is, when try load model arrays, takes 40 seconds load them in. i'm not sure why it's going slow, i've seen others code load same model in few seconds. suggestions? code loading file below:

-(void)loadmodel:(nsstring*)filepath {     try {      ifstream objfile([filepath utf8string]);     objfile >> numvertices;     objfile.ignore(128, '\n');     vertices.resize(numvertices*6);     vertexnormal* vertex = (vertexnormal*) &vertices[0];     svec3* facedef;      while (objfile) {         char c = objfile.get();          switch (c) {             case 'v':             {                 objfile >> vertex->vertices.x >> vertex->vertices.y >> vertex->vertices.z                 >> vertex->normals.x >> vertex->normals.y >> vertex->normals.z;                 vertex++;                 break;             }             case 'f':             {                 objfile >> facedef->x >> facedef->y >> facedef->z;                 facedef++;                 break;             }             case '#':             {                 part newpart;                 partlist.push_back(newpart);                 numobjects++;                 objfile.ignore(128, '\n');                 int numfaces;                 objfile >> numfaces;                 partlist[partlist.size()-1].faces.resize(numfaces*3);                 partlist[partlist.size()-1].numfaces = numfaces;                 facedef = (svec3*) &partlist[partlist.size()-1].faces[0];                 break;             }             default:                 break;         }         objfile.ignore(128, '\n');     }     objfile.close();     free(objfile);     } catch (nsexception *ex) {         nslog(@"%@", [ex reason]);     } } 

one line of thought had serialize arrays binary file, deserialize them straight program. haven't figured out how yet though, maybe along lines might solution.

the best practice in game industry keep models data in binary format, can fast load whole non-interleaved blocks of memory can represented vertices, normals or else. need - make small command line tool converting text .obj files own binary file.

also:

  • did try text loading stdio library, not stl ifstream?
  • maybe try read text data once , fill arrays memory, not filesystem?
  • how parts in file have? each resize of std::vector leads new allocation , copying. try reserve space in std::vector, if know desired volume before.

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -