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