💿🐜 Antkeeper source code https://antkeeper.com
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.

195 lines
4.0 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_MODEL_HPP
  20. #define ANTKEEPER_MODEL_HPP
  21. #include "gl/vertex-array.hpp"
  22. #include "gl/vertex-buffer.hpp"
  23. #include "gl/drawing-mode.hpp"
  24. #include "geom/aabb.hpp"
  25. #include <map>
  26. #include <string>
  27. #include <vector>
  28. class material;
  29. class skeleton;
  30. /**
  31. * Part of a model which is associated with exactly one material.
  32. */
  33. class model_group
  34. {
  35. public:
  36. void set_material(material* material);
  37. void set_drawing_mode(gl::drawing_mode mode);
  38. void set_start_index(std::size_t index);
  39. void set_index_count(std::size_t count);
  40. std::size_t get_index() const;
  41. const std::string& get_name() const;
  42. const material* get_material() const;
  43. material* get_material();
  44. gl::drawing_mode get_drawing_mode() const;
  45. std::size_t get_start_index() const;
  46. std::size_t get_index_count() const;
  47. private:
  48. friend class model;
  49. std::size_t index;
  50. std::string name;
  51. material* material;
  52. gl::drawing_mode drawing_mode;
  53. std::size_t start_index;
  54. std::size_t index_count;
  55. };
  56. inline void model_group::set_material(::material* material)
  57. {
  58. this->material = material;
  59. }
  60. inline void model_group::set_drawing_mode(gl::drawing_mode mode)
  61. {
  62. this->drawing_mode = mode;
  63. }
  64. inline void model_group::set_start_index(std::size_t index)
  65. {
  66. this->start_index = index;
  67. }
  68. inline void model_group::set_index_count(std::size_t count)
  69. {
  70. this->index_count = count;
  71. }
  72. inline std::size_t model_group::get_index() const
  73. {
  74. return index;
  75. }
  76. inline const std::string& model_group::get_name() const
  77. {
  78. return name;
  79. }
  80. inline const material* model_group::get_material() const
  81. {
  82. return material;
  83. }
  84. inline material* model_group::get_material()
  85. {
  86. return material;
  87. }
  88. inline gl::drawing_mode model_group::get_drawing_mode() const
  89. {
  90. return drawing_mode;
  91. }
  92. inline std::size_t model_group::get_start_index() const
  93. {
  94. return start_index;
  95. }
  96. inline std::size_t model_group::get_index_count() const
  97. {
  98. return index_count;
  99. }
  100. /**
  101. *
  102. */
  103. class model
  104. {
  105. public:
  106. typedef geom::aabb<float> aabb_type;
  107. model();
  108. ~model();
  109. void set_bounds(const aabb_type& bounds);
  110. model_group* add_group(const std::string& name = std::string());
  111. bool remove_group(const std::string& name);
  112. bool remove_group(model_group* group);
  113. const aabb_type& get_bounds() const;
  114. const model_group* get_group(const std::string& name) const;
  115. model_group* get_group(const std::string& name);
  116. const std::vector<model_group*>* get_groups() const;
  117. const gl::vertex_array* get_vertex_array() const;
  118. gl::vertex_array* get_vertex_array();
  119. const gl::vertex_buffer* get_vertex_buffer() const;
  120. gl::vertex_buffer* get_vertex_buffer();
  121. private:
  122. aabb_type bounds;
  123. std::vector<model_group*> groups;
  124. std::map<std::string, model_group*> group_map;
  125. gl::vertex_array vao;
  126. gl::vertex_buffer vbo;
  127. skeleton* skeleton;
  128. };
  129. inline void model::set_bounds(const aabb_type& bounds)
  130. {
  131. this->bounds = bounds;
  132. }
  133. inline const typename model::aabb_type& model::get_bounds() const
  134. {
  135. return bounds;
  136. }
  137. inline const std::vector<model_group*>* model::get_groups() const
  138. {
  139. return &groups;
  140. }
  141. inline const gl::vertex_array* model::get_vertex_array() const
  142. {
  143. return &vao;
  144. }
  145. inline gl::vertex_array* model::get_vertex_array()
  146. {
  147. return &vao;
  148. }
  149. inline const gl::vertex_buffer* model::get_vertex_buffer() const
  150. {
  151. return &vbo;
  152. }
  153. inline gl::vertex_buffer* model::get_vertex_buffer()
  154. {
  155. return &vbo;
  156. }
  157. #endif // ANTKEEPER_MODEL_HPP