sunday dirty commit
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user