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

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