GPBFile.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef GPBFILE_H_
  2. #define GPBFILE_H_
  3. #include "FileIO.h"
  4. #include "Object.h"
  5. #include "Scene.h"
  6. #include "Node.h"
  7. #include "Camera.h"
  8. #include "Light.h"
  9. #include "Mesh.h"
  10. #include "Reference.h"
  11. #include "ReferenceTable.h"
  12. #include "Animations.h"
  13. #include "Animation.h"
  14. #include "AnimationChannel.h"
  15. namespace gameplay
  16. {
  17. /**
  18. * Increment the version number when making a change that break binary compatibility.
  19. * [0] is major, [1] is minor.
  20. */
  21. const unsigned char GPB_VERSION[2] = {1, 1};
  22. /**
  23. * The GamePlay Binary file class handles writing the GamePlay Binary file.
  24. */
  25. class GPBFile
  26. {
  27. public:
  28. /**
  29. * Constructor.
  30. */
  31. GPBFile(void);
  32. /**
  33. * Destructor.
  34. */
  35. ~GPBFile(void);
  36. /**
  37. * Returns the GPBFile instance.
  38. */
  39. static GPBFile* getInstance();
  40. /**
  41. * Saves the GPBFile as a binary file at filepath.
  42. *
  43. * @param filepath The file name and path to save to.
  44. */
  45. void saveBinary(const std::string& filepath);
  46. /**
  47. * Saves the GPBFile as a text file at filepath. Useful for debugging.
  48. *
  49. * @param filepath The file name and path to save to.
  50. */
  51. void saveText(const std::string& filepath);
  52. void add(Object* obj);
  53. void addScene(Scene* scene);
  54. void addCamera(Camera* camera);
  55. void addLight(Light* light);
  56. void addMesh(Mesh* mesh);
  57. void addNode(Node* node);
  58. /**
  59. * Adds a node that does not belong to a scene.
  60. */
  61. void addScenelessNode(Node* node);
  62. void addAnimation(Animation* animation);
  63. /**
  64. * Adds the given object to the ref table.
  65. */
  66. void addToRefTable(Object* obj);
  67. /**
  68. * Returns the object with the given id. Returns NULL if not found.
  69. */
  70. Object* getFromRefTable(const std::string& id);
  71. /**
  72. * Returns true if the id was found in the ref table.
  73. */
  74. bool idExists(const std::string& id);
  75. Camera* getCamera(const char* id);
  76. Light* getLight(const char* id);
  77. Mesh* getMesh(const char* id);
  78. Node* getNode(const char* id);
  79. Animations* getAnimations();
  80. /**
  81. * Adjusts the game play binary file before it is written.
  82. */
  83. void adjust();
  84. private:
  85. /**
  86. * Computes the bounds of all meshes in the node hierarchy.
  87. */
  88. void computeBounds(Node* node);
  89. void optimizeTransformAnimations();
  90. /**
  91. * Decomposes an ANIMATE_SCALE_ROTATE_TRANSLATE channel into 3 new channels. (Scale, Rotate and Translate)
  92. *
  93. * @param animation The animation that the channel belongs to.
  94. * @param channel The animation channel to decompose.
  95. */
  96. void decomposeTransformAnimationChannel(Animation* animation, const AnimationChannel* channel);
  97. private:
  98. FILE* _file;
  99. std::list<Object*> _objects;
  100. std::list<Camera*> _cameras;
  101. std::list<Light*> _lights;
  102. std::list<Mesh*> _geometry;
  103. std::list<Node*> _nodes;
  104. Animations _animations;
  105. bool _animationsAdded;
  106. ReferenceTable _refTable;
  107. };
  108. }
  109. #endif