#ifndef __S_MESH_H_INCLUDED__
#define __S_MESH_H_INCLUDED__
#include "IMesh.h"
#include "IMeshBuffer.h"
#include "aabbox3d.h"
#include "irrArray.h"
namespace irr
{
namespace scene
{
struct SMesh : public IMesh
{
SMesh()
{
#ifdef _DEBUG
setDebugName("SMesh");
#endif
}
virtual ~SMesh()
{
for (u32 i=0; i<MeshBuffers.size(); ++i)
MeshBuffers[i]->drop();
}
virtual void clear()
{
for (u32 i=0; i<MeshBuffers.size(); ++i)
MeshBuffers[i]->drop();
MeshBuffers.clear();
BoundingBox.reset ( 0.f, 0.f, 0.f );
}
virtual u32 getMeshBufferCount() const
{
return MeshBuffers.size();
}
virtual IMeshBuffer* getMeshBuffer(u32 nr) const
{
return MeshBuffers[nr];
}
virtual IMeshBuffer* getMeshBuffer( const video::SMaterial & material) const
{
for (s32 i = (s32)MeshBuffers.size()-1; i >= 0; --i)
{
if ( material == MeshBuffers[i]->getMaterial())
return MeshBuffers[i];
}
return 0;
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return BoundingBox;
}
virtual void setBoundingBox( const core::aabbox3df& box)
{
BoundingBox = box;
}
void recalculateBoundingBox()
{
if (MeshBuffers.size())
{
BoundingBox = MeshBuffers[0]->getBoundingBox();
for (u32 i=1; i<MeshBuffers.size(); ++i)
BoundingBox.addInternalBox(MeshBuffers[i]->getBoundingBox());
}
else
BoundingBox.reset(0.0f, 0.0f, 0.0f);
}
void addMeshBuffer(IMeshBuffer* buf)
{
if (buf)
{
buf->grab();
MeshBuffers.push_back(buf);
}
}
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
{
for (u32 i=0; i<MeshBuffers.size(); ++i)
MeshBuffers[i]->getMaterial().setFlag(flag, newvalue);
}
virtual void setHardwareMappingHint( E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX )
{
for (u32 i=0; i<MeshBuffers.size(); ++i)
MeshBuffers[i]->setHardwareMappingHint(newMappingHint, buffer);
}
virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
{
for (u32 i=0; i<MeshBuffers.size(); ++i)
MeshBuffers[i]->setDirty(buffer);
}
core::array<IMeshBuffer*> MeshBuffers;
core::aabbox3d<f32> BoundingBox;
};
}
}
#endif