loadModel.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef _LOADOBJ_
  2. #define _LOADOBJ_
  3. #include <vector>
  4. #include "vec3.h"
  5. /* Loads a .obj file (it's a toy parser - it's not complete)
  6. * gets object's vertices and calculate's its boundbox
  7. */
  8. bool loadOBJ(
  9. const char *path,
  10. std::vector<vec3> &out_vertices,
  11. vec3 *bound,
  12. unsigned char mirror);
  13. /* Loads a .ply file (it's a toy parser - it's not complete)
  14. * gets object's vertices and vertex colors and calculate's its boundbox
  15. * mirror makes the object mirrored on x/y/z
  16. * x = 0b1 | y = 0b10 | z = 0b100
  17. */
  18. bool loadPLY(
  19. const char *path,
  20. std::vector<vec3> &out_vertices,
  21. std::vector<vec3> &out_color,
  22. vec3 *out_bound,
  23. unsigned char mirror);
  24. /* Experiment to improve importing */
  25. // Hold all data that are extracted by a file (that the game uses)
  26. struct mesh_data
  27. {
  28. unsigned int vcount;
  29. float *pos;
  30. float *col;
  31. vec3 pbound, nbound;
  32. };
  33. struct property
  34. {
  35. unsigned int flag;
  36. unsigned char format;
  37. };
  38. // Flags of what data to parse
  39. #define FLG_V_POS_X 1
  40. #define FLG_V_POS_Y 2
  41. #define FLG_V_POS_Z 4
  42. #define FLG_V_POS_MIRROR_X 8
  43. #define FLG_V_POS_MIRROR_Y 16
  44. #define FLG_V_POS_MIRROR_Z 32
  45. #define FLG_V_COL_R 64
  46. #define FLG_V_COL_G 128
  47. #define FLG_V_COL_B 256
  48. #define FLG_F_VINDICES 512
  49. //Formats
  50. #define PLY_UNSUPPORTED 0
  51. #define PLY_CHAR 1
  52. #define PLY_UCHAR 2
  53. #define PLY_SHORT 3
  54. #define PLY_USHORT 4
  55. #define PLY_INT 5
  56. #define PLY_UINT 6
  57. #define PLY_FLOAT 7
  58. #define PLY_DOUBLE 8
  59. /* Load a .ply file, and return a struct with mesh data
  60. * path is filepath
  61. * flags declare what data to parse and how (mirroring)
  62. */
  63. mesh_data *loadPly(const char *path, int flags);
  64. unsigned char form_to_num( char *format );
  65. unsigned int flag_to_num( char *flag );
  66. char *flagstr( unsigned int flag );
  67. char *formatstr( char format );
  68. #endif