Saga3D API Documentation  1.0-RC4
SAnimatedMesh.h
Go to the documentation of this file.
1 #ifndef __SANIMATED_MESH_H_INCLUDED__
2 #define __SANIMATED_MESH_H_INCLUDED__
3 
4 #include "IAnimatedMesh.h"
5 #include "IMesh.h"
6 #include "aabbox3d.h"
7 
8 namespace saga
9 {
10 namespace scene
11 {
12 
14  struct SAnimatedMesh : public IAnimatedMesh
15  {
17  SAnimatedMesh(const std::shared_ptr<scene::IMesh>& mesh = nullptr) : IAnimatedMesh(), FramesPerSecond(25.f)
18  {
19  addMesh(mesh);
21  }
22 
24  virtual ~SAnimatedMesh()
25  {
26  Meshes.clear();
27  }
28 
29  virtual E_MESH_TYPE getMeshType() const override { return E_MESH_TYPE::ANIMATED; }
30 
32 
33  virtual std::uint32_t getFrameCount() const
34  {
35  return Meshes.size();
36  }
37 
39 
40  virtual float getAnimationSpeed() const
41  {
42  return FramesPerSecond;
43  }
44 
46 
48  virtual void setAnimationSpeed(float fps)
49  {
50  FramesPerSecond=fps;
51  }
52 
54 
61  virtual const std::shared_ptr<IMesh>& getMesh(std::int32_t frame, std::int32_t detailLevel=255, std::int32_t startFrameLoop=-1, std::int32_t endFrameLoop=-1)
62  {
63  return Meshes[frame];
64  }
65 
67  void addMesh(const std::shared_ptr<IMesh>& mesh)
68  {
69  if (mesh)
70  {
71  Meshes.push_back(mesh);
72  }
73  }
74 
76 
77  virtual const core::aabbox3d<float>& getBoundingBox() const
78  {
79  return Box;
80  }
81 
83  virtual void setBoundingBox(const core::aabbox3df& box)
84  {
85  Box = box;
86  }
87 
90  {
91  Box.reset(0,0,0);
92 
93  if (Meshes.empty())
94  return;
95 
96  Box = Meshes[0]->getBoundingBox();
97 
98  for (std::uint32_t i=1; i < Meshes.size(); ++i)
99  Box.addInternalBox(Meshes[i]->getBoundingBox());
100  }
101 
103  virtual std::uint32_t getMeshBufferCount() const
104  {
105  if (Meshes.empty())
106  return 0;
107 
108  return Meshes[0]->getMeshBufferCount();
109  }
110 
112  virtual IMeshBuffer& getMeshBuffer(std::uint32_t nr = 0) override
113  {
114  return Meshes[0]->getMeshBuffer(nr);
115  }
116 
118 
119  virtual void addMeshBuffer(std::unique_ptr<IMeshBuffer> buf) override
120  {
121 
122  }
123 
125 
126  virtual void setAnimation(const uint32_t index) override
127  {
128 
129  }
130 
132  virtual void onAnimate(const float time) override
133  {
134 
135  }
136 
138  std::vector<std::shared_ptr<IMesh>> Meshes;
139 
142 
145  };
146 
147 
148 } // namespace scene
149 } // namespace saga
150 
151 #endif
152 
saga::scene::ANIMATED
@ ANIMATED
Definition: IMesh.h:18
saga::scene::SAnimatedMesh::Box
core::aabbox3d< float > Box
The bounding box of this mesh.
Definition: SAnimatedMesh.h:141
saga::scene::SAnimatedMesh::FramesPerSecond
float FramesPerSecond
Default animation speed of this mesh.
Definition: SAnimatedMesh.h:144
saga::scene::SAnimatedMesh::~SAnimatedMesh
virtual ~SAnimatedMesh()
destructor
Definition: SAnimatedMesh.h:24
saga::scene::SAnimatedMesh::setAnimationSpeed
virtual void setAnimationSpeed(float fps)
Gets the frame count of the animated mesh.
Definition: SAnimatedMesh.h:48
saga::scene::SAnimatedMesh
Simple implementation of the IAnimatedMesh interface.
Definition: SAnimatedMesh.h:14
saga::scene::SAnimatedMesh::addMeshBuffer
virtual void addMeshBuffer(std::unique_ptr< IMeshBuffer > buf) override
adds a MeshBuffer
Definition: SAnimatedMesh.h:119
IAnimatedMesh.h
saga::scene::SAnimatedMesh::setAnimation
virtual void setAnimation(const uint32_t index) override
Set active animation.
Definition: SAnimatedMesh.h:126
saga::scene::SAnimatedMesh::getMesh
virtual const std::shared_ptr< IMesh > & getMesh(std::int32_t frame, std::int32_t detailLevel=255, std::int32_t startFrameLoop=-1, std::int32_t endFrameLoop=-1)
Returns the IMesh interface for a frame.
Definition: SAnimatedMesh.h:61
saga::scene::IMeshBuffer
Struct for holding a mesh with a single material.
Definition: IMeshBuffer.h:43
aabbox3d.h
saga::scene::SAnimatedMesh::Meshes
std::vector< std::shared_ptr< IMesh > > Meshes
All meshes defining the animated mesh.
Definition: SAnimatedMesh.h:138
saga::core::aabbox3d< float >
saga::core::aabbox3d::reset
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition: aabbox3d.h:49
saga::scene::SAnimatedMesh::getMeshBuffer
virtual IMeshBuffer & getMeshBuffer(std::uint32_t nr=0) override
returns pointer to a mesh buffer
Definition: SAnimatedMesh.h:112
saga::scene::SAnimatedMesh::getMeshBufferCount
virtual std::uint32_t getMeshBufferCount() const
returns amount of mesh buffers.
Definition: SAnimatedMesh.h:103
saga::scene::SAnimatedMesh::setBoundingBox
virtual void setBoundingBox(const core::aabbox3df &box)
set user axis aligned bounding box
Definition: SAnimatedMesh.h:83
saga::scene::SAnimatedMesh::getAnimationSpeed
virtual float getAnimationSpeed() const
Gets the default animation speed of the animated mesh.
Definition: SAnimatedMesh.h:40
saga::core::aabbox3d::addInternalBox
void addInternalBox(const aabbox3d< T > &b)
Adds another bounding box.
Definition: aabbox3d.h:81
saga::scene::SAnimatedMesh::getFrameCount
virtual std::uint32_t getFrameCount() const
Gets the frame count of the animated mesh.
Definition: SAnimatedMesh.h:33
saga::scene::SAnimatedMesh::getBoundingBox
virtual const core::aabbox3d< float > & getBoundingBox() const
Returns an axis aligned bounding box of the mesh.
Definition: SAnimatedMesh.h:77
saga::scene::SAnimatedMesh::getMeshType
virtual E_MESH_TYPE getMeshType() const override
Definition: SAnimatedMesh.h:29
saga::scene::SAnimatedMesh::recalculateBoundingBox
void recalculateBoundingBox()
Recalculates the bounding box.
Definition: SAnimatedMesh.h:89
saga::scene::IAnimatedMesh
Interface for an animated mesh.
Definition: IAnimatedMesh.h:16
saga::scene::SAnimatedMesh::SAnimatedMesh
SAnimatedMesh(const std::shared_ptr< scene::IMesh > &mesh=nullptr)
constructor
Definition: SAnimatedMesh.h:17
saga::scene::SAnimatedMesh::onAnimate
virtual void onAnimate(const float time) override
Animate the mesh.
Definition: SAnimatedMesh.h:132
IMesh.h
saga::scene::E_MESH_TYPE
E_MESH_TYPE
Definition: IMesh.h:15
saga::scene::SAnimatedMesh::addMesh
void addMesh(const std::shared_ptr< IMesh > &mesh)
adds a Mesh
Definition: SAnimatedMesh.h:67
saga
Definition: aabbox3d.h:11