des bubulles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

importobj.c 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. LIBBUBULLES
  3. some functions for importing bubulles from dot-OBJ files.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "bubulles.h"
  9. extern int verbosity;
  10. /* --------------------------------------------------------------------- */
  11. #define LINE_SZ 666
  12. int try_to_read_an_OBJ_file(char *fname, int notused)
  13. {
  14. FILE *fpin;
  15. char line[LINE_SZ+1], *cptr;
  16. float x, y, z;
  17. int foo, nbre;
  18. BBList *bublist;
  19. Bubulle bubulle;
  20. #if DEBUG_LEVEL
  21. fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused);
  22. #endif
  23. if (NULL==(fpin=fopen(fname, "r"))) {
  24. perror(fname);
  25. exit(1);
  26. }
  27. bublist = alloc_bubulles(fname, 1000, 0);
  28. if (NULL==bublist) {
  29. fprintf(stderr, "err in %s, aborting...\n", __func__);
  30. abort();
  31. }
  32. print_bublist_desc(bublist, 0);
  33. nbre = 0;
  34. while(cptr=fgets(line, LINE_SZ, fpin)) {
  35. if (verbosity>1) fputs(line, stderr);
  36. cptr = strtok(line, " ");
  37. if (strcmp(cptr, "v")) continue;
  38. cptr = strtok(NULL, " ");
  39. foo = sscanf(cptr, "%f", &x);
  40. cptr = strtok(NULL, " ");
  41. foo = sscanf(cptr, "%f", &y);
  42. cptr = strtok(NULL, " ");
  43. foo = sscanf(cptr, "%f", &z);
  44. memset(&bubulle, 0, sizeof(Bubulle));
  45. bubulle.p.x = x;
  46. bubulle.p.y = y;
  47. bubulle.p.z = z;
  48. if (verbosity > 1) niceprint_bubulle(&bubulle, 0);
  49. foo = push_bubulle(bublist, &bubulle);
  50. if (foo) {
  51. fprintf(stderr, "%s: err %d on push\n", __func__, foo);
  52. break;
  53. }
  54. nbre++;
  55. }
  56. fclose(fpin);
  57. if(verbosity) {
  58. fprintf(stderr, "%s : %d vertices loaded\n", __func__, nbre);
  59. }
  60. bubulles_to_data("xyz", NULL, bublist, 0);
  61. return 0;
  62. }
  63. /* --------------------------------------------------------------------- */