💿🐜 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.

210 lines
4.4 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_RENDER_MODEL_HPP
  20. #define ANTKEEPER_RENDER_MODEL_HPP
  21. #include "animation/skeleton.hpp"
  22. #include "gl/vertex-array.hpp"
  23. #include "gl/vertex-buffer.hpp"
  24. #include "gl/drawing-mode.hpp"
  25. #include "render/material.hpp"
  26. #include "geom/aabb.hpp"
  27. #include <unordered_map>
  28. #include <string>
  29. #include <vector>
  30. namespace render {
  31. /**
  32. * Part of a model which is associated with exactly one material.
  33. */
  34. class model_group
  35. {
  36. public:
  37. void set_material(material* material);
  38. void set_drawing_mode(gl::drawing_mode mode);
  39. void set_start_index(std::size_t index);
  40. void set_index_count(std::size_t count);
  41. std::size_t get_index() const;
  42. const std::string& get_name() const;
  43. const material* get_material() const;
  44. material* get_material();
  45. gl::drawing_mode get_drawing_mode() const;
  46. std::size_t get_start_index() const;
  47. std::size_t get_index_count() const;
  48. private:
  49. friend class model;
  50. std::size_t index;
  51. std::string name;
  52. material* material;
  53. gl::drawing_mode drawing_mode;
  54. std::size_t start_index;
  55. std::size_t index_count;
  56. };
  57. inline void model_group::set_material(render::material* material)
  58. {
  59. this->material = material;
  60. }
  61. inline void model_group::set_drawing_mode(gl::drawing_mode mode)
  62. {
  63. this->drawing_mode = mode;
  64. }
  65. inline void model_group::set_start_index(std::size_t index)
  66. {
  67. this->start_index = index;
  68. }
  69. inline void model_group::set_index_count(std::size_t count)
  70. {
  71. this->index_count = count;
  72. }
  73. inline std::size_t model_group::get_index() const
  74. {
  75. return index;
  76. }
  77. inline const std::string& model_group::get_name() const
  78. {
  79. return name;
  80. }
  81. inline const material* model_group::get_material() const
  82. {
  83. return material;
  84. }
  85. inline material* model_group::get_material()
  86. {
  87. return material;
  88. }
  89. inline gl::drawing_mode model_group::get_drawing_mode() const
  90. {
  91. return drawing_mode;
  92. }
  93. inline std::size_t model_group::get_start_index() const
  94. {
  95. return start_index;
  96. }
  97. inline std::size_t model_group::get_index_count() const
  98. {
  99. return index_count;
  100. }
  101. /**
  102. *
  103. */
  104. class model
  105. {
  106. public:
  107. typedef geom::aabb<float> aabb_type;
  108. model();
  109. ~model();
  110. void set_bounds(const aabb_type& bounds);
  111. model_group* add_group(const std::string& name = std::string());
  112. bool remove_group(const std::string& name);
  113. bool remove_group(model_group* group);
  114. const aabb_type& get_bounds() const;
  115. const model_group* get_group(const std::string& name) const;
  116. model_group* get_group(const std::string& name);
  117. const std::vector<model_group*>* get_groups() const;
  118. const gl::vertex_array* get_vertex_array() const;
  119. gl::vertex_array* get_vertex_array();
  120. const gl::vertex_buffer* get_vertex_buffer() const;
  121. gl::vertex_buffer* get_vertex_buffer();
  122. const skeleton& get_skeleton() const;
  123. skeleton& get_skeleton();
  124. private:
  125. aabb_type bounds;
  126. std::vector<model_group*> groups;
  127. std::unordered_map<std::string, model_group*> group_map;
  128. gl::vertex_array vao;
  129. gl::vertex_buffer vbo;
  130. ::skeleton skeleton;
  131. };
  132. inline void model::set_bounds(const aabb_type& bounds)
  133. {
  134. this->bounds = bounds;
  135. }
  136. inline const typename model::aabb_type& model::get_bounds() const
  137. {
  138. return bounds;
  139. }
  140. inline const std::vector<model_group*>* model::get_groups() const
  141. {
  142. return &groups;
  143. }
  144. inline const gl::vertex_array* model::get_vertex_array() const
  145. {
  146. return &vao;
  147. }
  148. inline gl::vertex_array* model::get_vertex_array()
  149. {
  150. return &vao;
  151. }
  152. inline const gl::vertex_buffer* model::get_vertex_buffer() const
  153. {
  154. return &vbo;
  155. }
  156. inline gl::vertex_buffer* model::get_vertex_buffer()
  157. {
  158. return &vbo;
  159. }
  160. inline const skeleton& model::get_skeleton() const
  161. {
  162. return skeleton;
  163. }
  164. inline skeleton& model::get_skeleton()
  165. {
  166. return skeleton;
  167. }
  168. } // namespace render
  169. #endif // ANTKEEPER_RENDER_MODEL_HPP