2008-05-22 04:51:37 -07:00
|
|
|
// Copyright (C) 2002-2008 Nikolaus Gebhardt
|
2007-05-20 11:03:49 -07:00
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#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
|
|
|
|
{
|
|
|
|
//! Simple implementation of the IMesh interface.
|
|
|
|
struct SMesh : public IMesh
|
|
|
|
{
|
|
|
|
//! constructor
|
|
|
|
SMesh()
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
setDebugName("SMesh");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//! destructor
|
2007-09-17 09:09:50 -07:00
|
|
|
virtual ~SMesh()
|
2007-05-20 11:03:49 -07:00
|
|
|
{
|
|
|
|
// drop buffers
|
|
|
|
for (u32 i=0; i<MeshBuffers.size(); ++i)
|
|
|
|
MeshBuffers[i]->drop();
|
2007-09-17 09:09:50 -07:00
|
|
|
}
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
//! returns amount of mesh buffers.
|
|
|
|
virtual u32 getMeshBufferCount() const
|
|
|
|
{
|
|
|
|
return MeshBuffers.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! returns pointer to a mesh buffer
|
|
|
|
virtual IMeshBuffer* getMeshBuffer(u32 nr) const
|
|
|
|
{
|
|
|
|
return MeshBuffers[nr];
|
|
|
|
}
|
|
|
|
|
|
|
|
//! returns a meshbuffer which fits a material
|
2008-05-22 04:51:37 -07:00
|
|
|
/** reverse search */
|
2007-05-20 11:03:49 -07:00
|
|
|
virtual IMeshBuffer* getMeshBuffer( const video::SMaterial & material) const
|
|
|
|
{
|
2008-03-02 06:28:48 -08:00
|
|
|
for (s32 i = (s32)MeshBuffers.size()-1; i >= 0; --i)
|
2007-05-20 11:03:49 -07:00
|
|
|
{
|
2007-05-28 04:14:47 -07:00
|
|
|
if ( material == MeshBuffers[i]->getMaterial())
|
2007-05-20 11:03:49 -07:00
|
|
|
return MeshBuffers[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! returns an axis aligned bounding box
|
|
|
|
virtual const core::aabbox3d<f32>& getBoundingBox() const
|
|
|
|
{
|
|
|
|
return BoundingBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! set user axis aligned bounding box
|
|
|
|
virtual void setBoundingBox( const core::aabbox3df& box)
|
|
|
|
{
|
|
|
|
BoundingBox = box;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! recalculates the bounding 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! adds a MeshBuffer
|
|
|
|
void addMeshBuffer(IMeshBuffer* buf)
|
|
|
|
{
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
buf->grab();
|
|
|
|
MeshBuffers.push_back(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! sets a flag of all contained materials to a new value
|
|
|
|
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
|
|
|
|
{
|
|
|
|
for (u32 i=0; i<MeshBuffers.size(); ++i)
|
|
|
|
MeshBuffers[i]->getMaterial().setFlag(flag, newvalue);
|
|
|
|
}
|
|
|
|
|
2008-05-22 04:51:37 -07:00
|
|
|
//! The meshbuffers of this mesh
|
2007-05-20 11:03:49 -07:00
|
|
|
core::array<IMeshBuffer*> MeshBuffers;
|
2008-05-22 04:51:37 -07:00
|
|
|
//! The bounding box of this mesh
|
2007-05-20 11:03:49 -07:00
|
|
|
core::aabbox3d<f32> BoundingBox;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace scene
|
|
|
|
} // end namespace irr
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|