Irrlicht 3D Engine
SAnimatedMesh.h
Go to the documentation of this file.
00001 // Copyright (C) 2002-2012 Nikolaus Gebhardt
00002 // This file is part of the "Irrlicht Engine".
00003 // For conditions of distribution and use, see copyright notice in irrlicht.h
00004 
00005 #ifndef __S_ANIMATED_MESH_H_INCLUDED__
00006 #define __S_ANIMATED_MESH_H_INCLUDED__
00007 
00008 #include "IAnimatedMesh.h"
00009 #include "IMesh.h"
00010 #include "aabbox3d.h"
00011 #include "irrArray.h"
00012 
00013 namespace irr
00014 {
00015 namespace scene
00016 {
00017 
00019     struct SAnimatedMesh : public IAnimatedMesh
00020     {
00022         SAnimatedMesh(scene::IMesh* mesh=0, scene::E_ANIMATED_MESH_TYPE type=scene::EAMT_UNKNOWN) : IAnimatedMesh(), FramesPerSecond(25.f), Type(type)
00023         {
00024             #ifdef _DEBUG
00025             setDebugName("SAnimatedMesh");
00026             #endif
00027             addMesh(mesh);
00028             recalculateBoundingBox();
00029         }
00030 
00032         virtual ~SAnimatedMesh()
00033         {
00034             // drop meshes
00035             for (u32 i=0; i<Meshes.size(); ++i)
00036                 Meshes[i]->drop();
00037         }
00038 
00040 
00041         virtual u32 getFrameCount() const
00042         {
00043             return Meshes.size();
00044         }
00045 
00047 
00048         virtual f32 getAnimationSpeed() const
00049         {
00050             return FramesPerSecond;
00051         }
00052 
00054 
00056         virtual void setAnimationSpeed(f32 fps)
00057         {
00058             FramesPerSecond=fps;
00059         }
00060 
00062 
00069         virtual IMesh* getMesh(s32 frame, s32 detailLevel=255, s32 startFrameLoop=-1, s32 endFrameLoop=-1)
00070         {
00071             if (Meshes.empty())
00072                 return 0;
00073 
00074             return Meshes[frame];
00075         }
00076 
00078         void addMesh(IMesh* mesh)
00079         {
00080             if (mesh)
00081             {
00082                 mesh->grab();
00083                 Meshes.push_back(mesh);
00084             }
00085         }
00086 
00088 
00089         virtual const core::aabbox3d<f32>& getBoundingBox() const
00090         {
00091             return Box;
00092         }
00093 
00095         virtual void setBoundingBox(const core::aabbox3df& box)
00096         {
00097             Box = box;
00098         }
00099 
00101         void recalculateBoundingBox()
00102         {
00103             Box.reset(0,0,0);
00104 
00105             if (Meshes.empty())
00106                 return;
00107 
00108             Box = Meshes[0]->getBoundingBox();
00109 
00110             for (u32 i=1; i<Meshes.size(); ++i)
00111                 Box.addInternalBox(Meshes[i]->getBoundingBox());
00112         }
00113 
00115         virtual E_ANIMATED_MESH_TYPE getMeshType() const
00116         {
00117             return Type;
00118         }
00119 
00121         virtual u32 getMeshBufferCount() const
00122         {
00123             if (Meshes.empty())
00124                 return 0;
00125 
00126             return Meshes[0]->getMeshBufferCount();
00127         }
00128 
00130         virtual IMeshBuffer* getMeshBuffer(u32 nr) const
00131         {
00132             if (Meshes.empty())
00133                 return 0;
00134 
00135             return Meshes[0]->getMeshBuffer(nr);
00136         }
00137 
00139 
00142         virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const
00143         {
00144             if (Meshes.empty())
00145                 return 0;
00146 
00147             return Meshes[0]->getMeshBuffer(material);
00148         }
00149 
00151         virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
00152         {
00153             for (u32 i=0; i<Meshes.size(); ++i)
00154                 Meshes[i]->setMaterialFlag(flag, newvalue);
00155         }
00156 
00158         virtual void setHardwareMappingHint( E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX )
00159         {
00160             for (u32 i=0; i<Meshes.size(); ++i)
00161                 Meshes[i]->setHardwareMappingHint(newMappingHint, buffer);
00162         }
00163 
00165         virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
00166         {
00167             for (u32 i=0; i<Meshes.size(); ++i)
00168                 Meshes[i]->setDirty(buffer);
00169         }
00170 
00172         core::array<IMesh*> Meshes;
00173 
00175         core::aabbox3d<f32> Box;
00176 
00178         f32 FramesPerSecond;
00179 
00181         E_ANIMATED_MESH_TYPE Type;
00182     };
00183 
00184 
00185 } // end namespace scene
00186 } // end namespace irr
00187 
00188 #endif
00189