1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __S_ANIMATED_MESH_H_INCLUDED__
\r
6 #define __S_ANIMATED_MESH_H_INCLUDED__
\r
8 #include "IAnimatedMesh.h"
\r
10 #include "aabbox3d.h"
\r
11 #include "irrArray.h"
\r
18 //! Simple implementation of the IAnimatedMesh interface.
\r
19 struct SAnimatedMesh : public IAnimatedMesh
\r
22 SAnimatedMesh(scene::IMesh* mesh=0, scene::E_ANIMATED_MESH_TYPE type=scene::EAMT_UNKNOWN) : IAnimatedMesh(), FramesPerSecond(25.f), Type(type)
\r
25 setDebugName("SAnimatedMesh");
\r
28 recalculateBoundingBox();
\r
32 virtual ~SAnimatedMesh()
\r
35 for (u32 i=0; i<Meshes.size(); ++i)
\r
39 //! Gets the frame count of the animated mesh.
\r
40 /** \return Amount of frames. If the amount is 1, it is a static, non animated mesh. */
\r
41 virtual u32 getFrameCount() const _IRR_OVERRIDE_
\r
43 return Meshes.size();
\r
46 //! Gets the default animation speed of the animated mesh.
\r
47 /** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */
\r
48 virtual f32 getAnimationSpeed() const _IRR_OVERRIDE_
\r
50 return FramesPerSecond;
\r
53 //! Gets the frame count of the animated mesh.
\r
54 /** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.
\r
55 The actual speed is set in the scene node the mesh is instantiated in.*/
\r
56 virtual void setAnimationSpeed(f32 fps) _IRR_OVERRIDE_
\r
58 FramesPerSecond=fps;
\r
61 //! Returns the IMesh interface for a frame.
\r
62 /** \param frame: Frame number as zero based index. The maximum frame number is
\r
63 getFrameCount() - 1;
\r
64 \param detailLevel: Level of detail. 0 is the lowest,
\r
65 255 the highest level of detail. Most meshes will ignore the detail level.
\r
66 \param startFrameLoop: start frame
\r
67 \param endFrameLoop: end frame
\r
68 \return The animated mesh based on a detail level. */
\r
69 virtual IMesh* getMesh(s32 frame, s32 detailLevel=255, s32 startFrameLoop=-1, s32 endFrameLoop=-1) _IRR_OVERRIDE_
\r
74 return Meshes[frame];
\r
78 void addMesh(IMesh* mesh)
\r
83 Meshes.push_back(mesh);
\r
87 //! Returns an axis aligned bounding box of the mesh.
\r
88 /** \return A bounding box of this mesh is returned. */
\r
89 virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_OVERRIDE_
\r
94 //! set user axis aligned bounding box
\r
95 virtual void setBoundingBox(const core::aabbox3df& box) _IRR_OVERRIDE_
\r
100 //! Recalculates the bounding box.
\r
101 void recalculateBoundingBox()
\r
105 if (Meshes.empty())
\r
108 Box = Meshes[0]->getBoundingBox();
\r
110 for (u32 i=1; i<Meshes.size(); ++i)
\r
111 Box.addInternalBox(Meshes[i]->getBoundingBox());
\r
114 //! Returns the type of the animated mesh.
\r
115 virtual E_ANIMATED_MESH_TYPE getMeshType() const _IRR_OVERRIDE_
\r
120 //! returns amount of mesh buffers.
\r
121 virtual u32 getMeshBufferCount() const _IRR_OVERRIDE_
\r
123 if (Meshes.empty())
\r
126 return Meshes[0]->getMeshBufferCount();
\r
129 //! returns pointer to a mesh buffer
\r
130 virtual IMeshBuffer* getMeshBuffer(u32 nr) const _IRR_OVERRIDE_
\r
132 if (Meshes.empty())
\r
135 return Meshes[0]->getMeshBuffer(nr);
\r
138 //! Returns pointer to a mesh buffer which fits a material
\r
139 /** \param material: material to search for
\r
140 \return Returns the pointer to the mesh buffer or
\r
141 NULL if there is no such mesh buffer. */
\r
142 virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const _IRR_OVERRIDE_
\r
144 if (Meshes.empty())
\r
147 return Meshes[0]->getMeshBuffer(material);
\r
150 //! Set a material flag for all meshbuffers of this mesh.
\r
151 virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) _IRR_OVERRIDE_
\r
153 for (u32 i=0; i<Meshes.size(); ++i)
\r
154 Meshes[i]->setMaterialFlag(flag, newvalue);
\r
157 //! set the hardware mapping hint, for driver
\r
158 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX ) _IRR_OVERRIDE_
\r
160 for (u32 i=0; i<Meshes.size(); ++i)
\r
161 Meshes[i]->setHardwareMappingHint(newMappingHint, buffer);
\r
164 //! flags the meshbuffer as changed, reloads hardware buffers
\r
165 virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_
\r
167 for (u32 i=0; i<Meshes.size(); ++i)
\r
168 Meshes[i]->setDirty(buffer);
\r
171 //! All meshes defining the animated mesh
\r
172 core::array<IMesh*> Meshes;
\r
174 //! The bounding box of this mesh
\r
175 core::aabbox3d<f32> Box;
\r
177 //! Default animation speed of this mesh.
\r
178 f32 FramesPerSecond;
\r
180 //! The type of the mesh.
\r
181 E_ANIMATED_MESH_TYPE Type;
\r
185 } // end namespace scene
\r
186 } // end namespace irr
\r