libbubulle/importobj.c

85 lines
1.6 KiB
C
Raw Normal View History

2020-06-05 00:17:17 +02: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 01:05:01 +02:00
extern int verbosity;
2020-06-05 00:17:17 +02:00
/* --------------------------------------------------------------------- */
2020-06-05 01:05:01 +02:00
#define LINE_SZ 666
2020-06-05 00:17:17 +02:00
int try_to_read_an_OBJ_file(char *fname, int notused)
{
FILE *fpin;
2020-06-05 01:05:01 +02:00
char line[LINE_SZ+1], *cptr;
float x, y, z;
2020-06-05 10:57:43 +02:00
int foo, nbre;
BBList *bublist;
Bubulle bubulle;
2020-06-05 00:17:17 +02:00
#if DEBUG_LEVEL
2020-06-05 01:05:01 +02:00
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused);
2020-06-05 00:17:17 +02:00
#endif
2020-06-05 01:05:01 +02:00
if (NULL==(fpin=fopen(fname, "r"))) {
perror(fname);
exit(1);
}
2020-06-05 10:57:43 +02: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;
2020-06-05 01:05:01 +02:00
while(cptr=fgets(line, LINE_SZ, fpin)) {
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 10:57:43 +02:00
memset(&bubulle, 0, sizeof(Bubulle));
2020-06-05 01:05:01 +02:00
2020-06-05 10:57:43 +02:00
bubulle.p.x = x;
bubulle.p.y = y;
bubulle.p.z = z;
2020-06-11 15:30:03 +02:00
if (verbosity > 1) niceprint_bubulle(&bubulle, 0);
2020-06-05 01:05:01 +02:00
2020-06-05 10:57:43 +02:00
foo = push_bubulle(bublist, &bubulle);
if (foo) {
2020-06-11 15:30:03 +02:00
fprintf(stderr, "%s: err %d on push\n", __func__, foo);
2020-06-05 10:57:43 +02:00
break;
}
nbre++;
}
2020-06-05 01:05:01 +02:00
fclose(fpin);
2020-06-05 10:57:43 +02:00
if(verbosity) {
fprintf(stderr, "%s : %d vertices loaded\n", __func__, nbre);
}
2020-06-11 15:30:03 +02:00
bubulles_to_data("xyz", NULL, bublist, 0);
2020-06-05 10:57:43 +02:00
return 0;
2020-06-05 00:17:17 +02:00
}
/* --------------------------------------------------------------------- */