/* LIBBUBULLES some functions for importing bubulles from dot-OBJ files. */ #include #include #include #include "bubulles.h" extern int verbosity; /* --------------------------------------------------------------------- */ #define LINE_SZ 666 int try_to_read_an_OBJ_file(char *fname, int notused) { FILE *fpin; char line[LINE_SZ+1], *cptr; float x, y, z; int foo, nbre; BBList *bublist; Bubulle bubulle; #if DEBUG_LEVEL fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused); #endif if (NULL==(fpin=fopen(fname, "r"))) { perror(fname); exit(1); } bublist = alloc_bubulles(fname, 1000, 0); if (NULL==bublist) { fprintf(stderr, "err in %s, aborting...\n", __func__); abort(); } print_bublist_desc(bublist, 0); nbre = 0; while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { if (verbosity>1) fputs(line, stderr); cptr = strtok(line, " "); if (strcmp(cptr, "v")) continue; cptr = strtok(NULL, " "); foo = sscanf(cptr, "%f", &x); cptr = strtok(NULL, " "); foo = sscanf(cptr, "%f", &y); cptr = strtok(NULL, " "); foo = sscanf(cptr, "%f", &z); memset(&bubulle, 0, sizeof(Bubulle)); bubulle.p.x = x; bubulle.p.y = y; bubulle.p.z = z; if (verbosity > 1) niceprint_bubulle(&bubulle, 0); foo = push_bubulle(bublist, &bubulle); if (foo) { fprintf(stderr, "%s: err %d on push\n", __func__, foo); break; } nbre++; } fclose(fpin); if(verbosity) { fprintf(stderr, "%s : %d vertices loaded\n", __func__, nbre); } bubulles_to_data("xyz", NULL, bublist, 0); return 0; } /* --------------------------------------------------------------------- */