more work done on .OBJ import

This commit is contained in:
tTh
2023-03-30 05:39:36 +02:00
parent 9577f1da1f
commit b861e8c86b
5 changed files with 53 additions and 20 deletions

View File

@@ -82,36 +82,50 @@ int parse_face(char *cptr, int phy)
int ix, foo;
int fa, fb;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, cptr, phy);
#endif
for (ix=0; ix<3; ix++) {
cptr = strtok(NULL, " ");
if (NULL == cptr) {
fprintf(stderr, "incomplete face in %s\n", __func__);
return -4;
}
if (2 != sscanf(cptr, "%d/%d", &fa, &fb)) {
fprintf(stderr, "%s: err sscanf\n", __func__);
exit(1);
return -3;
}
fprintf(stderr, " %d got %d %d\n", ix, fa, fb);
// XXX fprintf(stderr, " %d got %d %d\n", ix, fa, fb);
/*
* yes, i've found 0-lenght edges, wtf ?
*/
if (fa == fb) continue;
if (fa == fb) {
// fprintf(stderr, "'%s' dublicate\n", cptr);
continue;
}
foo = push_a_missing_edge(edges, fa, fb);
if (foo) {
fprintf(stderr, "%s: disaster #%d\n", __func__, foo);
#if MUST_ABORT
abort();
fflush(stderr), abort();
#endif
return -2;
}
}
#if DEBUG_LEVEL
fprintf(stderr, "<<< %s\n", __func__);
#endif
return 0;
}
/* --------------------------------------------------------------------- */
int try_to_read_an_OBJ_file(char *infname, char *outfname, int notused)
int try_to_read_an_OBJ_file(char *infname, char *file_vert, char *file_edges,
int notused)
{
FILE *fpin;
char line[LINE_SZ+1], *cptr;
@@ -129,21 +143,21 @@ if (NULL==(fpin=fopen(infname, "r"))) {
exit(1);
}
bublist = alloc_bubulles(infname, 800000, 0);
bublist = alloc_bubulles(infname, 500000, 0);
if (NULL==bublist) {
fprintf(stderr, "in %s, no mem for bubls, aborting...\n", __func__);
abort();
}
print_bublist_desc(bublist, 0);
edges = alloc_edgelist("krkrkr", 100000, 0);
edges = alloc_edgelist("krkrkr", 200000, 0);
if (NULL==edges) {
fprintf(stderr, "no mem for edges in %s, aborting...\n", __func__);
abort();
}
print_edgelist_desc(edges, 0);
fprintf(stderr, "\n\t************************\n");
fprintf(stderr, "\n***********************************\n");
nbre = 0;
while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
@@ -196,11 +210,12 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
case T_face:
foo = parse_face(cptr, 0);
fprintf(stderr, " parse face -> %d\n", foo);
if (foo) fprintf(stderr, " '%s' parse face -> %d\n",
cptr, foo);
break;
default:
fprintf(stderr, "\ttoken %d ?\n", tokenid);
// fprintf(stderr, "\ttoken %d ?\n", tokenid);
continue; /* wtf ? */
}
@@ -208,18 +223,18 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
}
fclose(fpin);
fprintf(stderr, "\n\t************************\n");
fprintf(stderr, "\n***********************************\n");
if(verbosity) {
fprintf(stderr, "in %s, %d vertices loaded\n", __func__, bublist->fidx);
}
print_bublist_desc(bublist, 0);
bubulles_to_data(outfname, NULL, bublist, 0);
bubulles_to_data(file_vert, NULL, bublist, 0);
free_bubulles(bublist, 0);
print_edgelist_desc(edges, 0);
print_the_edges(edges, 0);
print_the_edges(stdout, edges, 0);
free_edgelist(edges, 0);
return 0;