#include "CMetaTriangleSelector.h"
namespace irr
{
namespace scene
{
CMetaTriangleSelector::CMetaTriangleSelector()
{
#ifdef _DEBUG
setDebugName("CMetaTriangleSelector");
#endif
}
CMetaTriangleSelector::~CMetaTriangleSelector()
{
removeAllTriangleSelectors();
}
s32 CMetaTriangleSelector::getTriangleCount() const
{
s32 count = 0;
for (u32 i=0; i<TriangleSelectors.size(); ++i)
count += TriangleSelectors[i]->getTriangleCount();
return count;
}
void CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::matrix4* transform) const
{
s32 outWritten = 0;
for (u32 i=0; i<TriangleSelectors.size(); ++i)
{
s32 t = 0;
TriangleSelectors[i]->getTriangles(triangles + outWritten,
arraySize - outWritten, t, transform);
outWritten += t;
if (outWritten==arraySize)
break;
}
outTriangleCount = outWritten;
}
void CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::aabbox3d<f32>& box,
const core::matrix4* transform) const
{
s32 outWritten = 0;
for (u32 i=0; i<TriangleSelectors.size(); ++i)
{
s32 t = 0;
TriangleSelectors[i]->getTriangles(triangles + outWritten,
arraySize - outWritten, t, box, transform);
outWritten += t;
if (outWritten==arraySize)
break;
}
outTriangleCount = outWritten;
}
void CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::line3d<f32>& line,
const core::matrix4* transform) const
{
s32 outWritten = 0;
for (u32 i=0; i<TriangleSelectors.size(); ++i)
{
s32 t = 0;
TriangleSelectors[i]->getTriangles(triangles + outWritten,
arraySize - outWritten, t, line, transform);
outWritten += t;
if (outWritten==arraySize)
break;
}
outTriangleCount = outWritten;
}
void CMetaTriangleSelector::addTriangleSelector(ITriangleSelector* toAdd)
{
if (!toAdd)
return;
TriangleSelectors.push_back(toAdd);
toAdd->grab();
}
bool CMetaTriangleSelector::removeTriangleSelector(ITriangleSelector* toRemove)
{
for (u32 i=0; i<TriangleSelectors.size(); ++i)
{
if (toRemove == TriangleSelectors[i])
{
TriangleSelectors[i]->drop();
TriangleSelectors.erase(i);
return true;
}
}
return false;
}
void CMetaTriangleSelector::removeAllTriangleSelectors()
{
for (u32 i=0; i<TriangleSelectors.size(); ++i)
TriangleSelectors[i]->drop();
TriangleSelectors.clear();
}
ISceneNode* CMetaTriangleSelector::getSceneNodeForTriangle(u32 triangleIndex) const
{
u32 totalTriangles = 0;
for (u32 i=0; i<TriangleSelectors.size(); ++i)
{
totalTriangles += TriangleSelectors[i]->getTriangleCount();
if(totalTriangles > triangleIndex)
return TriangleSelectors[i]->getSceneNodeForTriangle(0);
}
return TriangleSelectors[0]->getSceneNodeForTriangle(0);
}
}
}