objparser.h 744 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include <stddef.h>
  3. struct ObjGroup
  4. {
  5. char material[256];
  6. size_t index_offset;
  7. size_t index_count;
  8. };
  9. class ObjFile
  10. {
  11. public:
  12. float* v; // positions; stride 3 (xyz)
  13. size_t v_size, v_cap;
  14. float* vt; // texture coordinates; stride 3 (uvw)
  15. size_t vt_size, vt_cap;
  16. float* vn; // vertex normals; stride 3 (xyz)
  17. size_t vn_size, vn_cap;
  18. int* f; // face elements; stride 9 (3 groups of indices into v/vt/vn)
  19. size_t f_size, f_cap;
  20. ObjGroup* g;
  21. size_t g_size, g_cap;
  22. ObjFile();
  23. ~ObjFile();
  24. private:
  25. ObjFile(const ObjFile&);
  26. ObjFile& operator=(const ObjFile&);
  27. };
  28. void objParseLine(ObjFile& result, const char* line);
  29. bool objParseFile(ObjFile& result, const char* path);
  30. bool objValidate(const ObjFile& result);