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

142 lines
3.5 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_SCENE_MODEL_INSTANCE_HPP
  20. #define ANTKEEPER_SCENE_MODEL_INSTANCE_HPP
  21. #include "scene/object.hpp"
  22. #include "animation/pose.hpp"
  23. #include "geom/aabb.hpp"
  24. #include "render/model.hpp"
  25. #include <vector>
  26. namespace scene {
  27. class model_instance: public object<model_instance>
  28. {
  29. public:
  30. typedef geom::aabb<float> aabb_type;
  31. explicit model_instance(render::model* model);
  32. model_instance();
  33. model_instance(const model_instance& other);
  34. model_instance& operator=(const model_instance& other);
  35. /**
  36. * Sets the model with which this model instance is associated. This will reset the pose and all overwritten materials.
  37. */
  38. void set_model(render::model* model);
  39. /**
  40. * Overwrites the material of a model group for this model instance.
  41. *
  42. * @param group_index Index of a model group.
  43. * @param material Pointer to the material which should overwrite the model group's material. A value of `nullptr` indicates the material will not be overwritten.
  44. */
  45. void set_material(std::size_t group_index, render::material* material);
  46. void set_instanced(bool instanced, std::size_t instance_count = 1);
  47. /**
  48. * Resets all overwritten materials.
  49. */
  50. void reset_materials();
  51. virtual const bounding_volume_type& get_local_bounds() const;
  52. virtual const bounding_volume_type& get_world_bounds() const;
  53. const render::model* get_model() const;
  54. render::model* get_model();
  55. /// Returns the skeletal animation pose of this model.
  56. const pose& get_pose() const;
  57. /// @copydoc model_instance::get_pose() const
  58. pose& get_pose();
  59. const std::vector<render::material*>* get_materials() const;
  60. bool is_instanced() const;
  61. std::size_t get_instance_count() const;
  62. virtual void update_tweens();
  63. void update_bounds();
  64. private:
  65. virtual void transformed();
  66. render::model* model;
  67. ::pose pose;
  68. std::vector<render::material*> materials;
  69. aabb_type local_bounds;
  70. aabb_type world_bounds;
  71. bool instanced;
  72. std::size_t instance_count;
  73. };
  74. inline const typename object_base::bounding_volume_type& model_instance::get_local_bounds() const
  75. {
  76. return local_bounds;
  77. }
  78. inline const typename object_base::bounding_volume_type& model_instance::get_world_bounds() const
  79. {
  80. return world_bounds;
  81. }
  82. inline const render::model* model_instance::get_model() const
  83. {
  84. return model;
  85. }
  86. inline render::model* model_instance::get_model()
  87. {
  88. return model;
  89. }
  90. inline const pose& model_instance::get_pose() const
  91. {
  92. return pose;
  93. }
  94. inline pose&model_instance::get_pose()
  95. {
  96. return pose;
  97. }
  98. inline const std::vector<render::material*>* model_instance::get_materials() const
  99. {
  100. return &materials;
  101. }
  102. inline bool model_instance::is_instanced() const
  103. {
  104. return instanced;
  105. }
  106. inline std::size_t model_instance::get_instance_count() const
  107. {
  108. return instance_count;
  109. }
  110. } // namespace scene
  111. #endif // ANTKEEPER_SCENE_MODEL_INSTANCE_HPP