2020-06-05 09:17:17 +11:00
|
|
|
/*
|
|
|
|
LIBBUBULLES
|
|
|
|
|
|
|
|
some functions for importing bubulles from dot-OBJ files.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "bubulles.h"
|
|
|
|
|
2020-06-05 10:05:01 +11:00
|
|
|
extern int verbosity;
|
|
|
|
|
2020-06-05 09:17:17 +11:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2020-06-05 10:05:01 +11:00
|
|
|
#define LINE_SZ 666
|
|
|
|
|
2020-06-05 09:17:17 +11:00
|
|
|
int try_to_read_an_OBJ_file(char *fname, int notused)
|
|
|
|
{
|
|
|
|
FILE *fpin;
|
2020-06-05 10:05:01 +11:00
|
|
|
char line[LINE_SZ+1], *cptr;
|
|
|
|
float x, y, z;
|
2020-06-05 19:57:43 +11:00
|
|
|
int foo, nbre;
|
|
|
|
BBList *bublist;
|
|
|
|
Bubulle bubulle;
|
2020-06-05 09:17:17 +11:00
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
2020-06-05 10:05:01 +11:00
|
|
|
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused);
|
2020-06-05 09:17:17 +11:00
|
|
|
#endif
|
|
|
|
|
2020-06-05 10:05:01 +11:00
|
|
|
if (NULL==(fpin=fopen(fname, "r"))) {
|
|
|
|
perror(fname);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-06-05 19:57:43 +11:00
|
|
|
bublist = alloc_bubulles(fname, 1000, 0);
|
|
|
|
if (NULL==bublist) {
|
|
|
|
fprintf(stderr, "err in %s, aborting...\n", __func__);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
print_bublist_desc(bublist, 0);
|
|
|
|
|
|
|
|
nbre = 0;
|
2021-05-07 21:27:16 +11:00
|
|
|
while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
|
2020-06-05 10:05:01 +11:00
|
|
|
|
|
|
|
if (verbosity>1) fputs(line, stderr);
|
|
|
|
|
|
|
|
cptr = strtok(line, " ");
|
|
|
|
if (strcmp(cptr, "v")) continue;
|
|
|
|
|
|
|
|
cptr = strtok(NULL, " ");
|
|
|
|
foo = sscanf(cptr, "%f", &x);
|
|
|
|
cptr = strtok(NULL, " ");
|
|
|
|
foo = sscanf(cptr, "%f", &y);
|
|
|
|
cptr = strtok(NULL, " ");
|
|
|
|
foo = sscanf(cptr, "%f", &z);
|
|
|
|
|
2020-06-05 19:57:43 +11:00
|
|
|
memset(&bubulle, 0, sizeof(Bubulle));
|
2020-06-05 10:05:01 +11:00
|
|
|
|
2020-06-05 19:57:43 +11:00
|
|
|
bubulle.p.x = x;
|
|
|
|
bubulle.p.y = y;
|
|
|
|
bubulle.p.z = z;
|
2020-06-12 00:30:03 +11:00
|
|
|
if (verbosity > 1) niceprint_bubulle(&bubulle, 0);
|
2020-06-05 10:05:01 +11:00
|
|
|
|
2020-06-05 19:57:43 +11:00
|
|
|
foo = push_bubulle(bublist, &bubulle);
|
|
|
|
if (foo) {
|
2020-06-12 00:30:03 +11:00
|
|
|
fprintf(stderr, "%s: err %d on push\n", __func__, foo);
|
2020-06-05 19:57:43 +11:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
nbre++;
|
|
|
|
}
|
2020-06-05 10:05:01 +11:00
|
|
|
fclose(fpin);
|
|
|
|
|
2020-06-05 19:57:43 +11:00
|
|
|
if(verbosity) {
|
|
|
|
fprintf(stderr, "%s : %d vertices loaded\n", __func__, nbre);
|
|
|
|
}
|
|
|
|
|
2020-06-12 00:30:03 +11:00
|
|
|
bubulles_to_data("xyz", NULL, bublist, 0);
|
|
|
|
|
2020-06-05 19:57:43 +11:00
|
|
|
return 0;
|
2020-06-05 09:17:17 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|