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

@ -1,7 +1,7 @@
BBFUNCS = ../libbubulles.a BBFUNCS = ../libbubulles.a
OPT = -Wall -g -DDEBUG_LEVEL=1 -DMUST_ABORT OPT = -Wall -g -pg -DDEBUG_LEVEL=0 -DMUST_ABORT=0
read_obj: read_obj.c Makefile importobj.o $(BBFUNCS) read_obj: read_obj.c Makefile importobj.o $(BBFUNCS)
gcc $(OPT) $< importobj.o $(BBFUNCS) -o $@ gcc $(OPT) $< importobj.o $(BBFUNCS) -o $@

View File

@ -1,6 +1,7 @@
# Importer des fichiers .OBJ # Importer des fichiers .OBJ
``` ```
v -1.177934647 -6.833468914 -73.19773865 v -1.177934647 -6.833468914 -73.19773865
vn -0.1279897094 -0.4501263499 -0.8837448359 vn -0.1279897094 -0.4501263499 -0.8837448359
@ -11,10 +12,10 @@ vn -0.05844723806 -0.09480132163 -0.993778944
Première étape : en lisant les vertices, nous saurons positionner Première étape : en lisant les vertices, nous saurons positionner
nos bubulles. nos bubulles.
Seconde étape : bien comprendre à quoi correspondent les Attention, mon parser EXIGE des fichiers Unix bien conformés :
lignes `vn` ? Des normales ? c'est-à-dire que la dernière ligne du .obj DOIT être terminée
par un newline !
Et troisème étape, que faire des vertices ?
Quatrième étape : aller vivre à la campagne ? Quatrième étape : aller vivre à la campagne ?

View File

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

7
tools/minimal.obj Normal file
View File

@ -0,0 +1,7 @@
g minimal
v 0 0 0
v 1 0 0
v 0 1 0
v 0 0 1
f 1/2, 2/3, 3/1
f 0/1, 0/1, 0/2

View File

@ -4,23 +4,33 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <libgen.h> // for basename(3)
#include "../bubulles.h" #include "../bubulles.h"
int try_to_read_an_OBJ_file(char *fname, char *outfname, int notused); int try_to_read_an_OBJ_file(char *fname,
int verbosity; char *outfname, char *file_edges,
int notused);
int verbosity = 0;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo; int foo;
char *fname; /* see manpage basename(3) */
if (2 != argc) { if (2 != argc) {
bubulles_version(1); bubulles_version(1);
exit(0); exit(0);
} }
verbosity = 2; verbosity = 0;
foo = try_to_read_an_OBJ_file(argv[1], "bubulles.asc", 0); fname = basename(argv[1]);
fprintf (stderr, "input fname is '%s'\n", fname);
foo = try_to_read_an_OBJ_file(argv[1], "bulles.vertices", "bulles.edges", 0);
fprintf(stderr, "try to read '%s' -> %d\n", argv [1], foo); fprintf(stderr, "try to read '%s' -> %d\n", argv [1], foo);
return 0; return 0;