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
|
*.vertices
|
||||||
*.edges
|
*.edges
|
||||||
|
*.blob
|
||||||
|
|
||||||
|
@ -1,13 +1,20 @@
|
|||||||
|
|
||||||
BBFUNCS = ../libbubulles.a
|
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)
|
read_obj: read_obj.c Makefile importobj.o rdwredges.o \
|
||||||
gcc $(OPT) $< importobj.o $(BBFUNCS) -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 $<
|
$(CC) $(OPT) -c $<
|
||||||
|
|
||||||
|
rdwredges.o: rdwredges.c objtrucs.h \
|
||||||
|
../bubulles.h ../edges.h Makefile
|
||||||
|
$(CC) $(OPT) -c $<
|
||||||
|
|
||||||
|
# ---------
|
||||||
|
|
||||||
essai_faces: essai_faces.c Makefile
|
essai_faces: essai_faces.c Makefile
|
||||||
$(CC) $(OPT) $< -o $@
|
$(CC) $(OPT) $< -o $@
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
|
||||||
# Importer des fichiers .OBJ
|
# 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
|
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
|
vn -0.05844723806 -0.09480132163 -0.993778944
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## read_obj
|
||||||
|
|
||||||
Première étape : en lisant les vertices, nous saurons positionner
|
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 :
|
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 !
|
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 ?
|
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("3 14 159");
|
||||||
foo = essai_lecture_face("2 4 6 8");
|
foo = essai_lecture_face("2 4 6 8");
|
||||||
foo = essai_lecture_face("0/10 1/11 2/12");
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
LIBBUBULLES
|
LIBBUBULLES IMPORT_OBJ
|
||||||
|
|
||||||
some functions for importing bubulles from dot-OBJ files.
|
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 <stdio.h>
|
||||||
@ -12,6 +15,8 @@
|
|||||||
#include "../bubulles.h"
|
#include "../bubulles.h"
|
||||||
#include "../edges.h"
|
#include "../edges.h"
|
||||||
|
|
||||||
|
#include "objtrucs.h"
|
||||||
|
|
||||||
extern int verbosity;
|
extern int verbosity;
|
||||||
|
|
||||||
/* --------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------- */
|
||||||
@ -20,6 +25,9 @@ extern int verbosity;
|
|||||||
|
|
||||||
static BBList *bublist;
|
static BBList *bublist;
|
||||||
static EdgeList *edges;
|
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 },
|
{ "s", T_smoothing },
|
||||||
{ "usemtl", T_usemtl },
|
{ "usemtl", T_usemtl },
|
||||||
{ "mtllib", T_mtllib },
|
{ "mtllib", T_mtllib },
|
||||||
|
/* and more to come... */
|
||||||
{ NULL, 0 }
|
{ NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -64,11 +73,14 @@ for (token=TokenList; token->token; token++) {
|
|||||||
return -1;
|
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;
|
float x, y, z;
|
||||||
int foo;
|
int foo;
|
||||||
|
|
||||||
|
/* /!\ this function kill the input buffer */
|
||||||
|
|
||||||
foo = 0;
|
foo = 0;
|
||||||
cptr = strtok(NULL, " ");
|
cptr = strtok(NULL, " ");
|
||||||
foo += sscanf(cptr, "%f", &x);
|
foo += sscanf(cptr, "%f", &x);
|
||||||
@ -83,15 +95,17 @@ 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...
|
* 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];
|
int pts[3];
|
||||||
|
|
||||||
#if DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
@ -121,25 +135,30 @@ for (ix=0; ix<3; ix++) {
|
|||||||
|
|
||||||
/** check the freshly read datas **/
|
/** check the freshly read datas **/
|
||||||
if ( pts[0]==pts[1] || pts[0]==pts[2] || pts[2]==pts[1] ) {
|
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]);
|
pts[0], pts[1], pts[2]);
|
||||||
sleep(5);
|
dropped++;
|
||||||
}
|
}
|
||||||
|
|
||||||
foo = push_a_missing_edge(edges, pts[0], pts[1]);
|
/*
|
||||||
if (foo) {
|
* may be we can check the "degenerated cylinder" here ?
|
||||||
fprintf(stderr, "%s: disaster #%d\n", __func__, foo);
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
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) {
|
if (dropped) {
|
||||||
fprintf(stderr, "%s: disaster #%d\n", __func__, foo);
|
fprintf(stderr, "%s: %d dropped...\n", __func__, dropped);
|
||||||
return -2;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
@ -167,22 +186,23 @@ if (NULL==(fpin=fopen(infname, "r"))) {
|
|||||||
perror(infname);
|
perror(infname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
linenumber = 0;
|
||||||
|
|
||||||
bublist = alloc_bubulles(infname, 200000, 0);
|
bublist = alloc_bubulles(infname, 400000, 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);
|
if (verbosity > 1) print_bublist_desc(bublist, 0);
|
||||||
|
|
||||||
edges = alloc_edgelist("krkrkr", 400000, 0);
|
edges = alloc_edgelist("krkrkr", 600000, 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);
|
if (verbosity > 1) print_edgelist_desc(edges, 0);
|
||||||
|
|
||||||
fprintf(stderr, "\n***********************************\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,6 +216,8 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
|
|||||||
line[strlen(line)-1] = '\0'; /* kill the newline */
|
line[strlen(line)-1] = '\0'; /* kill the newline */
|
||||||
if (verbosity>1) fprintf(stderr, "line read ==|%s|==\n", line);
|
if (verbosity>1) fprintf(stderr, "line read ==|%s|==\n", line);
|
||||||
|
|
||||||
|
linenumber++;
|
||||||
|
|
||||||
cptr = strtok(line, " ");
|
cptr = strtok(line, " ");
|
||||||
if (NULL == cptr) {
|
if (NULL == cptr) {
|
||||||
/* this is an empty line */
|
/* this is an empty line */
|
||||||
@ -233,8 +255,8 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
|
|||||||
/* experimental code here */
|
/* experimental code here */
|
||||||
foo = parse_face(cptr, 0);
|
foo = parse_face(cptr, 0);
|
||||||
if (foo) {
|
if (foo) {
|
||||||
fprintf(stderr, " '%s' parse face -> %d\n",
|
fprintf(stderr, "line %d '%s' parse face -> %d\n",
|
||||||
cptr, foo);
|
linenumber, cptr, foo);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -267,23 +289,30 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
|
|||||||
fprintf(stderr, "token %s -> %d ?\n", token, tokenid);
|
fprintf(stderr, "token %s -> %d ?\n", token, tokenid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
nbre++;
|
nbre++;
|
||||||
}
|
}
|
||||||
fclose(fpin);
|
fclose(fpin);
|
||||||
|
|
||||||
fprintf(stderr, "\n***********************************\n");
|
fprintf(stderr, " ***********************************\n");
|
||||||
|
|
||||||
if(verbosity) {
|
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);
|
if (verbosity > 1) {
|
||||||
bubulles_to_data(file_vert, NULL, bublist, 0);
|
print_bublist_desc(bublist, 0);
|
||||||
free_bubulles(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);
|
edges_to_data(file_edges, edges, 0);
|
||||||
|
|
||||||
|
foo = x_write_vertedges("foo.blob", bublist, edges);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
free_bubulles(bublist, 0);
|
||||||
free_edgelist(edges, 0);
|
free_edgelist(edges, 0);
|
||||||
|
|
||||||
return 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