24 #include <unordered_map>
31 #include "../interfaces/boundable.h"
32 #include "../generic/managed.h"
33 #include "../generic/identifiable.h"
34 #include "../generic/property.h"
36 #include "../loadable.h"
38 #include "../vertex_data.h"
40 #include "../interfaces.h"
41 #include "../animation.h"
52 enum MeshAnimationType {
53 MESH_ANIMATION_TYPE_NONE,
54 MESH_ANIMATION_TYPE_VERTEX_MORPH,
55 MESH_ANIMATION_TYPE_SKELETAL
59 typedef sig::signal<void (Mesh*, MeshAnimationType, uint32_t)> SignalAnimationEnabled;
73 virtual void prepare_unpack(
74 uint32_t current_frame,
76 float t,
Rig*
const rig,
77 Debug*
const debug=
nullptr
83 virtual void unpack_frame(
84 const uint32_t current_frame,
85 const uint32_t next_frame,
89 Debug*
const debug=
nullptr
93 typedef std::shared_ptr<FrameUnpacker> FrameUnpackerPtr;
98 typedef std::vector<std::shared_ptr<SubMesh>> container_type;
99 typedef typename container_type::iterator iterator_type;
104 container_(container) {
108 container_type& container_;
111 iterator_type begin() {
112 return container_.begin();
115 iterator_type end() {
116 return container_.end();
141 VertexDataPtr vertex_data
157 void reset(VertexDataPtr vertex_data);
162 bool add_skeleton(uint32_t num_joints);
165 bool has_skeleton()
const;
175 const std::string& name,
177 MeshArrangement arrangement=MESH_ARRANGEMENT_TRIANGLES
189 const std::string& name,
191 IndexType index_type,
192 MeshArrangement arrangement=MESH_ARRANGEMENT_TRIANGLES
204 const std::string& name,
206 IndexDataPtr index_data,
207 MeshArrangement arrangement=MESH_ARRANGEMENT_TRIANGLES
211 const std::string& name,
215 std::size_t segment_count,
216 std::size_t vertical_segment_count,
217 std::size_t ring_count
220 SubMeshPtr new_submesh_as_sphere(
const std::string& name,
227 SubMeshPtr new_submesh_as_icosphere(
const std::string& name,
230 uint32_t subdivisions
234 const std::string& name,
242 const std::string& name,
248 const std::string& name,
256 uint32_t submesh_count()
const {
return submeshes_.size(); }
257 bool has_submesh(
const std::string& name)
const;
258 SubMeshPtr find_submesh(
const std::string& name)
const;
261 void destroy_submesh(
const std::string& name);
268 const AABB& aabb()
const;
270 void transform_vertices(
const smlt::Mat4& transform);
274 void enable_animation(MeshAnimationType animation_type, uint32_t animation_frames, FrameUnpackerPtr data);
275 bool is_animated()
const {
return animation_type_ != MESH_ANIMATION_TYPE_NONE; }
276 uint32_t animation_frames()
const {
return animation_frames_; }
277 MeshAnimationType animation_type()
const {
return animation_type_; }
281 void generate_adjacency_info();
282 bool has_adjacency_info()
const {
return bool(adjacency_); }
304 VertexDataPtr vertex_data_;
305 MeshAnimationType animation_type_ = MESH_ANIMATION_TYPE_NONE;
306 uint32_t animation_frames_ = 0;
307 FrameUnpackerPtr animated_frame_data_;
309 std::vector<std::shared_ptr<SubMesh>> submeshes_;
319 bool maintain_adjacency_info_ =
true;
320 std::unique_ptr<AdjacencyInfo> adjacency_;
322 void vertex_data_updated();
323 void submesh_index_data_updated(
SubMesh* sm);
328 S_DEFINE_PROPERTY(adjacency_info, &Mesh::adjacency_);
330 S_DEFINE_PROPERTY(vertex_data, &Mesh::vertex_data_);
333 S_DEFINE_PROPERTY(skeleton, &Mesh::skeleton_);