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

108 lines
2.8 KiB

  1. /*
  2. * Copyright (C) 2023 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_STATIC_MESH_HPP
  20. #define ANTKEEPER_SCENE_STATIC_MESH_HPP
  21. #include <engine/scene/object.hpp>
  22. #include <engine/animation/pose.hpp>
  23. #include <engine/render/model.hpp>
  24. #include <engine/render/operation.hpp>
  25. #include <vector>
  26. namespace scene {
  27. /**
  28. *
  29. */
  30. class static_mesh: public object<static_mesh>
  31. {
  32. public:
  33. /**
  34. * Constructs a static mesh from a model.
  35. *
  36. * @param model Model from which the static mesh will be constructed.
  37. */
  38. explicit static_mesh(std::shared_ptr<render::model> model);
  39. /**
  40. * Constructs a model instance.
  41. */
  42. static_mesh() = default;
  43. /**
  44. * Sets the model with which this model instance is associated. This will reset the pose and all overwritten materials.
  45. */
  46. void set_model(std::shared_ptr<render::model> model);
  47. /**
  48. * Overwrites the material of a model group for this model instance.
  49. *
  50. * @param index Index of a model group.
  51. * @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.
  52. */
  53. void set_material(std::size_t index, std::shared_ptr<render::material> material);
  54. /**
  55. * Resets all overwritten materials.
  56. */
  57. void reset_materials();
  58. [[nodiscard]] inline const aabb_type& get_bounds() const noexcept override
  59. {
  60. return m_bounds;
  61. }
  62. /**
  63. * Returns the model of the model instance.
  64. */
  65. [[nodiscard]] inline const std::shared_ptr<render::model>& get_model() const noexcept
  66. {
  67. return m_model;
  68. }
  69. /**
  70. * Returns the skeletal animation pose of this model instance.
  71. */
  72. /// @{
  73. [[nodiscard]] inline const pose& get_pose() const noexcept
  74. {
  75. return m_pose;
  76. }
  77. [[nodiscard]] inline pose& get_pose() noexcept
  78. {
  79. return m_pose;
  80. }
  81. /// @}
  82. void render(render::context& ctx) const override;
  83. private:
  84. void update_bounds();
  85. void transformed() override;
  86. std::shared_ptr<render::model> m_model;
  87. mutable std::vector<render::operation> m_operations;
  88. ::pose m_pose;
  89. aabb_type m_bounds{{0, 0, 0}, {0, 0, 0}};
  90. };
  91. } // namespace scene
  92. #endif // ANTKEEPER_SCENE_STATIC_MESH_HPP