objfile.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * OBJ File header
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #ifndef DORAYME_OBJFILE_H
  10. #define DORAYME_OBJFILE_H
  11. #include <stdint.h>
  12. #include <tuple.h>
  13. #include <shape.h>
  14. #include <group.h>
  15. #include <renderstat.h>
  16. class OBJFile : public Shape
  17. {
  18. private:
  19. Group *baseGroup;
  20. Group *currentGroup;
  21. uint32_t allocatedVertexCount;
  22. Point* *vertexList;
  23. uint32_t vertexCount;
  24. uint32_t allocatedVertexNormalCount;
  25. Vector* *vertexNormalList;
  26. uint32_t vertexNormalCount;
  27. private:
  28. void localIntersect(Ray r, Intersect &xs);
  29. Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
  30. public:
  31. /* Some stats */
  32. uint32_t ignoredLines;
  33. protected:
  34. void addGroup(Group *group);
  35. void addVertex(Point *vertex);
  36. void addVertexNormal(Vector *vertexNormal);
  37. void parseLine(char *line, uint32_t currentLine);
  38. int execLine(int argc, char *argv[], uint32_t currentLine);
  39. BoundingBox bounds;
  40. public:
  41. OBJFile();
  42. OBJFile(const char *filepath);
  43. ~OBJFile();
  44. int parseOBJFile(const char *content);
  45. /* OBJ file expect the first vertice to be 1 and not 0 */
  46. Point vertices(uint32_t i) { return *this->vertexList[i - 1]; };
  47. Vector verticesNormal(uint32_t i) { return *this->vertexNormalList[i - 1]; };
  48. Group *groups(const char *groupName);
  49. void intersect(Ray &r, Intersect &xs);
  50. BoundingBox getLocalBounds();
  51. BoundingBox getBounds();
  52. Shape *getBaseGroup() { return this->baseGroup; };
  53. bool includes(Shape *b);
  54. void updateBoundingBox();
  55. void updateTransform();
  56. void lock();
  57. void dumpMe(FILE * fp);
  58. };
  59. #define OBJ_DEFAULT_GROUP "_DefaultObjGroup_"
  60. #endif /* DORAYME_OBJFILE_H */