not ready for prime time

This commit is contained in:
tTh 2023-04-03 00:52:09 +02:00
parent c4547fa832
commit 52e5ace4e1
6 changed files with 146 additions and 40 deletions

3
tools/.gitignore vendored
View File

@ -1,4 +1,7 @@
essai_faces
read_obj
*.vertices *.vertices
*.edges *.edges

View File

@ -8,3 +8,6 @@ read_obj: read_obj.c Makefile importobj.o $(BBFUNCS)
importobj.o: importobj.c ../bubulles.h Makefile importobj.o: importobj.c ../bubulles.h Makefile
$(CC) $(OPT) -c $< $(CC) $(OPT) -c $<
essai_faces: essai_faces.c Makefile
$(CC) $(OPT) $< -o $@

49
tools/cube.obj Normal file
View File

@ -0,0 +1,49 @@
# cube.obj
#
o cube
v 0.0 0.0 0.0
v 0.0 0.0 1.0
v 0.0 1.0 0.0
v 0.0 1.0 1.0
v 1.0 0.0 0.0
v 1.0 0.0 1.0
v 1.0 1.0 0.0
v 1.0 1.0 1.0
vt 0.25 0.0
vt 0.5 0.0
vt 0 0.25
vt 0.25 0.25
vt 0.5 0.25
vt 0.75 0.25
vt 0.0 0.5
vt 0.25 0.5
vt 0.5 0.5
vt 0.75 0.5
vt 0.25 0.75
vt 0.5 0.75
vt 0.25 1.0
vt 0.5 1.0
vn 0.0 0.0 1.0
vn 0.0 0.0 -1.0
vn 0.0 1.0 0.0
vn 0.0 -1.0 0.0
vn 1.0 0.0 0.0
vn -1.0 0.0 0.0
f 1/11/2 7/14/2 5/12/2
f 1/11/2 3/13/2 7/14/2
f 1/7/6 4/4/6 3/3/6
f 1/7/6 2/8/6 4/4/6
f 3/1/3 8/5/3 7/2/3
f 3/1/3 4/4/3 8/5/3
f 5/10/5 7/6/5 8/5/5
f 5/10/5 8/5/5 6/9/5
f 1/11/4 5/12/4 6/9/4
f 1/11/4 6/9/4 2/8/4
f 2/8/1 6/9/1 8/5/1
f 2/8/1 8/5/1 4/4/1

View File

@ -7,6 +7,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "../bubulles.h" #include "../bubulles.h"
#include "../edges.h" #include "../edges.h"
@ -27,7 +28,8 @@ typedef struct {
int id; int id;
} Tokens; } Tokens;
enum token_id { T_comment=1, T_vertice, T_group, T_face, T_vt }; enum token_id { T_comment=1, T_vertice, T_group, T_face, T_vt, T_vn,
T_line, T_object, T_smoothing, T_usemtl, T_mtllib };
Tokens TokenList[] = { Tokens TokenList[] = {
{ "#", T_comment }, { "#", T_comment },
@ -35,6 +37,12 @@ Tokens TokenList[] = {
{ "g", T_group }, // to be verified ! { "g", T_group }, // to be verified !
{ "f", T_face }, { "f", T_face },
{ "vt", T_vt }, // c'est quoi ce truc ? { "vt", T_vt }, // c'est quoi ce truc ?
{ "vn", T_vt }, // c'est quoi ce truc ?
{ "l", T_line },
{ "o", T_object },
{ "s", T_smoothing },
{ "usemtl", T_usemtl },
{ "mtllib", T_mtllib },
{ NULL, 0 } { NULL, 0 }
}; };
@ -76,45 +84,62 @@ if (3 == foo) {
return foo; return foo;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* new Mon 27 Mar 2023 12:08:18 AM CEST */ /* new Mon 27 Mar 2023 12:08:18 AM CEST
*
* mmmm... complex thing to do...
*
*/
int parse_face(char *cptr, int phy) int parse_face(char *cptr, int phy)
{ {
int ix, foo; int ix, foo;
int fa, fb; int pts[3];
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, cptr, phy); fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, cptr, phy);
#endif #endif
#if (0)
fprintf(stderr, "parse_face");
for (foo=0; foo<16; foo++) {
fprintf(stderr, " %02X", ((unsigned char *)cptr)[foo]);
}
fprintf(stderr, "\n");
#endif
for (ix=0; ix<3; ix++) { for (ix=0; ix<3; ix++) {
cptr = strtok(NULL, " "); cptr = strtok(NULL, " ");
if (NULL == cptr) { if (NULL == cptr) {
fprintf(stderr, "incomplete face in %s\n", __func__); fprintf(stderr, "incomplete face in %s\n", __func__);
return -4; return -4;
} }
if (2 != sscanf(cptr, "%d/%d", &fa, &fb)) { if (1 != sscanf(cptr, "%d", &pts[ix])) {
fprintf(stderr, "%s: err sscanf\n", __func__); fprintf(stderr, "%s: err sscanf\n", __func__);
exit(1); exit(1);
return -3; return -3;
} }
// XXX fprintf(stderr, " %d got %d %d\n", ix, fa, fb); }
/* /** check the freshly read datas **/
* yes, i've found 0-lenght edges, wtf ? if ( pts[0]==pts[1] || pts[0]==pts[2] || pts[2]==pts[1] ) {
*/ fprintf(stderr, "%s: degerated face ( %d %d %d )\n", __func__,
if (fa == fb) { pts[0], pts[1], pts[2]);
// fprintf(stderr, "'%s' dublicate\n", cptr); sleep(5);
continue; }
}
foo = push_a_missing_edge(edges, fa, fb); foo = push_a_missing_edge(edges, pts[0], pts[1]);
if (foo) { if (foo) {
fprintf(stderr, "%s: disaster #%d\n", __func__, foo); fprintf(stderr, "%s: disaster #%d\n", __func__, foo);
#if MUST_ABORT return -2;
fflush(stderr), abort(); }
#endif foo = push_a_missing_edge(edges, pts[1], pts[2]);
return -2; if (foo) {
} fprintf(stderr, "%s: disaster #%d\n", __func__, foo);
return -2;
}
foo = push_a_missing_edge(edges, pts[2], pts[0]);
if (foo) {
fprintf(stderr, "%s: disaster #%d\n", __func__, foo);
return -2;
} }
#if DEBUG_LEVEL #if DEBUG_LEVEL
@ -128,7 +153,7 @@ int try_to_read_an_OBJ_file(char *infname, char *file_vert, char *file_edges,
int notused) int notused)
{ {
FILE *fpin; FILE *fpin;
char line[LINE_SZ+1], *cptr; char line[LINE_SZ+1], *cptr, *token;
float x, y, z; float x, y, z;
int foo, nbre, tokenid; int foo, nbre, tokenid;
Bubulle bubulle; Bubulle bubulle;
@ -143,14 +168,14 @@ if (NULL==(fpin=fopen(infname, "r"))) {
exit(1); exit(1);
} }
bublist = alloc_bubulles(infname, 500000, 0); bublist = alloc_bubulles(infname, 200000, 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", 200000, 0); edges = alloc_edgelist("krkrkr", 400000, 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();
@ -173,9 +198,11 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
cptr = strtok(line, " "); cptr = strtok(line, " ");
if (NULL == cptr) { if (NULL == cptr) {
fprintf(stderr, "no token ?\n"); /* this is an empty line */
// fprintf(stderr, "no token ?\n");
continue; continue;
} }
token = cptr;
tokenid = type_of_the_line(cptr); tokenid = type_of_the_line(cptr);
if (verbosity > 1) if (verbosity > 1)
fprintf(stderr, "token '%s' --> %d\n", cptr, tokenid); fprintf(stderr, "token '%s' --> %d\n", cptr, tokenid);
@ -202,21 +229,43 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
abort(); abort();
} }
break; break;
case T_face:
case T_group: /* experimental code here */
cptr = strtok(NULL, " "); foo = parse_face(cptr, 0);
fprintf(stderr, "\tGroup: %s\n", cptr); if (foo) {
fprintf(stderr, " '%s' parse face -> %d\n",
cptr, foo);
exit(1);
}
break; break;
case T_face: case T_object:
foo = parse_face(cptr, 0); cptr = strtok(NULL, " ");
if (foo) fprintf(stderr, " '%s' parse face -> %d\n", fprintf(stderr, "\tObject: %s\n", cptr);
cptr, foo); break;
case T_group:
cptr = strtok(NULL, " ");
fprintf(stderr, "\tGroup: %s\n", cptr);
break;
case T_usemtl:
cptr = strtok(NULL, " ");
fprintf(stderr, "\tUsemtl: %s\n", cptr);
break;
case T_mtllib:
cptr = strtok(NULL, " ");
fprintf(stderr, "\tMtllib: %s\n", cptr);
break;
case T_line:
break;
case T_smoothing:
break;
case T_vt:
break; break;
default: default:
// fprintf(stderr, "\ttoken %d ?\n", tokenid); fprintf(stderr, "token %s -> %d ?\n", token, tokenid);
continue; /* wtf ? */ break;
} }
nbre++; nbre++;
@ -234,7 +283,7 @@ 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(stdout, edges, 0); edges_to_data(file_edges, edges, 0);
free_edgelist(edges, 0); free_edgelist(edges, 0);
return 0; return 0;

View File

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

View File

@ -20,15 +20,17 @@ int main(int argc, char *argv[])
int foo; int foo;
char *fname; /* see manpage basename(3) */ char *fname; /* see manpage basename(3) */
fprintf(stderr, "\n### READ_OBJ %s %s\n\n", __DATE__, __TIME__);
if (2 != argc) { if (2 != argc) {
bubulles_version(1); bubulles_version(1);
exit(0); exit(0);
} }
verbosity = 0; verbosity = 1;
fname = basename(argv[1]); fname = basename(argv[1]);
fprintf (stderr, "input fname is '%s'\n", fname); fprintf (stderr, "input file name is '%s'\n", fname);
foo = try_to_read_an_OBJ_file(argv[1], "bulles.vertices", "bulles.edges", 0); 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);