Antkeeper  0.0.1
static-mesh.hpp
Go to the documentation of this file.
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 
20 #ifndef ANTKEEPER_SCENE_STATIC_MESH_HPP
21 #define ANTKEEPER_SCENE_STATIC_MESH_HPP
22 
23 #include <engine/scene/object.hpp>
24 #include <engine/render/model.hpp>
26 #include <vector>
27 
28 namespace scene {
29 
33 class static_mesh: public object<static_mesh>
34 {
35 public:
41  explicit static_mesh(std::shared_ptr<render::model> model);
42 
46  static_mesh() = default;
47 
53  void set_model(std::shared_ptr<render::model> model);
54 
61  void set_material(std::size_t index, std::shared_ptr<render::material> material);
62 
66  void reset_materials();
67 
68  [[nodiscard]] inline const aabb_type& get_bounds() const noexcept override
69  {
70  return m_bounds;
71  }
72 
76  [[nodiscard]] inline const std::shared_ptr<render::model>& get_model() const noexcept
77  {
78  return m_model;
79  }
80 
81  void render(render::context& ctx) const override;
82 
83 private:
84  void update_bounds();
85  void transformed() override;
86 
87  std::shared_ptr<render::model> m_model;
88  mutable std::vector<render::operation> m_operations;
89  aabb_type m_bounds{{0, 0, 0}, {0, 0, 0}};
90 };
91 
92 } // namespace scene
93 
94 #endif // ANTKEEPER_SCENE_STATIC_MESH_HPP
geom::box< float > aabb_type
Definition: object.hpp:42
Abstract base class for lights, cameras, model instances, and other scene objects.
Definition: object.hpp:172
static_mesh()=default
Constructs a model instance.
void render(render::context &ctx) const override
Adds render operations to a render context.
const std::shared_ptr< render::model > & get_model() const noexcept
Returns the model of the model instance.
Definition: static-mesh.hpp:76
void set_material(std::size_t index, std::shared_ptr< render::material > material)
Overwrites the material of a model group for this model instance.
Definition: static-mesh.cpp:64
void set_model(std::shared_ptr< render::model > model)
Sets the model with which this model instance is associated.
Definition: static-mesh.cpp:32
const aabb_type & get_bounds() const noexcept override
Returns the bounds of the object.
Definition: static-mesh.hpp:68
void reset_materials()
Resets all overwritten materials.
Definition: static-mesh.cpp:76
3D scene.
Definition: context.hpp:28
n-dimensional axis-aligned rectangle.
Context of a renderer.
Definition: context.hpp:40