#ifndef __S_ANIMATED_MESH_H_INCLUDED__
#define __S_ANIMATED_MESH_H_INCLUDED__
#include "IAnimatedMesh.h"
#include "IMesh.h"
#include "aabbox3d.h"
#include "irrArray.h"
namespace irr
{
namespace scene
{
struct SAnimatedMesh : public IAnimatedMesh
{
SAnimatedMesh(scene::IMesh* mesh=0, scene::E_ANIMATED_MESH_TYPE type=scene::EAMT_UNKNOWN) : IAnimatedMesh(), Type(type)
{
#ifdef _DEBUG
setDebugName("SAnimatedMesh");
#endif
addMesh(mesh);
recalculateBoundingBox();
}
virtual ~SAnimatedMesh()
{
for (u32 i=0; i<Meshes.size(); ++i)
Meshes[i]->drop();
}
virtual u32 getFrameCount() const
{
return Meshes.size();
}
virtual IMesh* getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop=-1, s32 endFrameLoop=-1)
{
if (Meshes.empty())
return 0;
return Meshes[frame];
}
void addMesh(IMesh* mesh)
{
if (mesh)
{
mesh->grab();
Meshes.push_back(mesh);
}
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return Box;
}
virtual void setBoundingBox(const core::aabbox3df& box)
{
Box = box;
}
void recalculateBoundingBox()
{
Box.reset(0,0,0);
if (Meshes.empty())
return;
Box = Meshes[0]->getBoundingBox();
for (u32 i=1; i<Meshes.size(); ++i)
Box.addInternalBox(Meshes[i]->getBoundingBox());
}
virtual E_ANIMATED_MESH_TYPE getMeshType() const
{
return Type;
}
virtual u32 getMeshBufferCount() const
{
if (Meshes.empty())
return 0;
return Meshes[0]->getMeshBufferCount();
}
virtual IMeshBuffer* getMeshBuffer(u32 nr) const
{
if (Meshes.empty())
return 0;
return Meshes[0]->getMeshBuffer(nr);
}
virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const
{
if (Meshes.empty())
return 0;
return Meshes[0]->getMeshBuffer(material);
}
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
{
for (u32 i=0; i<Meshes.size(); ++i)
Meshes[i]->setMaterialFlag(flag, newvalue);
}
virtual void setHardwareMappingHint( E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX )
{
for (u32 i=0; i<Meshes.size(); ++i)
Meshes[i]->setHardwareMappingHint(newMappingHint, buffer);
}
virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
{
for (u32 i=0; i<Meshes.size(); ++i)
Meshes[i]->setDirty(buffer);
}
core::array<IMesh*> Meshes;
core::aabbox3d<f32> Box;
E_ANIMATED_MESH_TYPE Type;
};
}
}
#endif