void OBJModel::process_line(std::string const& line) { std::vector<std::string> tokens = tokenize(line); if (tokens.size() > 0) { std::string token = tokens[0]; tokens.erase(tokens.begin()); if (token == "v") { process_v(tokens); } else if (token == "vt") { process_vt(tokens); } else if (token == "vn") { process_vn(tokens); } else if (token == "f") { process_f(tokens); } else if (token == "g") { process_g(tokens); } } }
int arread( int (*rf)( void *data, int len ), void (*process_f)(const char *fname, void *data, int len) ) { char *nametab = 0; char *arIndex = 0; char ghbuf[GHSIZE]; struct arreader a; if( GHSIZE != rf( ghbuf, GHSIZE )) { die( &a, "no hdr"); } while(1) { char fhbuf[FHSIZE]; int ret = rf( fhbuf, FHSIZE ); if( ret == 0 ) break; if( FHSIZE != ret ) { die( &a, "no fhdr"); } char r_fname[17]; strlcpy( r_fname, fhbuf, 16 ); char r_fsize[10]; strlcpy( r_fsize, fhbuf+48, 9 ); if( fhbuf[58] != 0x60u || fhbuf[59] != 0x0Au ) { //hexdump(fhbuf, FHSIZE, "", 0); printf("name '%s', size '%s' magic: %x %x\n", r_fname, r_fsize, fhbuf[58], fhbuf[59] ); die( &a, "no file magic" ); } //printf("name '%s', size '%s'\n", r_fname, r_fsize ); //printf("name '%s'\n", r_fname ); int size = (int)atol(r_fsize); pack((unsigned char *)r_fname); //printf("name '%s'\n", r_fname ); int isSlash = !strcmp( r_fname, "/" ); if(isSlash) { /* char *arIndex = calloc( size+1, 1 ); if( arIndex == 0 || size != rf( arIndex, size ) ) die( &a, "can't load /"); */ arIndex = loadall( &a, rf, size ); //printf("/=\n'%.*s'\n", size, arIndex ); parseIndex( &a, arIndex, size); } int isSlashSlash = !strcmp( r_fname, "//" ); if(isSlashSlash) { /* nametab = calloc( size+1, 1 ); if( nametab == 0 || size != rf( nametab, size ) ) die( &a, "can't load //"); */ nametab = loadall( &a, rf, size ); //printf("//=\n%.*s\n", size, nametab ); } char *fname = r_fname; if( r_fname[0] == '/' && r_fname[1] ) fname = getLongName( &a, nametab, (int) atol(r_fname+1) ); if(!isSlashSlash && !isSlash) { //rdata( rf, size, fname ); void *d = loadall( &a, rf, size ); process_f( fname, d, size ); free(d); } // align at 2 bytes if( size & 1 ) rf( fhbuf, 1 ); } if(nametab) free(nametab); if(arIndex) free(arIndex); return 0; /* die: if(nametab) free(nametab); if(arIndex) free(arIndex); return -1; */ }