sunday dirty commit
This commit is contained in:
parent
62664c00a6
commit
4bca017774
1
tools/.gitignore
vendored
1
tools/.gitignore
vendored
@ -4,4 +4,5 @@ read_obj
|
||||
|
||||
*.vertices
|
||||
*.edges
|
||||
*.blob
|
||||
|
||||
|
@ -1,13 +1,20 @@
|
||||
|
||||
BBFUNCS = ../libbubulles.a
|
||||
|
||||
OPT = -Wall -g -DDEBUG_LEVEL=0 -DMUST_ABORT=0
|
||||
OPT = -Wall -Wextra -g -DDEBUG_LEVEL=0 -DMUST_ABORT=0
|
||||
|
||||
read_obj: read_obj.c Makefile importobj.o $(BBFUNCS)
|
||||
gcc $(OPT) $< importobj.o $(BBFUNCS) -o $@
|
||||
read_obj: read_obj.c Makefile importobj.o rdwredges.o \
|
||||
$(BBFUNCS)
|
||||
gcc $(OPT) $< importobj.o rdwredges.o $(BBFUNCS) -o $@
|
||||
|
||||
importobj.o: importobj.c ../bubulles.h Makefile
|
||||
importobj.o: importobj.c ../bubulles.h ../edges.h Makefile
|
||||
$(CC) $(OPT) -c $<
|
||||
|
||||
rdwredges.o: rdwredges.c objtrucs.h \
|
||||
../bubulles.h ../edges.h Makefile
|
||||
$(CC) $(OPT) -c $<
|
||||
|
||||
# ---------
|
||||
|
||||
essai_faces: essai_faces.c Makefile
|
||||
$(CC) $(OPT) $< -o $@
|
||||
|
@ -1,6 +1,9 @@
|
||||
|
||||
# Importer des fichiers .OBJ
|
||||
|
||||
* https://en.wikipedia.org/wiki/Wavefront_.obj_file
|
||||
* http://fegemo.github.io/cefet-cg/attachments/obj-spec.pdf
|
||||
* https://people.sc.fsu.edu/~jburkardt/data/obj/obj.html
|
||||
|
||||
```
|
||||
v -1.177934647 -6.833468914 -73.19773865
|
||||
@ -9,13 +12,24 @@ v -0.8008174896 -6.425453663 -73.32041931
|
||||
vn -0.05844723806 -0.09480132163 -0.993778944
|
||||
```
|
||||
|
||||
## read_obj
|
||||
|
||||
Première étape : en lisant les vertices, nous saurons positionner
|
||||
nos bubulles.
|
||||
nos bubulles. Ensuite, en explorant les faces, nous pouvons
|
||||
en déduire les arètes (aka: edges).
|
||||
|
||||
Attention, mon parser EXIGE des fichiers Unix bien conformés :
|
||||
c'est-à-dire que la dernière ligne du .obj DOIT être terminée
|
||||
c'est-à-dire que la dernière ligne du `.obj` DOIT être terminée
|
||||
par un newline !
|
||||
|
||||
## TODO LIST
|
||||
|
||||
* Songer à un système d'auto-scaler et de recentrage
|
||||
* Import/export en blob du combo "edges & vertices"
|
||||
* Comment générer un `.obj` à partir d'une image flottante ?
|
||||
* Gérer les arêtes de longueur nulle (degenerated cylinder)
|
||||
|
||||
## rendu final
|
||||
|
||||
Quatrième étape : aller vivre à la campagne ?
|
||||
|
||||
|
@ -39,6 +39,8 @@ int foo, bar;
|
||||
foo = essai_lecture_face("3 14 159");
|
||||
foo = essai_lecture_face("2 4 6 8");
|
||||
foo = essai_lecture_face("0/10 1/11 2/12");
|
||||
foo = essai_lecture_face("3.14159");
|
||||
foo = essai_lecture_face("We make porn");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
/*
|
||||
LIBBUBULLES
|
||||
|
||||
LIBBUBULLES IMPORT_OBJ
|
||||
some functions for importing bubulles from dot-OBJ files.
|
||||
|
||||
https://git.tetalab.org/tTh/libbubulle/src/branch/master/tools/
|
||||
http://fegemo.github.io/cefet-cg/attachments/obj-spec.pdf
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@ -12,6 +15,8 @@
|
||||
#include "../bubulles.h"
|
||||
#include "../edges.h"
|
||||
|
||||
#include "objtrucs.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
@ -20,6 +25,9 @@ extern int verbosity;
|
||||
|
||||
static BBList *bublist;
|
||||
static EdgeList *edges;
|
||||
static int dropped;
|
||||
static int linenumber;
|
||||
static char obj_filename[LINE_SZ+1];
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@ -43,6 +51,7 @@ Tokens TokenList[] = {
|
||||
{ "s", T_smoothing },
|
||||
{ "usemtl", T_usemtl },
|
||||
{ "mtllib", T_mtllib },
|
||||
/* and more to come... */
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
@ -64,11 +73,14 @@ for (token=TokenList; token->token; token++) {
|
||||
return -1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int parse_vertice(char *cptr, float *px, float *py, float *pz)
|
||||
|
||||
static int parse_vertice(char *cptr, float *px, float *py, float *pz)
|
||||
{
|
||||
float x, y, z;
|
||||
int foo;
|
||||
|
||||
/* /!\ this function kill the input buffer */
|
||||
|
||||
foo = 0;
|
||||
cptr = strtok(NULL, " ");
|
||||
foo += sscanf(cptr, "%f", &x);
|
||||
@ -83,15 +95,17 @@ if (3 == foo) {
|
||||
|
||||
return foo;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* new Mon 27 Mar 2023 12:08:18 AM CEST
|
||||
*
|
||||
* mmmm... complex thing to do...
|
||||
*
|
||||
* and what is this "phy" parameter ?
|
||||
*/
|
||||
int parse_face(char *cptr, int phy)
|
||||
static int parse_face(char *cptr, int phy)
|
||||
{
|
||||
int ix, foo;
|
||||
int ix, foo, a, b;
|
||||
int pts[3];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
@ -121,25 +135,30 @@ for (ix=0; ix<3; ix++) {
|
||||
|
||||
/** check the freshly read datas **/
|
||||
if ( pts[0]==pts[1] || pts[0]==pts[2] || pts[2]==pts[1] ) {
|
||||
fprintf(stderr, "%s: degerated face ( %d %d %d )\n", __func__,
|
||||
fprintf(stderr, "%s: degenerated face ( %d %d %d )\n", __func__,
|
||||
pts[0], pts[1], pts[2]);
|
||||
sleep(5);
|
||||
dropped++;
|
||||
}
|
||||
|
||||
foo = push_a_missing_edge(edges, pts[0], pts[1]);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: disaster #%d\n", __func__, foo);
|
||||
return -2;
|
||||
/*
|
||||
* may be we can check the "degenerated cylinder" here ?
|
||||
*/
|
||||
|
||||
|
||||
for (ix=0; ix<3; ix++) {
|
||||
a = ix % 3;
|
||||
b = (ix+1) % 3;
|
||||
foo = push_a_missing_edge(edges, pts[a], pts[b]);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: disaster #%d line %d\n",
|
||||
__func__, foo, linenumber);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
foo = push_a_missing_edge(edges, pts[1], pts[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 (dropped) {
|
||||
fprintf(stderr, "%s: %d dropped...\n", __func__, dropped);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
@ -167,22 +186,23 @@ if (NULL==(fpin=fopen(infname, "r"))) {
|
||||
perror(infname);
|
||||
exit(1);
|
||||
}
|
||||
linenumber = 0;
|
||||
|
||||
bublist = alloc_bubulles(infname, 200000, 0);
|
||||
bublist = alloc_bubulles(infname, 400000, 0);
|
||||
if (NULL==bublist) {
|
||||
fprintf(stderr, "in %s, no mem for bubls, aborting...\n", __func__);
|
||||
abort();
|
||||
}
|
||||
print_bublist_desc(bublist, 0);
|
||||
if (verbosity > 1) print_bublist_desc(bublist, 0);
|
||||
|
||||
edges = alloc_edgelist("krkrkr", 400000, 0);
|
||||
edges = alloc_edgelist("krkrkr", 600000, 0);
|
||||
if (NULL==edges) {
|
||||
fprintf(stderr, "no mem for edges in %s, aborting...\n", __func__);
|
||||
abort();
|
||||
}
|
||||
print_edgelist_desc(edges, 0);
|
||||
if (verbosity > 1) print_edgelist_desc(edges, 0);
|
||||
|
||||
fprintf(stderr, "\n***********************************\n");
|
||||
fprintf(stderr, "\n ***********************************\n");
|
||||
|
||||
nbre = 0;
|
||||
while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
|
||||
@ -196,6 +216,8 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
|
||||
line[strlen(line)-1] = '\0'; /* kill the newline */
|
||||
if (verbosity>1) fprintf(stderr, "line read ==|%s|==\n", line);
|
||||
|
||||
linenumber++;
|
||||
|
||||
cptr = strtok(line, " ");
|
||||
if (NULL == cptr) {
|
||||
/* this is an empty line */
|
||||
@ -233,8 +255,8 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
|
||||
/* experimental code here */
|
||||
foo = parse_face(cptr, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, " '%s' parse face -> %d\n",
|
||||
cptr, foo);
|
||||
fprintf(stderr, "line %d '%s' parse face -> %d\n",
|
||||
linenumber, cptr, foo);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
@ -267,23 +289,30 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
|
||||
fprintf(stderr, "token %s -> %d ?\n", token, tokenid);
|
||||
break;
|
||||
}
|
||||
|
||||
nbre++;
|
||||
}
|
||||
fclose(fpin);
|
||||
|
||||
fprintf(stderr, "\n***********************************\n");
|
||||
fprintf(stderr, " ***********************************\n");
|
||||
|
||||
if(verbosity) {
|
||||
fprintf(stderr, "in %s, %d vertices loaded\n", __func__, bublist->fidx);
|
||||
fprintf(stderr, "%s(): %d vertices loaded\n", __func__, bublist->fidx);
|
||||
fprintf(stderr, "%s(): %d edges loaded\n", __func__, edges->fidx);
|
||||
}
|
||||
|
||||
print_bublist_desc(bublist, 0);
|
||||
bubulles_to_data(file_vert, NULL, bublist, 0);
|
||||
free_bubulles(bublist, 0);
|
||||
if (verbosity > 1) {
|
||||
print_bublist_desc(bublist, 0);
|
||||
print_edgelist_desc(edges, 0);
|
||||
}
|
||||
|
||||
bubulles_to_data(file_vert, NULL, bublist, 0);
|
||||
|
||||
print_edgelist_desc(edges, 0);
|
||||
edges_to_data(file_edges, edges, 0);
|
||||
|
||||
foo = x_write_vertedges("foo.blob", bublist, edges);
|
||||
|
||||
// Cleanup
|
||||
free_bubulles(bublist, 0);
|
||||
free_edgelist(edges, 0);
|
||||
|
||||
return 0;
|
||||
|
14
tools/objtrucs.h
Normal file
14
tools/objtrucs.h
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* EXPERIMENTAL CODE !
|
||||
*/
|
||||
|
||||
|
||||
typedef struct {
|
||||
unsigned long magic;
|
||||
BBList *Blist;
|
||||
EdgeList *Elist;
|
||||
int status;
|
||||
} EdgeAndVertices;
|
||||
|
||||
int x_write_vertedges(char *filename, BBList *bblist, EdgeList *edges);
|
||||
|
59
tools/rdwredges.c
Normal file
59
tools/rdwredges.c
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
LIBBUBULLES IMPORT_OBJ
|
||||
some functions for importing bubulles from dot-OBJ files.
|
||||
|
||||
https://git.tetalab.org/tTh/libbubulle/src/branch/master/tools/
|
||||
http://fegemo.github.io/cefet-cg/attachments/obj-spec.pdf
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../bubulles.h"
|
||||
#include "../edges.h"
|
||||
|
||||
#include "objtrucs.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* EXPERIMENTAL GRUIK-CODE !!! */
|
||||
int x_write_vertedges(char *filename, BBList *bblist, EdgeList *edges)
|
||||
{
|
||||
FILE *fp;
|
||||
int idx, edg[2];
|
||||
double coo[3];
|
||||
|
||||
fprintf(stderr, ">>> %s ( '%s' %p %p )\n", __func__, filename,
|
||||
bblist, edges);
|
||||
|
||||
if (NULL==(fp=fopen(filename, "w"))) {
|
||||
perror(filename);
|
||||
return -4;
|
||||
}
|
||||
|
||||
print_bublist_desc(bblist, 0);
|
||||
fwrite("VERTICES", 8, 1, fp);
|
||||
for (idx=0; idx<bblist->fidx; idx++) {
|
||||
fprintf(stderr, "vertice %d\n", idx);
|
||||
coo[0] = bblist->bbs[idx].p.x;
|
||||
coo[1] = bblist->bbs[idx].p.y;
|
||||
coo[2] = bblist->bbs[idx].p.z;
|
||||
fwrite(coo, sizeof(coo), 1, fp);
|
||||
}
|
||||
|
||||
print_edgelist_desc(edges, 0);
|
||||
fwrite("EDGES ", 8, 1, fp);
|
||||
for (idx=0; idx<edges->fidx; idx++) {
|
||||
edg[0] = edges->edges[idx].A;
|
||||
edg[1] = edges->edges[idx].B;
|
||||
fwrite(edg, sizeof(edg), 1, fp);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
Loading…
Reference in New Issue
Block a user